Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk): add more information about current version #3358

Merged
merged 5 commits into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cli/cdsctl/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
.PHONY: clean

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

TARGET_DIR = ./dist
TARGET_BINARY = cdsctl
TARGET_LDFLAGS = -ldflags "-X github.com/ovh/cds/sdk.VERSION=$(VERSION)"
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)"
TARGET_OS = $(if ${OS},${OS},windows darwin linux freebsd)
TARGET_ARCH = $(if ${ARCH},${ARCH},amd64 arm 386)

Expand Down
5 changes: 2 additions & 3 deletions cli/cdsctl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"
"path"
"runtime"
"strconv"

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

func userHomeDir() string {
env := "HOME"
if runtime.GOOS == "windows" {
if sdk.GOOS == "windows" {
env = "USERPROFILE"
} else if runtime.GOOS == "plan9" {
} else if sdk.GOOS == "plan9" {
env = "home"
}
return os.Getenv(env)
Expand Down
4 changes: 2 additions & 2 deletions cli/cdsctl/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"path"
"reflect"
"regexp"
"runtime"
"strings"

"github.com/howeyc/gopass"

"github.com/ovh/cds/cli"
"github.com/ovh/cds/sdk"
"github.com/ovh/cds/sdk/cdsclient"
)

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

if env && runtime.GOOS == "windows" {
if env && sdk.GOOS == "windows" {
fmt.Println("env option is not supported on windows yet")
os.Exit(1)
}
Expand Down
7 changes: 3 additions & 4 deletions cli/cdsctl/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"net/http"
"reflect"
"runtime"

"github.com/inconshreveable/go-update"

Expand All @@ -26,19 +25,19 @@ var updateCmd = cli.Command{
}

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

var urlBinary string
if v.GetBool("from-github") {
// no need to have apiEndpoint here
var errGH error
urlBinary, errGH = client.DownloadURLFromGithub(sdk.GetArtifactFilename("cdsctl", runtime.GOOS, runtime.GOARCH))
urlBinary, errGH = client.DownloadURLFromGithub(sdk.GetArtifactFilename("cdsctl", sdk.GOOS, sdk.GOARCH))
if errGH != nil {
return fmt.Errorf("Error while getting URL from Github url:%s err:%s", urlBinary, errGH)
}
fmt.Printf("Updating binary from Github on %s...\n", urlBinary)
} else {
urlBinary = client.DownloadURLFromAPI("cdsctl", runtime.GOOS, runtime.GOARCH)
urlBinary = client.DownloadURLFromAPI("cdsctl", sdk.GOOS, sdk.GOARCH)
fmt.Printf("Updating binary from CDS API on %s...\n", urlBinary)
}

Expand Down
3 changes: 1 addition & 2 deletions cli/cdsctl/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"runtime"

"github.com/ovh/cds/cli"
"github.com/ovh/cds/sdk"
Expand All @@ -14,7 +13,7 @@ var versionCmd = cli.Command{
}

func versionRun(v cli.Values) error {
fmt.Printf("CDS cdsctl version: %s os:%s architecture:%s\n", sdk.VERSION, runtime.GOOS, runtime.GOARCH)
fmt.Println(sdk.VersionString())
version, err := client.Version()
if err != nil {
return err
Expand Down
4 changes: 3 additions & 1 deletion contrib/grpcplugins/action/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.PHONY: clean

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

TARGET_DIR = dist
TARGET_NAME = $(filter-out $@,$(MAKECMDGOALS))
Expand All @@ -12,7 +14,7 @@ cmd: ./%filename%
endef
export PLUGIN_MANIFEST_BINARY

TARGET_LDFLAGS = -ldflags "-X github.com/ovh/cds/sdk.VERSION=$(VERSION)"
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)"
TARGET_OS = $(if ${OS},${OS},windows darwin linux freebsd)
TARGET_ARCH = $(if ${ARCH},${ARCH},amd64 arm 386)

Expand Down
4 changes: 3 additions & 1 deletion contrib/grpcplugins/deployment/arsenal/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.PHONY: clean

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

TARGET_DIR = ./dist
TARGET_NAME = arsenal
Expand All @@ -15,7 +17,7 @@ cmd: ./%filename%
endef
export PLUGIN_MANIFEST_BINARY

TARGET_LDFLAGS = -ldflags "-X github.com/ovh/cds/sdk.VERSION=$(VERSION)"
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)"
TARGET_OS = $(if ${OS},${OS},windows darwin linux freebsd)
TARGET_ARCH = $(if ${ARCH},${ARCH},amd64 arm 386)

Expand Down
2 changes: 1 addition & 1 deletion docs/content/workflows/pipelines/requirements/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Type of requirements:
- [Network access]({{< relref "/workflows/pipelines/requirements/network_access/_index.md" >}})
- [Service]({{< relref "/workflows/pipelines/requirements/service/_index.md" >}})
- Memory
- OS & Architecture
- [OS & Architecture]({{< relref "/workflows/pipelines/requirements/os_architecture/_index.md" >}})

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
+++
title = "OS & Architecture"
weight = 1

+++

The OS-Architecture prerequisiste allow you to require a worker with a specific OS & Architecture.

**Beware about default value**: there is a default value for OS & Architecture, it's specified in CDS API Configuration.

If user does not specify a prerequisite `os-architecture`, the default value is applied when the job is in CDS Queue.

Then, a hatchery will spawn a worker compiled with the specified `os-architecture` prerequisite.

**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.

### How to set a OS & Architecture

![Step](/images/workflows.pipelines.requirements.os_architecture.choose.png)

### Setup default OS & Architecture on a CDS API Configuration

```toml
#####################
# API Configuration
#####################
[api]

# if no model and no os/arch is specified in your job's requirements then spawn worker on this architecture (example: amd64, arm, 386)
defaultArch = "amd64"

# if no model and os/arch is specified in your job's requirements then spawn worker on this operating system (example: freebsd, linux, windows)
defaultOS = "linux"
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion engine/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
.PHONY: clean

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

TARGET_DIR = ./dist
TARGET_ENGINE = cds-engine
TARGET_LDFLAGS = -ldflags "-X github.com/ovh/cds/sdk.VERSION=$(VERSION)"
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_ENGINE)"
TARGET_OS = $(if ${OS},${OS},windows darwin linux freebsd)
TARGET_ARCH = $(if ${ARCH},${ARCH},amd64 arm 386)

Expand Down
3 changes: 1 addition & 2 deletions engine/api/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import (
"net/http"
"os"
"path"
"runtime"
"testing"

"github.com/ovh/cds/engine/api/test"
)

const dummyBinaryFile = "https://github.com/ovh/cds/releases/download/0.8.1/plugin-download-" + runtime.GOOS + "-amd64"
//const dummyBinaryFile = "https://github.com/ovh/cds/releases/download/0.8.1/plugin-download-" + sdk.GOOS + "-amd64"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?


func downloadFile(t *testing.T, name, url string) (string, func(), error) {
t.Logf("Downloading file %s", url)
Expand Down
8 changes: 1 addition & 7 deletions engine/api/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"net/http"
"runtime"
"sort"
"strings"

Expand All @@ -24,12 +23,7 @@ import (
// VersionHandler returns version of current uservice
func VersionHandler() service.Handler {
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
s := sdk.Version{
Version: sdk.VERSION,
Architecture: runtime.GOARCH,
OS: runtime.GOOS,
}
return service.WriteJSON(w, s, http.StatusOK)
return service.WriteJSON(w, sdk.VersionCurrent(), http.StatusOK)
}
}

Expand Down
5 changes: 2 additions & 3 deletions engine/hatchery/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"html/template"
"os"
"os/exec"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -139,8 +138,8 @@ func (h *HatcheryLocal) Serve(ctx context.Context) error {
Image: h.Name,
Cmd: "worker --api={{.API}} --token={{.Token}} --basedir={{.BaseDir}} --model={{.Model}} --name={{.Name}} --hatchery-name={{.HatcheryName}} --insecure={{.HTTPInsecure}} --graylog-extra-key={{.GraylogExtraKey}} --graylog-extra-value={{.GraylogExtraValue}} --graylog-host={{.GraylogHost}} --graylog-port={{.GraylogPort}} --booked-workflow-job-id={{.WorkflowJobID}} --booked-pb-job-id={{.PipelineBuildJobID}} --single-use --force-exit",
},
RegisteredArch: runtime.GOARCH,
RegisteredOS: runtime.GOOS,
RegisteredArch: sdk.GOARCH,
RegisteredOS: sdk.GOOS,
RegisteredCapabilities: capa,
Provision: int64(h.Config.NbProvision),
}
Expand Down
5 changes: 3 additions & 2 deletions engine/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"os"
"os/signal"
"runtime"
"sort"
"strings"
"syscall"
Expand Down Expand Up @@ -104,7 +103,7 @@ var versionCmd = &cobra.Command{
Use: "version",
Short: "Display CDS version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("CDS Engine version:%s os:%s architecture:%s\n", sdk.VERSION, runtime.GOOS, runtime.GOARCH)
fmt.Println(sdk.VersionString())
},
}

Expand Down Expand Up @@ -505,6 +504,8 @@ See $ engine config command for more details.
GraylogExtraKey: conf.Log.Graylog.ExtraKey,
GraylogExtraValue: conf.Log.Graylog.ExtraValue,
GraylogFieldCDSVersion: sdk.VERSION,
GraylogFieldCDSOS: sdk.GOOS,
GraylogFieldCDSArch: sdk.GOARCH,
GraylogFieldCDSName: strings.Join(names, "_"),
Ctx: ctx,
})
Expand Down
7 changes: 3 additions & 4 deletions engine/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"net/http"
"runtime"

"github.com/inconshreveable/go-update"
"github.com/spf13/cobra"
Expand All @@ -29,18 +28,18 @@ var updateCmd = &cobra.Command{
conf := cdsclient.Config{Host: updateURLAPI}
client := cdsclient.New(conf)

fmt.Printf("CDS engine version:%s os:%s architecture:%s\n", sdk.VERSION, runtime.GOOS, runtime.GOARCH)
fmt.Println(sdk.VersionString())

if updateFromGithub {
// no need to have apiEndpoint here
var errGH error
urlBinary, errGH = client.DownloadURLFromGithub(sdk.GetArtifactFilename("engine", runtime.GOOS, runtime.GOARCH))
urlBinary, errGH = client.DownloadURLFromGithub(sdk.GetArtifactFilename("engine", sdk.GOOS, sdk.GOARCH))
if errGH != nil {
sdk.Exit("Error while getting URL from Github url:%s err:%s\n", urlBinary, errGH)
}
fmt.Printf("Updating binary from Github on %s...\n", urlBinary)
} else {
urlBinary = client.DownloadURLFromAPI("engine", runtime.GOOS, runtime.GOARCH)
urlBinary = client.DownloadURLFromAPI("engine", sdk.GOOS, sdk.GOARCH)
fmt.Printf("Updating binary from CDS API on %s...\n", urlBinary)
}

Expand Down
4 changes: 3 additions & 1 deletion engine/worker/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
.PHONY: clean

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

TARGET_DIR = ./dist
TARGET_BINARY = cds-worker
TARGET_LDFLAGS = -ldflags "-X github.com/ovh/cds/sdk.VERSION=$(VERSION)"
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)"
TARGET_OS = $(if ${OS},${OS},windows darwin linux freebsd)
TARGET_ARCH = $(if ${ARCH},${ARCH},amd64 arm 386)

Expand Down
5 changes: 2 additions & 3 deletions engine/worker/builtin_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"os/exec"
"path"
"runtime"
"strings"

"github.com/kardianos/osext"
Expand Down Expand Up @@ -42,7 +41,7 @@ func runScriptAction(w *currentWorker) BuiltInAction {
var opts []string

// except on windows where it's powershell
if runtime.GOOS == "windows" {
if sdk.GOOS == "windows" {
shell = "PowerShell"
opts = append(opts, "-ExecutionPolicy", "Bypass", "-Command")
// on windows, we add ErrorActionPreference just below
Expand Down Expand Up @@ -89,7 +88,7 @@ func runScriptAction(w *currentWorker) BuiltInAction {
oldPath := tmpscript.Name()
tmpscript.Close()
var scriptPath string
if runtime.GOOS == "windows" {
if sdk.GOOS == "windows" {
//Remove all .txt Extensions, there is not always a .txt extension
newPath := strings.Replace(oldPath, ".txt", "", -1)
//and add .PS1 extension
Expand Down
7 changes: 3 additions & 4 deletions engine/worker/cmd_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"crypto/tls"
"fmt"
"net/http"
"runtime"
"time"

"github.com/facebookgo/httpcontrol"
Expand Down Expand Up @@ -39,7 +38,7 @@ Update from your CDS API:

func updateCmd(w *currentWorker) func(cmd *cobra.Command, args []string) {
return func(cmd *cobra.Command, args []string) {
fmt.Printf("CDS Worker version:%s os:%s architecture:%s\n", sdk.VERSION, runtime.GOOS, runtime.GOARCH)
fmt.Println(sdk.VersionString())
var urlBinary string
if !FlagBool(cmd, "from-github") {
w.apiEndpoint = FlagString(cmd, flagAPI)
Expand All @@ -53,14 +52,14 @@ func updateCmd(w *currentWorker) func(cmd *cobra.Command, args []string) {
},
})

urlBinary = w.client.DownloadURLFromAPI("worker", runtime.GOOS, runtime.GOARCH)
urlBinary = w.client.DownloadURLFromAPI("worker", sdk.GOOS, sdk.GOARCH)
fmt.Printf("Updating worker binary from CDS API on %s...\n", urlBinary)
} else {
// no need to have apiEndpoint here
w.client = cdsclient.NewWorker("", "download", nil)

var errGH error
urlBinary, errGH = w.client.DownloadURLFromGithub(sdk.GetArtifactFilename("worker", runtime.GOOS, runtime.GOARCH))
urlBinary, errGH = w.client.DownloadURLFromGithub(sdk.GetArtifactFilename("worker", sdk.GOOS, sdk.GOARCH))
if errGH != nil {
sdk.Exit("Error while getting URL from Github: %s", errGH)
}
Expand Down
Loading