8000 feat(sdk): add more information about current version (#3358) · ovh/cds@ac8f104 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit ac8f104

Browse files
authored
feat(sdk): add more information about current version (#3358)
1 parent 7abf470 commit ac8f104

File tree

33 files changed

+162
-83
lines changed

33 files changed

+162
-83
lines changed

cli/cdsctl/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
.PHONY: clean
22

33
VERSION := $(if ${CDS_SEMVER},${CDS_SEMVER},snapshot)
4+
GITHASH := $(if ${GIT_HASH},${GIT_HASH},`git log -1 --format="%H"`)
5+
BUILDTIME := `date "+%m/%d/%y-%H:%M:%S"`
46

57
TARGET_DIR = ./dist
68
TARGET_BINARY = cdsctl
7-
TARGET_LDFLAGS = -ldflags "-X github.com/ovh/cds/sdk.VERSION=$(VERSION)"
9+
TARGET_LDFLAGS = -ldflags "-X github.com/ovh/cds/sdk.VERSION=$(VERSION) -X github.com/ovh/cds/sdk.GOOS=$$GOOS -X github.com/ovh/cds/sdk.GOARCH=$$GOARCH -X github.com/ovh/cds/sdk.GITHASH=$(GITHASH) -X github.com/ovh/cds/sdk.BUILDTIME=$(BUILDTIME) -X github.com/ovh/cds/sdk.BINARY=$(TARGET_BINARY)"
810
TARGET_OS = $(if ${OS},${OS},windows darwin linux freebsd)
911
TARGET_ARCH = $(if ${ARCH},${ARCH},amd64 arm 386)
1012

cli/cdsctl/config.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"os"
66
"path"
7-
"runtime"
87
"strconv"
98

109
repo "github.com/fsamin/go-repo"
@@ -29,9 +28,9 @@ type config struct {
2928

3029
func userHomeDir() string {
3130
env := "HOME"
32-
if runtime.GOOS == "windows" {
31+
if sdk.GOOS == "windows" {
3332
env = "USERPROFILE"
34-
} else if runtime.GOOS == "plan9" {
33+
} else if sdk.GOOS == "plan9" {
3534
env = "home"
3635
}
3736
return os.Getenv(env)

cli/cdsctl/login.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import (
66
"path"
77
"reflect"
88
"regexp"
9-
"runtime"
109
"strings"
1110

1211
"github.com/howeyc/gopass"
1312

1413
"github.com/ovh/cds/cli"
14+
"github.com/ovh/cds/sdk"
1515
"github.com/ovh/cds/sdk/cdsclient"
1616
)
1717

@@ -106,7 +106,7 @@ func doLogin(url, username, password string, env bool) error {
106106
return fmt.Errorf("login failed")
107107
}
108108

109-
if env && runtime.GOOS == "windows" {
109+
if env && sdk.GOOS == "windows" {
110110
fmt.Println("env option is not supported on windows yet")
111111
os.Exit(1)
112112
}

cli/cdsctl/update.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"net/http"
66
"reflect"
7-
"runtime"
87

98
"github.com/inconshreveable/go-update"
109

@@ -26,19 +25,19 @@ var updateCmd = cli.Command{
2625
}
2726

2827
func updateRun(v cli.Values) error {
29-
fmt.Printf("CDS cdsctl version:%s os:%s architecture:%s\n", sdk.VERSION, runtime.GOOS, runtime.GOARCH)
28+
fmt.Println(sdk.VersionString())
3029

3130
var urlBinary string
3231
if v.GetBool("from-github") {
3332
// no need to have apiEndpoint here
3433
var errGH error
35-
urlBinary, errGH = client.DownloadURLFromGithub(sdk.GetArtifactFilename("cdsctl", runtime.GOOS, runtime.GOARCH))
34+
urlBinary, errGH = client.DownloadURLFromGithub(sdk.GetArtifactFilename("cdsctl", sdk.GOOS, sdk.GOARCH))
3635
if errGH != nil {
3736
return fmt.Errorf("Error while getting URL from Github url:%s err:%s", urlBinary, errGH)
3837
}
3938
fmt.Printf("Updating binary from Github on %s...\n", urlBinary)
4039
} else {
41-
urlBinary = client.DownloadURLFromAPI("cdsctl", runtime.GOOS, runtime.GOARCH)
40+
urlBinary = client.DownloadURLFromAPI("cdsctl", sdk.GOOS, sdk.GOARCH)
4241
fmt.Printf("Updating binary from CDS API on %s...\n", urlBinary)
4342
}
4443

cli/cdsctl/version.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"fmt"
5-
"runtime"
65

76
"github.com/ovh/cds/cli"
87
"github.com/ovh/cds/sdk"
@@ -14,7 +13,7 @@ var versionCmd = cli.Command{
1413
}
1514

1615
func versionRun(v cli.Values) error {
17-
fmt.Printf("CDS cdsctl version: %s os:%s architecture:%s\n", sdk.VERSION, runtime.GOOS, runtime.GOARCH)
16+
fmt.Println(sdk.VersionString())
1817
version, err := client.Version()
1918
if err != nil {
2019
return err

contrib/grpcplugins/action/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.PHONY: clean
22

33
VERSION := $(if ${CDS_SEMVER},${CDS_SEMVER},snapshot)
4+
GITHASH := $(if ${GIT_HASH},${GIT_HASH},`git log -1 --format="%H"`)
5+
BUILDTIME := `date "+%m/%d/%y-%H:%M:%S"`
46

57
TARGET_DIR = dist
68
TARGET_NAME = $(filter-out $@,$(MAKECMDGOALS))
@@ -12,7 +14,7 @@ cmd: ./%filename%
1214
endef
1315
export PLUGIN_MANIFEST_BINARY
1416

15-
TARGET_LDFLAGS = -ldflags "-X github.com/ovh/cds/sdk.VERSION=$(VERSION)"
17+
TARGET_LDFLAGS = -ldflags "-X github.com/ovh/cds/sdk.VERSION=$(VERSION) -X github.com/ovh/cds/sdk.GOOS=$$GOOS -X github.com/ovh/cds/sdk.GOARCH=$$GOARCH -X github.com/ovh/cds/sdk.GITHASH=$(GITHASH) -X github.com/ovh/cds/sdk.BUILDTIME=$(BUILDTIME) -X github.com/ovh/cds/sdk.BINARY=$(TARGET_NAME)"
1618
TARGET_OS = $(if ${OS},${OS},windows darwin linux freebsd)
1719
TARGET_ARCH = $(if ${ARCH},${ARCH},amd64 arm 386)
1820

contrib/grpcplugins/deployment/arsenal/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.PHONY: clean
22

33
VERSION := $(if ${CDS_SEMVER},${CDS_SEMVER},snapshot)
4+
GITHASH := $(if ${GIT_HASH},${GIT_HASH},`git log -1 --format="%H"`)
5+
BUILDTIME := `date "+%m/%d/%y-%H:%M:%S"`
46

57
TARGET_DIR = ./dist
68
TARGET_NAME = arsenal
@@ -15,7 +17,7 @@ cmd: ./%filename%
1517
endef
1618
export PLUGIN_MANIFEST_BINARY
1719

18-
TARGET_LDFLAGS = -ldflags "-X github.com/ovh/cds/sdk.VERSION=$(VERSION)"
20+
TARGET_LDFLAGS = -ldflags "-X github.com/ovh/cds/sdk.VERSION=$(VERSION) -X github.com/ovh/cds/sdk.GOOS=$$GOOS -X github.com/ovh/cds/sdk.GOARCH=$$GOARCH -X github.com/ovh/cds/sdk.GITHASH=$(GITHASH) -X github.com/ovh/cds/sdk.BUILDTIME=$(BUILDTIME) -X github.com/ovh/cds/sdk.BINARY=$(TARGET_NAME)"
1921
TARGET_OS = $(if ${OS},${OS},windows darwin linux freebsd)
2022
TARGET_ARCH = $(if ${ARCH},${ARCH},amd64 arm 386)
2123

docs/content/workflows/pipelines/requirements/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Type of requirements:
1313
- [Network access]({{< relref "/workflows/pipelines/requirements/network_access/_index.md" >}})
1414
- [Service]({{< relref "/workflows/pipelines/requirements/service/_index.md" >}})
1515
- Memory
16-
- OS & Architecture
16+
- [OS & Architecture]({{< relref "/workflows/pipelines/requirements/os_architecture/_index.md" >}})
1717

1818
A [Job]({{< relref "gettingstarted/concepts/job.md" >}}) will be executed by a **worker**.
1919

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
+++
2+
title = "OS & Architecture"
3+
weight = 1
4+
5+
+++
6+
7+
The OS-Architecture prerequisiste allow you to require a worker with a specific OS & Architecture.
8+
9+
**Beware about default value**: there is a default value for OS & Architecture, it's specified in CDS API Configuration.
10+
11+
If user does not specify a prerequisite `os-architecture`, the default value is applied when the job is in CDS Queue.
12+
13+
Then, a hatchery will spawn a worker compiled with the specified `os-architecture` prerequisite.
14+
15+
**Bewere about launching job**: if you put a prerequisite `os-architecture` with value `linux/386`, the job won't be launched by a worker `linux/amd64` even if technically speaking, the worker could launch this job without issue.
16+
17+
### How to set a OS & Architecture
18+
19+
![Step](/images/workflows.pipelines.requirements.os_architecture.choose.png)
20+
21+
### Setup default OS & Architecture on a CDS API Configuration
22+
23+
```toml
24+
#####################
25+
# API Configuration
26+
#####################
27+
[api]
28+
29+
# if no model and no os/arch is specified in your job's requirements then spawn worker on this architecture (example: amd64, arm, 386)
30+
defaultArch = "amd64"
31+
32+
# if no model and os/arch is specified in your job's requirements then spawn worker on this operating system (example: freebsd, linux, windows)
33+
defaultOS = "linux"
34+
```
Loading

0 commit comments

Comments
 (0)
0