diff --git a/command/daemon/config.go b/command/daemon/config.go index d4fb455..339803a 100644 --- a/command/daemon/config.go +++ b/command/daemon/config.go @@ -7,6 +7,7 @@ package daemon import ( "fmt" "os" + "runtime" "github.com/joho/godotenv" "github.com/kelseyhightower/envconfig" @@ -54,12 +55,23 @@ type Config struct { } Runner struct { - Name string `envconfig:"DRONE_RUNNER_NAME"` - Capacity int `envconfig:"DRONE_RUNNER_CAPACITY" default:"10"` - Procs int64 `envconfig:"DRONE_RUNNER_MAX_PROCS"` - Labels map[string]string `envconfig:"DRONE_RUNNER_LABELS"` - Environ map[string]string `envconfig:"DRONE_RUNNER_ENVIRON"` - EnvFile string `envconfig:"DRONE_RUNNER_ENV_FILE"` + Name string `envconfig:"DRONE_RUNNER_NAME"` + Capacity int `envconfig:"DRONE_RUNNER_CAPACITY" default:"2"` + Procs int64 `envconfig:"DRONE_RUNNER_MAX_PROCS"` + Environ map[string]string `envconfig:"DRONE_RUNNER_ENVIRON"` + EnvFile string `envconfig:"DRONE_RUNNER_ENV_FILE"` + Labels map[string]string `envconfig:"DRONE_RUNNER_LABELS"` + Volumes map[string]string `envconfig:"DRONE_RUNNER_VOLUMES"` + Devices []string `envconfig:"DRONE_RUNNER_DEVICES"` + Networks []string `envconfig:"DRONE_RUNNER_NETWORKS"` + Privileged []string `envconfig:"DRONE_RUNNER_PRIVILEGED_IMAGES"` + } + + Platform struct { + OS string `envconfig:"DRONE_PLATFORM_OS"` + Arch string `envconfig:"DRONE_PLATFORM_ARCH"` + Kernel string `envconfig:"DRONE_PLATFORM_KERNEL"` + Variant string `envconfig:"DRONE_PLATFORM_VARIANT"` } Limit struct { @@ -73,6 +85,16 @@ type Config struct { Token string `envconfig:"DRONE_SECRET_PLUGIN_TOKEN"` SkipVerify bool `envconfig:"DRONE_SECRET_PLUGIN_SKIP_VERIFY"` } + + Registry struct { + Endpoint string `envconfig:"DRONE_REGISTRY_PLUGIN_ENDPOINT"` + Token string `envconfig:"DRONE_REGISTRY_PLUGIN_SECRET"` + SkipVerify bool `envconfig:"DRONE_REGISTRY_PLUGIN_SKIP_VERIFY"` + } + + Docker struct { + Config string `envconfig:"DRONE_DOCKER_CONFIG"` + } } func fromEnviron() (Config, error) { @@ -93,6 +115,13 @@ func fromEnviron() (Config, error) { config.Client.Host, ) + if config.Platform.OS == "" { + config.Platform.OS = runtime.GOOS + } + if config.Platform.Arch == "" { + config.Platform.Arch = runtime.GOARCH + } + // environment variables can be sourced from a separate // file. These variables are loaded and appended to the // environment list. diff --git a/command/daemon/daemon.go b/command/daemon/daemon.go index fcff330..88d35af 100644 --- a/command/daemon/daemon.go +++ b/command/daemon/daemon.go @@ -21,6 +21,7 @@ import ( loghistory "github.com/drone/runner-go/logger/history" "github.com/drone/runner-go/pipeline/history" "github.com/drone/runner-go/pipeline/remote" + "github.com/drone/runner-go/registry" "github.com/drone/runner-go/secret" "github.com/drone/runner-go/server" "github.com/drone/signal" @@ -115,13 +116,21 @@ func (c *daemonCommand) run(*kingpin.ParseContext) error { config.Limit.Trusted, ), Compiler: &compiler.Compiler{ - Environ: nil, - Labels: nil, - Privileged: nil, - Networks: nil, - Volumes: nil, + Environ: config.Runner.Environ, + Privileged: config.Runner.Privileged, + Networks: config.Runner.Networks, + Volumes: config.Runner.Volumes, // Resources: nil, - Registry: nil, + Registry: registry.Combine( + registry.File( + config.Docker.Config, + ), + registry.External( + config.Registry.Endpoint, + config.Registry.Token, + config.Registry.SkipVerify, + ), + ), Secret: secret.External( config.Secret.Endpoint, config.Secret.Token, @@ -136,9 +145,13 @@ func (c *daemonCommand) run(*kingpin.ParseContext) error { ), }, Filter: &client.Filter{ - Kind: resource.Kind, - Type: resource.Type, - Labels: config.Runner.Labels, + Kind: resource.Kind, + Type: resource.Type, + OS: config.Platform.OS, + Arch: config.Platform.Arch, + Variant: config.Platform.Variant, + Kernel: config.Platform.Kernel, + Labels: config.Runner.Labels, }, } diff --git a/docker/Docker.windows.amd64.1809 b/docker/Docker.windows.amd64.1809 index 9517493..5438893 100644 --- a/docker/Docker.windows.amd64.1809 +++ b/docker/Docker.windows.amd64.1809 @@ -4,6 +4,9 @@ USER ContainerAdministrator EXPOSE 3000 ENV GODEBUG=netdns=go +ENV DRONE_PLATFORM_OS windows +ENV DRONE_PLATFORM_ARCH amd64 +ENV DRONE_PLATFORM_KERNEL 1809 ADD release/windows/amd64/drone-runner-docker.exe C:/drone-runner-docker.exe ENTRYPOINT [ "C:\\drone-runner-docker.exe" ] diff --git a/docker/Docker.windows.amd64.1903 b/docker/Docker.windows.amd64.1903 index e04524b..552c6c8 100644 --- a/docker/Docker.windows.amd64.1903 +++ b/docker/Docker.windows.amd64.1903 @@ -3,7 +3,10 @@ FROM mcr.microsoft.com/windows/nanoserver:1903 USER ContainerAdministrator EXPOSE 3000 -ENV GODEBUG=netdns=go +ENV GODEBUG netdns=go +ENV DRONE_PLATFORM_OS windows +ENV DRONE_PLATFORM_ARCH amd64 +ENV DRONE_PLATFORM_KERNEL 1903 ADD release/windows/amd64/drone-runner-docker.exe C:/drone-runner-docker.exe ENTRYPOINT [ "C:\\drone-runner-docker.exe" ] \ No newline at end of file diff --git a/docker/Dockerfile.linux.amd64 b/docker/Dockerfile.linux.amd64 index f77f2c4..a92889b 100644 --- a/docker/Dockerfile.linux.amd64 +++ b/docker/Dockerfile.linux.amd64 @@ -5,8 +5,10 @@ FROM alpine:3.6 EXPOSE 3000 ENV GODEBUG netdns=go +ENV DRONE_PLATFORM_OS linux +ENV DRONE_PLATFORM_ARCH arm64 COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -ADD release/linux/amd64/drone-runner-docker /bin/ +ADD release/linux/arm64/drone-runner-docker /bin/ ENTRYPOINT ["/bin/drone-runner-docker"] diff --git a/docker/Dockerfile.linux.arm b/docker/Dockerfile.linux.arm index d2a3a37..64b5378 100644 --- a/docker/Dockerfile.linux.arm +++ b/docker/Dockerfile.linux.arm @@ -5,6 +5,8 @@ FROM alpine:3.6 EXPOSE 3000 ENV GODEBUG netdns=go +ENV DRONE_PLATFORM_OS linux +ENV DRONE_PLATFORM_ARCH arm COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ diff --git a/docker/Dockerfile.linux.arm64 b/docker/Dockerfile.linux.arm64 index 9f0e2b5..15d68e4 100644 --- a/docker/Dockerfile.linux.arm64 +++ b/docker/Dockerfile.linux.arm64 @@ -5,6 +5,8 @@ FROM alpine:3.6 EXPOSE 3000 ENV GODEBUG netdns=go +ENV DRONE_PLATFORM_OS linux +ENV DRONE_PLATFORM_ARCH amd64 COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ diff --git a/engine/compiler/clone_test.go b/engine/compiler/clone_test.go index be4f2f5..0799f8e 100644 --- a/engine/compiler/clone_test.go +++ b/engine/compiler/clone_test.go @@ -12,6 +12,8 @@ import ( "github.com/drone-runners/drone-runner-docker/engine/resource" "github.com/drone/drone-go/drone" "github.com/drone/runner-go/manifest" + "github.com/drone/runner-go/registry" + "github.com/drone/runner-go/secret" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" @@ -24,6 +26,10 @@ func TestClone(t *testing.T) { }() c := &Compiler{ + Registry: registry.Static(nil), + Secret: secret.Static(nil), + } + args := Args{ Repo: &drone.Repo{}, Build: &drone.Build{}, Stage: &drone.Stage{}, @@ -37,12 +43,19 @@ func TestClone(t *testing.T) { ID: "random", Image: "drone/git:1", Name: "clone", + Pull: engine.PullDefault, RunPolicy: engine.RunAlways, WorkingDir: "/drone/src", + Volumes: []*engine.VolumeMount{ + &engine.VolumeMount{ + Name: "_workspace", + Path: "/drone/src", + }, + }, }, } - got := c.Compile(nil) - ignore := cmpopts.IgnoreFields(engine.Step{}, "Envs") + got := c.Compile(nocontext, args) + ignore := cmpopts.IgnoreFields(engine.Step{}, "Envs", "Labels") if diff := cmp.Diff(got.Steps, want, ignore); len(diff) != 0 { t.Errorf(diff) } @@ -50,6 +63,10 @@ func TestClone(t *testing.T) { func TestCloneDisable(t *testing.T) { c := &Compiler{ + Registry: registry.Static(nil), + Secret: secret.Static(nil), + } + args := Args{ Repo: &drone.Repo{}, Build: &drone.Build{}, Stage: &drone.Stage{}, @@ -58,7 +75,7 @@ func TestCloneDisable(t *testing.T) { Manifest: &manifest.Manifest{}, Pipeline: &resource.Pipeline{Clone: manifest.Clone{Disable: true}}, } - got := c.Compile(nil) + got := c.Compile(nocontext, args) if len(got.Steps) != 0 { t.Errorf("Expect no clone step added when disabled") } diff --git a/engine/compiler/compiler_test.go b/engine/compiler/compiler_test.go index b2d88f9..22f8900 100644 --- a/engine/compiler/compiler_test.go +++ b/engine/compiler/compiler_test.go @@ -18,6 +18,7 @@ import ( "github.com/drone-runners/drone-runner-docker/engine/resource" "github.com/drone/drone-go/drone" "github.com/drone/runner-go/manifest" + "github.com/drone/runner-go/registry" "github.com/drone/runner-go/secret" "github.com/google/go-cmp/cmp" @@ -82,7 +83,7 @@ func TestCompile_RunAlways(t *testing.T) { // This test verifies that steps configured to run on failure // are configured to run on failure. -func TestCompile_RunFaiure(t *testing.T) { +func TestCompile_RunFailure(t *testing.T) { ir := testCompile(t, "testdata/run_failure.yml", "testdata/run_failure.json") if ir.Steps[0].RunPolicy != engine.RunOnFailure { t.Errorf("Expect run on failure") @@ -94,20 +95,27 @@ func TestCompile_RunFaiure(t *testing.T) { // at compile time. func TestCompile_Secrets(t *testing.T) { manifest, _ := manifest.ParseFile("testdata/secret.yml") - compiler := Compiler{} - compiler.Build = &drone.Build{} - compiler.Repo = &drone.Repo{} - compiler.Stage = &drone.Stage{} - compiler.System = &drone.System{} - compiler.Netrc = &drone.Netrc{} - compiler.Manifest = manifest - compiler.Pipeline = manifest.Resources[0].(*resource.Pipeline) - compiler.Secret = secret.StaticVars(map[string]string{ - "token": "3DA541559918A808C2402BBA5012F6C60B27661C", - "password": "password", - "my_username": "octocat", - }) - ir := compiler.Compile(nocontext) + + compiler := &Compiler{ + Registry: registry.Static(nil), + Secret: secret.StaticVars(map[string]string{ + "token": "3DA541559918A808C2402BBA5012F6C60B27661C", + "password": "password", + "my_username": "octocat", + }), + } + args := Args{ + Repo: &drone.Repo{}, + Build: &drone.Build{}, + Stage: &drone.Stage{}, + System: &drone.System{}, + Netrc: &drone.Netrc{}, + Manifest: manifest, + Pipeline: manifest.Resources[0].(*resource.Pipeline), + Secret: secret.Static(nil), + } + + ir := compiler.Compile(nocontext, args) got := ir.Steps[0].Secrets want := []*engine.Secret{ { @@ -149,15 +157,26 @@ func testCompile(t *testing.T, source, golden string) *engine.Spec { return nil } - compiler := Compiler{} - compiler.Build = &drone.Build{Target: "master"} - compiler.Repo = &drone.Repo{} - compiler.Stage = &drone.Stage{} - compiler.System = &drone.System{} - compiler.Netrc = &drone.Netrc{Machine: "github.com", Login: "octocat", Password: "correct-horse-battery-staple"} - compiler.Manifest = manifest - compiler.Pipeline = manifest.Resources[0].(*resource.Pipeline) - got := compiler.Compile(nocontext) + compiler := &Compiler{ + Registry: registry.Static(nil), + Secret: secret.StaticVars(map[string]string{ + "token": "3DA541559918A808C2402BBA5012F6C60B27661C", + "password": "password", + "my_username": "octocat", + }), + } + args := Args{ + Repo: &drone.Repo{}, + Build: &drone.Build{Target: "master"}, + Stage: &drone.Stage{}, + System: &drone.System{}, + Netrc: &drone.Netrc{Machine: "github.com", Login: "octocat", Password: "correct-horse-battery-staple"}, + Manifest: manifest, + Pipeline: manifest.Resources[0].(*resource.Pipeline), + Secret: secret.Static(nil), + } + + got := compiler.Compile(nocontext, args) raw, err := ioutil.ReadFile(golden) if err != nil { @@ -170,10 +189,15 @@ func testCompile(t *testing.T, source, golden string) *engine.Spec { t.Error(err) } - ignore := cmpopts.IgnoreFields(engine.Step{}, "Envs", "Secrets") - unexported := cmpopts.IgnoreUnexported(engine.Spec{}) - if diff := cmp.Diff(got, want, ignore, unexported); len(diff) != 0 { + opts := cmp.Options{ + cmpopts.IgnoreUnexported(engine.Spec{}), + cmpopts.IgnoreFields(engine.Step{}, "Envs", "Secrets", "Labels"), + cmpopts.IgnoreFields(engine.Network{}, "Labels"), + cmpopts.IgnoreFields(engine.VolumeEmptyDir{}, "Labels"), + } + if diff := cmp.Diff(got, want, opts...); len(diff) != 0 { t.Errorf(diff) + dump(got) } return got diff --git a/engine/compiler/os.go b/engine/compiler/os.go deleted file mode 100644 index 5522c39..0000000 --- a/engine/compiler/os.go +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Polyform License -// that can be found in the LICENSE file. - -package compiler - -import ( - "fmt" - "strings" - - "github.com/drone/runner-go/shell/bash" - "github.com/drone/runner-go/shell/powershell" -) - -// helper function returns the base temporary directory based -// on the target platform. -func tempdir(os string) string { - dir := fmt.Sprintf("drone-%s", random()) - switch os { - case "windows": - return join(os, "C:\\Windows\\Temp", dir) - default: - return join(os, "/tmp", dir) - } -} - -// helper function joins the file paths. -func join(os string, paths ...string) string { - switch os { - case "windows": - return strings.Join(paths, "\\") - default: - return strings.Join(paths, "/") - } -} - -// helper function returns the shell extension based on the -// target platform. -func getExt(os, file string) (s string) { - switch os { - case "windows": - return file + ".ps1" - default: - return file - } -} - -// -// TODO(bradrydzewski) can we remove the below functions? -// - -// helper function returns the shell command and arguments -// based on the target platform to invoke the script -func getCommand(os, script string) (string, []string) { - cmd, args := bash.Command() - switch os { - case "windows": - cmd, args = powershell.Command() - } - return cmd, append(args, script) -} - -// helper function returns the netrc file name based on the -// target platform. -func getNetrc(os string) string { - switch os { - case "windows": - return "_netrc" - default: - return ".netrc" - } -} - -// helper function generates and returns a shell script to -// execute the provided shell commands. The shell scripting -// language (bash vs pwoershell) is determined by the operating -// system. -func genScript(os string, commands []string) string { - switch os { - case "windows": - return powershell.Script(commands) - default: - return bash.Script(commands) - } -} diff --git a/engine/compiler/os_test.go b/engine/compiler/os_test.go deleted file mode 100644 index 9eb9bff..0000000 --- a/engine/compiler/os_test.go +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Polyform License -// that can be found in the LICENSE file. - -package compiler - -import ( - "reflect" - "testing" - - "github.com/drone/runner-go/shell/bash" - "github.com/drone/runner-go/shell/powershell" - - "github.com/dchest/uniuri" -) - -func Test_tempdir(t *testing.T) { - // replace the default random function with one that - // is deterministic, for testing purposes. - random = notRandom - - // restore the default random function and the previously - // specified temporary directory - defer func() { - random = uniuri.New - }() - - tests := []struct { - os string - path string - }{ - {os: "windows", path: "C:\\Windows\\Temp\\drone-random"}, - {os: "linux", path: "/tmp/drone-random"}, - {os: "openbsd", path: "/tmp/drone-random"}, - {os: "netbsd", path: "/tmp/drone-random"}, - {os: "freebsd", path: "/tmp/drone-random"}, - } - - for _, test := range tests { - if got, want := tempdir(test.os), test.path; got != want { - t.Errorf("Want tempdir %s, got %s", want, got) - } - } -} - -func Test_join(t *testing.T) { - tests := []struct { - os string - a []string - b string - }{ - {os: "windows", a: []string{"C:", "Windows", "Temp"}, b: "C:\\Windows\\Temp"}, - {os: "linux", a: []string{"/tmp", "foo", "bar"}, b: "/tmp/foo/bar"}, - } - for _, test := range tests { - if got, want := join(test.os, test.a...), test.b; got != want { - t.Errorf("Want %s, got %s", want, got) - } - } -} - -func Test_getExt(t *testing.T) { - tests := []struct { - os string - a string - b string - }{ - {os: "windows", a: "clone", b: "clone.ps1"}, - {os: "linux", a: "clone", b: "clone"}, - } - for _, test := range tests { - if got, want := getExt(test.os, test.a), test.b; got != want { - t.Errorf("Want %s, got %s", want, got) - } - } -} - -func Test_getCommand(t *testing.T) { - cmd, args := getCommand("linux", "clone.sh") - if got, want := cmd, "/bin/sh"; got != want { - t.Errorf("Want command %s, got %s", want, got) - } - if !reflect.DeepEqual(args, []string{"-e", "clone.sh"}) { - t.Errorf("Unexpected args %v", args) - } - - cmd, args = getCommand("windows", "clone.ps1") - if got, want := cmd, "powershell"; got != want { - t.Errorf("Want command %s, got %s", want, got) - } - if !reflect.DeepEqual(args, []string{"-noprofile", "-noninteractive", "-command", "clone.ps1"}) { - t.Errorf("Unexpected args %v", args) - } -} - -func Test_getNetrc(t *testing.T) { - tests := []struct { - os string - name string - }{ - {os: "windows", name: "_netrc"}, - {os: "linux", name: ".netrc"}, - {os: "openbsd", name: ".netrc"}, - {os: "netbsd", name: ".netrc"}, - {os: "freebsd", name: ".netrc"}, - } - for _, test := range tests { - if got, want := getNetrc(test.os), test.name; got != want { - t.Errorf("Want %s on %s, got %s", want, test.os, got) - } - } -} - -func Test_getScript(t *testing.T) { - commands := []string{"go build"} - - a := genScript("windows", commands) - b := powershell.Script(commands) - if !reflect.DeepEqual(a, b) { - t.Errorf("Generated windows linux script") - } - - a = genScript("linux", commands) - b = bash.Script(commands) - if !reflect.DeepEqual(a, b) { - t.Errorf("Generated invalid linux script") - } -} diff --git a/engine/compiler/script.go b/engine/compiler/script.go index 0947b82..b4a5331 100644 --- a/engine/compiler/script.go +++ b/engine/compiler/script.go @@ -11,6 +11,8 @@ import ( "github.com/drone-runners/drone-runner-docker/engine/resource" ) +// helper function configures the pipeline script for the +// target operating system. func setupScript(src *resource.Step, dst *engine.Step, os string) { if len(src.Commands) > 0 { switch os { @@ -22,12 +24,16 @@ func setupScript(src *resource.Step, dst *engine.Step, os string) { } } +// helper function configures the pipeline script for the +// windows operating system. func setupScriptWindows(src *resource.Step, dst *engine.Step) { dst.Entrypoint = []string{"powershell", "-noprofile", "-noninteractive", "-command"} dst.Command = []string{"echo $DRONE_SCRIPT | iex"} dst.Envs["DRONE_SCRIPT"] = powershell.Script(src.Commands) } +// helper function configures the pipeline script for the +// linux operating system. func setupScriptPosix(src *resource.Step, dst *engine.Step) { dst.Entrypoint = []string{"/bin/sh", "-c"} dst.Command = []string{`echo "$DRONE_SCRIPT" | /bin/sh`} diff --git a/engine/compiler/testdata/graph.json b/engine/compiler/testdata/graph.json index 33e15cd..9590279 100644 --- a/engine/compiler/testdata/graph.json +++ b/engine/compiler/testdata/graph.json @@ -1,104 +1,366 @@ { "platform": {}, - "token": "3DA541559918A808C2402BBA5012F6C60B27661C", - "server": { - "name": "drone-temp-random", - "image": "docker-18-04", - "region": "nyc1", - "size": "s-1vcpu-1gb", - "user": "root" - }, - "root": "/tmp/drone-random", - "files": [ - { - "path": "/tmp/drone-random/home", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/home/drone", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/drone", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/drone/src", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/opt", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/home/drone/.netrc", - "mode": 384, - "data": "bWFjaGluZSBnaXRodWIuY29tIGxvZ2luIG9jdG9jYXQgcGFzc3dvcmQgY29ycmVjdC1ob3JzZS1iYXR0ZXJ5LXN0YXBsZQ==" - } - ], "steps": [ { - "args": [ - "-e", - "/tmp/drone-random/opt/clone" - ], - "command": "/bin/sh", - "files": [ + "id": "random", + "environment": { + "CI": "true", + "DRONE": "true", + "DRONE_BRANCH": "master", + "DRONE_BUILD_ACTION": "", + "DRONE_BUILD_CREATED": "0", + "DRONE_BUILD_EVENT": "", + "DRONE_BUILD_FINISHED": "1571810984", + "DRONE_BUILD_LINK": ":////0", + "DRONE_BUILD_NUMBER": "0", + "DRONE_BUILD_PARENT": "0", + "DRONE_BUILD_STARTED": "1571810984", + "DRONE_BUILD_STATUS": "success", + "DRONE_COMMIT": "", + "DRONE_COMMIT_AFTER": "", + "DRONE_COMMIT_AUTHOR": "", + "DRONE_COMMIT_AUTHOR_AVATAR": "", + "DRONE_COMMIT_AUTHOR_EMAIL": "", + "DRONE_COMMIT_AUTHOR_NAME": "", + "DRONE_COMMIT_BEFORE": "", + "DRONE_COMMIT_BRANCH": "master", + "DRONE_COMMIT_LINK": "", + "DRONE_COMMIT_MESSAGE": "", + "DRONE_COMMIT_REF": "", + "DRONE_COMMIT_SHA": "", + "DRONE_DEPLOY_TO": "", + "DRONE_DOCKER_NETWORK_ID": "random", + "DRONE_DOCKER_VOLUME_ID": "random", + "DRONE_GIT_HTTP_URL": "", + "DRONE_GIT_SSH_URL": "", + "DRONE_NETRC_FILE": "machine github.com login octocat password correct-horse-battery-staple", + "DRONE_NETRC_MACHINE": "github.com", + "DRONE_NETRC_PASSWORD": "correct-horse-battery-staple", + "DRONE_NETRC_USERNAME": "octocat", + "DRONE_REMOTE_URL": "", + "DRONE_REPO": "", + "DRONE_REPO_BRANCH": "", + "DRONE_REPO_LINK": "", + "DRONE_REPO_NAME": "", + "DRONE_REPO_NAMESPACE": "", + "DRONE_REPO_OWNER": "", + "DRONE_REPO_PRIVATE": "false", + "DRONE_REPO_SCM": "", + "DRONE_REPO_VISIBILITY": "", + "DRONE_SOURCE_BRANCH": "", + "DRONE_STAGE_ARCH": "", + "DRONE_STAGE_DEPENDS_ON": "", + "DRONE_STAGE_FINISHED": "1571810984", + "DRONE_STAGE_KIND": "", + "DRONE_STAGE_MACHINE": "", + "DRONE_STAGE_NAME": "", + "DRONE_STAGE_NUMBER": "0", + "DRONE_STAGE_OS": "", + "DRONE_STAGE_STARTED": "1571810984", + "DRONE_STAGE_STATUS": "success", + "DRONE_STAGE_TYPE": "", + "DRONE_STAGE_VARIANT": "", + "DRONE_SYSTEM_HOST": "", + "DRONE_SYSTEM_HOSTNAME": "", + "DRONE_SYSTEM_PROTO": "", + "DRONE_SYSTEM_VERSION": "", + "DRONE_TARGET_BRANCH": "master", + "DRONE_WORKSPACE": "/drone/src", + "DRONE_WORKSPACE_BASE": "/drone/src", + "DRONE_WORKSPACE_PATH": "", + "GIT_AUTHOR_EMAIL": "noreply@drone", + "GIT_AUTHOR_NAME": "drone", + "GIT_COMMITTER_EMAIL": "noreply@drone", + "GIT_COMMITTER_NAME": "drone", + "GIT_TERMINAL_PROMPT": "0" + }, + "image": "drone/git:1", + "labels": { + "io.drone": "true", + "io.drone.build.number": "0", + "io.drone.created": "1571810984", + "io.drone.expires": "1571814584", + "io.drone.protected": "false", + "io.drone.repo.name": "", + "io.drone.repo.namespace": "", + "io.drone.repo.slug": "", + "io.drone.stage.name": "", + "io.drone.stage.number": "0", + "io.drone.system.host": "", + "io.drone.system.proto": "", + "io.drone.system.version": "", + "io.drone.ttl": "0s" + }, + "name": "clone", + "run_policy": "always", + "volumes": [ { - "path": "/tmp/drone-random/opt/clone", - "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnaXQgaW5pdCIKZ2l0IGluaXQKCmVjaG8gKyAiZ2l0IHJlbW90ZSBhZGQgb3JpZ2luICIKZ2l0IHJlbW90ZSBhZGQgb3JpZ2luIAoKZWNobyArICJnaXQgZmV0Y2ggIG9yaWdpbiArcmVmcy9oZWFkcy9tYXN0ZXI6IgpnaXQgZmV0Y2ggIG9yaWdpbiArcmVmcy9oZWFkcy9tYXN0ZXI6CgplY2hvICsgImdpdCBjaGVja291dCAgLWIgbWFzdGVyIgpnaXQgY2hlY2tvdXQgIC1iIG1hc3Rlcgo=" + "name": "_workspace", + "path": "/drone/src" } ], - "secrets": [], - "name": "clone", - "run_policy": 2, - "working_dir": "/tmp/drone-random/drone/src" + "working_dir": "/drone/src" }, { + "id": "random", "args": [ - "-e", - "/tmp/drone-random/opt/build" + "echo \"$DRONE_SCRIPT\" | /bin/sh" ], - "command": "/bin/sh", "depends_on": [ "clone" ], - "files": [ + "entrypoint": [ + "/bin/sh", + "-c" + ], + "environment": { + "CI": "true", + "DRONE": "true", + "DRONE_BRANCH": "master", + "DRONE_BUILD_ACTION": "", + "DRONE_BUILD_CREATED": "0", + "DRONE_BUILD_EVENT": "", + "DRONE_BUILD_FINISHED": "1571810984", + "DRONE_BUILD_LINK": ":////0", + "DRONE_BUILD_NUMBER": "0", + "DRONE_BUILD_PARENT": "0", + "DRONE_BUILD_STARTED": "1571810984", + "DRONE_BUILD_STATUS": "success", + "DRONE_COMMIT": "", + "DRONE_COMMIT_AFTER": "", + "DRONE_COMMIT_AUTHOR": "", + "DRONE_COMMIT_AUTHOR_AVATAR": "", + "DRONE_COMMIT_AUTHOR_EMAIL": "", + "DRONE_COMMIT_AUTHOR_NAME": "", + "DRONE_COMMIT_BEFORE": "", + "DRONE_COMMIT_BRANCH": "master", + "DRONE_COMMIT_LINK": "", + "DRONE_COMMIT_MESSAGE": "", + "DRONE_COMMIT_REF": "", + "DRONE_COMMIT_SHA": "", + "DRONE_DEPLOY_TO": "", + "DRONE_DOCKER_NETWORK_ID": "random", + "DRONE_DOCKER_VOLUME_ID": "random", + "DRONE_GIT_HTTP_URL": "", + "DRONE_GIT_SSH_URL": "", + "DRONE_NETRC_FILE": "machine github.com login octocat password correct-horse-battery-staple", + "DRONE_NETRC_MACHINE": "github.com", + "DRONE_NETRC_PASSWORD": "correct-horse-battery-staple", + "DRONE_NETRC_USERNAME": "octocat", + "DRONE_REMOTE_URL": "", + "DRONE_REPO": "", + "DRONE_REPO_BRANCH": "", + "DRONE_REPO_LINK": "", + "DRONE_REPO_NAME": "", + "DRONE_REPO_NAMESPACE": "", + "DRONE_REPO_OWNER": "", + "DRONE_REPO_PRIVATE": "false", + "DRONE_REPO_SCM": "", + "DRONE_REPO_VISIBILITY": "", + "DRONE_SCRIPT": "\n\nif [ ! -z \"${DRONE_NETRC_FILE}\" ]; then\n\techo $DRONE_NETRC_FILE \u003e $HOME/.netrc\nfi\n\nunset DRONE_SCRIPT\nunset DRONE_NETRC_MACHINE\nunset DRONE_NETRC_USERNAME\nunset DRONE_NETRC_PASSWORD\nunset DRONE_NETRC_FILE\n\nset -e\n\n\necho + \"go build\"\ngo build\n", + "DRONE_SOURCE_BRANCH": "", + "DRONE_STAGE_ARCH": "", + "DRONE_STAGE_DEPENDS_ON": "", + "DRONE_STAGE_FINISHED": "1571810984", + "DRONE_STAGE_KIND": "", + "DRONE_STAGE_MACHINE": "", + "DRONE_STAGE_NAME": "", + "DRONE_STAGE_NUMBER": "0", + "DRONE_STAGE_OS": "", + "DRONE_STAGE_STARTED": "1571810984", + "DRONE_STAGE_STATUS": "success", + "DRONE_STAGE_TYPE": "", + "DRONE_STAGE_VARIANT": "", + "DRONE_SYSTEM_HOST": "", + "DRONE_SYSTEM_HOSTNAME": "", + "DRONE_SYSTEM_PROTO": "", + "DRONE_SYSTEM_VERSION": "", + "DRONE_TARGET_BRANCH": "master", + "DRONE_WORKSPACE": "/drone/src", + "DRONE_WORKSPACE_BASE": "/drone/src", + "DRONE_WORKSPACE_PATH": "", + "GIT_AUTHOR_EMAIL": "noreply@drone", + "GIT_AUTHOR_NAME": "drone", + "GIT_COMMITTER_EMAIL": "noreply@drone", + "GIT_COMMITTER_NAME": "drone", + "GIT_TERMINAL_PROMPT": "0" + }, + "labels": { + "io.drone": "true", + "io.drone.build.number": "0", + "io.drone.created": "1571810984", + "io.drone.expires": "1571814584", + "io.drone.protected": "false", + "io.drone.repo.name": "", + "io.drone.repo.namespace": "", + "io.drone.repo.slug": "", + "io.drone.stage.name": "", + "io.drone.stage.number": "0", + "io.drone.system.host": "", + "io.drone.system.proto": "", + "io.drone.system.version": "", + "io.drone.ttl": "0s" + }, + "name": "build", + "volumes": [ { - "path": "/tmp/drone-random/opt/build", - "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQK" + "name": "_workspace", + "path": "/drone/src" } ], - "secrets": [], - "name": "build", - "working_dir": "/tmp/drone-random/drone/src" + "working_dir": "/drone/src" }, { + "id": "random", "args": [ - "-e", - "/tmp/drone-random/opt/test" + "echo \"$DRONE_SCRIPT\" | /bin/sh" ], - "command": "/bin/sh", "depends_on": [ "build" ], - "files": [ + "entrypoint": [ + "/bin/sh", + "-c" + ], + "environment": { + "CI": "true", + "DRONE": "true", + "DRONE_BRANCH": "master", + "DRONE_BUILD_ACTION": "", + "DRONE_BUILD_CREATED": "0", + "DRONE_BUILD_EVENT": "", + "DRONE_BUILD_FINISHED": "1571810984", + "DRONE_BUILD_LINK": ":////0", + "DRONE_BUILD_NUMBER": "0", + "DRONE_BUILD_PARENT": "0", + "DRONE_BUILD_STARTED": "1571810984", + "DRONE_BUILD_STATUS": "success", + "DRONE_COMMIT": "", + "DRONE_COMMIT_AFTER": "", + "DRONE_COMMIT_AUTHOR": "", + "DRONE_COMMIT_AUTHOR_AVATAR": "", + "DRONE_COMMIT_AUTHOR_EMAIL": "", + "DRONE_COMMIT_AUTHOR_NAME": "", + "DRONE_COMMIT_BEFORE": "", + "DRONE_COMMIT_BRANCH": "master", + "DRONE_COMMIT_LINK": "", + "DRONE_COMMIT_MESSAGE": "", + "DRONE_COMMIT_REF": "", + "DRONE_COMMIT_SHA": "", + "DRONE_DEPLOY_TO": "", + "DRONE_DOCKER_NETWORK_ID": "random", + "DRONE_DOCKER_VOLUME_ID": "random", + "DRONE_GIT_HTTP_URL": "", + "DRONE_GIT_SSH_URL": "", + "DRONE_NETRC_FILE": "machine github.com login octocat password correct-horse-battery-staple", + "DRONE_NETRC_MACHINE": "github.com", + "DRONE_NETRC_PASSWORD": "correct-horse-battery-staple", + "DRONE_NETRC_USERNAME": "octocat", + "DRONE_REMOTE_URL": "", + "DRONE_REPO": "", + "DRONE_REPO_BRANCH": "", + "DRONE_REPO_LINK": "", + "DRONE_REPO_NAME": "", + "DRONE_REPO_NAMESPACE": "", + "DRONE_REPO_OWNER": "", + "DRONE_REPO_PRIVATE": "false", + "DRONE_REPO_SCM": "", + "DRONE_REPO_VISIBILITY": "", + "DRONE_SCRIPT": "\n\nif [ ! -z \"${DRONE_NETRC_FILE}\" ]; then\n\techo $DRONE_NETRC_FILE \u003e $HOME/.netrc\nfi\n\nunset DRONE_SCRIPT\nunset DRONE_NETRC_MACHINE\nunset DRONE_NETRC_USERNAME\nunset DRONE_NETRC_PASSWORD\nunset DRONE_NETRC_FILE\n\nset -e\n\n\necho + \"go test\"\ngo test\n", + "DRONE_SOURCE_BRANCH": "", + "DRONE_STAGE_ARCH": "", + "DRONE_STAGE_DEPENDS_ON": "", + "DRONE_STAGE_FINISHED": "1571810984", + "DRONE_STAGE_KIND": "", + "DRONE_STAGE_MACHINE": "", + "DRONE_STAGE_NAME": "", + "DRONE_STAGE_NUMBER": "0", + "DRONE_STAGE_OS": "", + "DRONE_STAGE_STARTED": "1571810984", + "DRONE_STAGE_STATUS": "success", + "DRONE_STAGE_TYPE": "", + "DRONE_STAGE_VARIANT": "", + "DRONE_SYSTEM_HOST": "", + "DRONE_SYSTEM_HOSTNAME": "", + "DRONE_SYSTEM_PROTO": "", + "DRONE_SYSTEM_VERSION": "", + "DRONE_TARGET_BRANCH": "master", + "DRONE_WORKSPACE": "/drone/src", + "DRONE_WORKSPACE_BASE": "/drone/src", + "DRONE_WORKSPACE_PATH": "", + "GIT_AUTHOR_EMAIL": "noreply@drone", + "GIT_AUTHOR_NAME": "drone", + "GIT_COMMITTER_EMAIL": "noreply@drone", + "GIT_COMMITTER_NAME": "drone", + "GIT_TERMINAL_PROMPT": "0" + }, + "labels": { + "io.drone": "true", + "io.drone.build.number": "0", + "io.drone.created": "1571810984", + "io.drone.expires": "1571814584", + "io.drone.protected": "false", + "io.drone.repo.name": "", + "io.drone.repo.namespace": "", + "io.drone.repo.slug": "", + "io.drone.stage.name": "", + "io.drone.stage.number": "0", + "io.drone.system.host": "", + "io.drone.system.proto": "", + "io.drone.system.version": "", + "io.drone.ttl": "0s" + }, + "name": "test", + "volumes": [ { - "path": "/tmp/drone-random/opt/test", - "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyB0ZXN0IgpnbyB0ZXN0Cg==" + "name": "_workspace", + "path": "/drone/src" } ], - "secrets": [], - "name": "test", - "working_dir": "/tmp/drone-random/drone/src" + "working_dir": "/drone/src" } - ] + ], + "volumes": [ + { + "temp": { + "id": "random", + "name": "_workspace", + "labels": { + "io.drone": "true", + "io.drone.build.number": "0", + "io.drone.created": "1571810984", + "io.drone.expires": "1571814584", + "io.drone.protected": "false", + "io.drone.repo.name": "", + "io.drone.repo.namespace": "", + "io.drone.repo.slug": "", + "io.drone.stage.name": "", + "io.drone.stage.number": "0", + "io.drone.system.host": "", + "io.drone.system.proto": "", + "io.drone.system.version": "", + "io.drone.ttl": "0s" + } + } + } + ], + "network": { + "id": "random", + "labels": { + "io.drone": "true", + "io.drone.build.number": "0", + "io.drone.created": "1571810984", + "io.drone.expires": "1571814584", + "io.drone.protected": "false", + "io.drone.repo.name": "", + "io.drone.repo.namespace": "", + "io.drone.repo.slug": "", + "io.drone.stage.name": "", + "io.drone.stage.number": "0", + "io.drone.system.host": "", + "io.drone.system.proto": "", + "io.drone.system.version": "", + "io.drone.ttl": "0s" + } + } } \ No newline at end of file diff --git a/engine/compiler/testdata/match.json b/engine/compiler/testdata/match.json index a6e7c24..ba7fa35 100644 --- a/engine/compiler/testdata/match.json +++ b/engine/compiler/testdata/match.json @@ -1,82 +1,264 @@ { "platform": {}, - "token": "3DA541559918A808C2402BBA5012F6C60B27661C", - "server": { - "name": "drone-temp-random", - "image": "docker-18-04", - "region": "nyc1", - "size": "s-1vcpu-1gb", - "user": "root" - }, - "root": "/tmp/drone-random", - "files": [ - { - "path": "/tmp/drone-random/home", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/home/drone", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/drone", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/drone/src", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/opt", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/home/drone/.netrc", - "mode": 384, - "data": "bWFjaGluZSBnaXRodWIuY29tIGxvZ2luIG9jdG9jYXQgcGFzc3dvcmQgY29ycmVjdC1ob3JzZS1iYXR0ZXJ5LXN0YXBsZQ==" - } - ], "steps": [ { + "id": "random", "args": [ - "-e", - "/tmp/drone-random/opt/build" + "echo \"$DRONE_SCRIPT\" | /bin/sh" ], - "command": "/bin/sh", - "files": [ + "entrypoint": [ + "/bin/sh", + "-c" + ], + "environment": { + "CI": "true", + "DRONE": "true", + "DRONE_BRANCH": "master", + "DRONE_BUILD_ACTION": "", + "DRONE_BUILD_CREATED": "0", + "DRONE_BUILD_EVENT": "", + "DRONE_BUILD_FINISHED": "1571811065", + "DRONE_BUILD_LINK": ":////0", + "DRONE_BUILD_NUMBER": "0", + "DRONE_BUILD_PARENT": "0", + "DRONE_BUILD_STARTED": "1571811065", + "DRONE_BUILD_STATUS": "success", + "DRONE_COMMIT": "", + "DRONE_COMMIT_AFTER": "", + "DRONE_COMMIT_AUTHOR": "", + "DRONE_COMMIT_AUTHOR_AVATAR": "", + "DRONE_COMMIT_AUTHOR_EMAIL": "", + "DRONE_COMMIT_AUTHOR_NAME": "", + "DRONE_COMMIT_BEFORE": "", + "DRONE_COMMIT_BRANCH": "master", + "DRONE_COMMIT_LINK": "", + "DRONE_COMMIT_MESSAGE": "", + "DRONE_COMMIT_REF": "", + "DRONE_COMMIT_SHA": "", + "DRONE_DEPLOY_TO": "", + "DRONE_DOCKER_NETWORK_ID": "random", + "DRONE_DOCKER_VOLUME_ID": "random", + "DRONE_GIT_HTTP_URL": "", + "DRONE_GIT_SSH_URL": "", + "DRONE_NETRC_FILE": "machine github.com login octocat password correct-horse-battery-staple", + "DRONE_NETRC_MACHINE": "github.com", + "DRONE_NETRC_PASSWORD": "correct-horse-battery-staple", + "DRONE_NETRC_USERNAME": "octocat", + "DRONE_REMOTE_URL": "", + "DRONE_REPO": "", + "DRONE_REPO_BRANCH": "", + "DRONE_REPO_LINK": "", + "DRONE_REPO_NAME": "", + "DRONE_REPO_NAMESPACE": "", + "DRONE_REPO_OWNER": "", + "DRONE_REPO_PRIVATE": "false", + "DRONE_REPO_SCM": "", + "DRONE_REPO_VISIBILITY": "", + "DRONE_SCRIPT": "\n\nif [ ! -z \"${DRONE_NETRC_FILE}\" ]; then\n\techo $DRONE_NETRC_FILE \u003e $HOME/.netrc\nfi\n\nunset DRONE_SCRIPT\nunset DRONE_NETRC_MACHINE\nunset DRONE_NETRC_USERNAME\nunset DRONE_NETRC_PASSWORD\nunset DRONE_NETRC_FILE\n\nset -e\n\n\necho + \"go build\"\ngo build\n", + "DRONE_SOURCE_BRANCH": "", + "DRONE_STAGE_ARCH": "", + "DRONE_STAGE_DEPENDS_ON": "", + "DRONE_STAGE_FINISHED": "1571811065", + "DRONE_STAGE_KIND": "", + "DRONE_STAGE_MACHINE": "", + "DRONE_STAGE_NAME": "", + "DRONE_STAGE_NUMBER": "0", + "DRONE_STAGE_OS": "", + "DRONE_STAGE_STARTED": "1571811065", + "DRONE_STAGE_STATUS": "success", + "DRONE_STAGE_TYPE": "", + "DRONE_STAGE_VARIANT": "", + "DRONE_SYSTEM_HOST": "", + "DRONE_SYSTEM_HOSTNAME": "", + "DRONE_SYSTEM_PROTO": "", + "DRONE_SYSTEM_VERSION": "", + "DRONE_TARGET_BRANCH": "master", + "DRONE_WORKSPACE": "/drone/src", + "DRONE_WORKSPACE_BASE": "/drone/src", + "DRONE_WORKSPACE_PATH": "", + "GIT_AUTHOR_EMAIL": "noreply@drone", + "GIT_AUTHOR_NAME": "drone", + "GIT_COMMITTER_EMAIL": "noreply@drone", + "GIT_COMMITTER_NAME": "drone", + "GIT_TERMINAL_PROMPT": "0" + }, + "labels": { + "io.drone": "true", + "io.drone.build.number": "0", + "io.drone.created": "1571811065", + "io.drone.expires": "1571814665", + "io.drone.protected": "false", + "io.drone.repo.name": "", + "io.drone.repo.namespace": "", + "io.drone.repo.slug": "", + "io.drone.stage.name": "", + "io.drone.stage.number": "0", + "io.drone.system.host": "", + "io.drone.system.proto": "", + "io.drone.system.version": "", + "io.drone.ttl": "0s" + }, + "name": "build", + "volumes": [ { - "path": "/tmp/drone-random/opt/build", - "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQK" + "name": "_workspace", + "path": "/drone/src" } ], - "name": "build", - "working_dir": "/tmp/drone-random/drone/src" + "working_dir": "/drone/src" }, { + "id": "random", "args": [ - "-e", - "/tmp/drone-random/opt/test" + "echo \"$DRONE_SCRIPT\" | /bin/sh" ], - "command": "/bin/sh", "depends_on": [ "build" ], - "files": [ + "entrypoint": [ + "/bin/sh", + "-c" + ], + "environment": { + "CI": "true", + "DRONE": "true", + "DRONE_BRANCH": "master", + "DRONE_BUILD_ACTION": "", + "DRONE_BUILD_CREATED": "0", + "DRONE_BUILD_EVENT": "", + "DRONE_BUILD_FINISHED": "1571811065", + "DRONE_BUILD_LINK": ":////0", + "DRONE_BUILD_NUMBER": "0", + "DRONE_BUILD_PARENT": "0", + "DRONE_BUILD_STARTED": "1571811065", + "DRONE_BUILD_STATUS": "success", + "DRONE_COMMIT": "", + "DRONE_COMMIT_AFTER": "", + "DRONE_COMMIT_AUTHOR": "", + "DRONE_COMMIT_AUTHOR_AVATAR": "", + "DRONE_COMMIT_AUTHOR_EMAIL": "", + "DRONE_COMMIT_AUTHOR_NAME": "", + "DRONE_COMMIT_BEFORE": "", + "DRONE_COMMIT_BRANCH": "master", + "DRONE_COMMIT_LINK": "", + "DRONE_COMMIT_MESSAGE": "", + "DRONE_COMMIT_REF": "", + "DRONE_COMMIT_SHA": "", + "DRONE_DEPLOY_TO": "", + "DRONE_DOCKER_NETWORK_ID": "random", + "DRONE_DOCKER_VOLUME_ID": "random", + "DRONE_GIT_HTTP_URL": "", + "DRONE_GIT_SSH_URL": "", + "DRONE_NETRC_FILE": "machine github.com login octocat password correct-horse-battery-staple", + "DRONE_NETRC_MACHINE": "github.com", + "DRONE_NETRC_PASSWORD": "correct-horse-battery-staple", + "DRONE_NETRC_USERNAME": "octocat", + "DRONE_REMOTE_URL": "", + "DRONE_REPO": "", + "DRONE_REPO_BRANCH": "", + "DRONE_REPO_LINK": "", + "DRONE_REPO_NAME": "", + "DRONE_REPO_NAMESPACE": "", + "DRONE_REPO_OWNER": "", + "DRONE_REPO_PRIVATE": "false", + "DRONE_REPO_SCM": "", + "DRONE_REPO_VISIBILITY": "", + "DRONE_SCRIPT": "\n\nif [ ! -z \"${DRONE_NETRC_FILE}\" ]; then\n\techo $DRONE_NETRC_FILE \u003e $HOME/.netrc\nfi\n\nunset DRONE_SCRIPT\nunset DRONE_NETRC_MACHINE\nunset DRONE_NETRC_USERNAME\nunset DRONE_NETRC_PASSWORD\nunset DRONE_NETRC_FILE\n\nset -e\n\n\necho + \"go test\"\ngo test\n", + "DRONE_SOURCE_BRANCH": "", + "DRONE_STAGE_ARCH": "", + "DRONE_STAGE_DEPENDS_ON": "", + "DRONE_STAGE_FINISHED": "1571811065", + "DRONE_STAGE_KIND": "", + "DRONE_STAGE_MACHINE": "", + "DRONE_STAGE_NAME": "", + "DRONE_STAGE_NUMBER": "0", + "DRONE_STAGE_OS": "", + "DRONE_STAGE_STARTED": "1571811065", + "DRONE_STAGE_STATUS": "success", + "DRONE_STAGE_TYPE": "", + "DRONE_STAGE_VARIANT": "", + "DRONE_SYSTEM_HOST": "", + "DRONE_SYSTEM_HOSTNAME": "", + "DRONE_SYSTEM_PROTO": "", + "DRONE_SYSTEM_VERSION": "", + "DRONE_TARGET_BRANCH": "master", + "DRONE_WORKSPACE": "/drone/src", + "DRONE_WORKSPACE_BASE": "/drone/src", + "DRONE_WORKSPACE_PATH": "", + "GIT_AUTHOR_EMAIL": "noreply@drone", + "GIT_AUTHOR_NAME": "drone", + "GIT_COMMITTER_EMAIL": "noreply@drone", + "GIT_COMMITTER_NAME": "drone", + "GIT_TERMINAL_PROMPT": "0" + }, + "labels": { + "io.drone": "true", + "io.drone.build.number": "0", + "io.drone.created": "1571811065", + "io.drone.expires": "1571814665", + "io.drone.protected": "false", + "io.drone.repo.name": "", + "io.drone.repo.namespace": "", + "io.drone.repo.slug": "", + "io.drone.stage.name": "", + "io.drone.stage.number": "0", + "io.drone.system.host": "", + "io.drone.system.proto": "", + "io.drone.system.version": "", + "io.drone.ttl": "0s" + }, + "name": "test", + "run_policy": "never", + "volumes": [ { - "path": "/tmp/drone-random/opt/test", - "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyB0ZXN0IgpnbyB0ZXN0Cg==" + "name": "_workspace", + "path": "/drone/src" } ], - "name": "test", - "run_policy": 3, - "working_dir": "/tmp/drone-random/drone/src" + "working_dir": "/drone/src" } - ] + ], + "volumes": [ + { + "temp": { + "id": "random", + "name": "_workspace", + "labels": { + "io.drone": "true", + "io.drone.build.number": "0", + "io.drone.created": "1571811065", + "io.drone.expires": "1571814665", + "io.drone.protected": "false", + "io.drone.repo.name": "", + "io.drone.repo.namespace": "", + "io.drone.repo.slug": "", + "io.drone.stage.name": "", + "io.drone.stage.number": "0", + "io.drone.system.host": "", + "io.drone.system.proto": "", + "io.drone.system.version": "", + "io.drone.ttl": "0s" + } + } + } + ], + "network": { + "id": "random", + "labels": { + "io.drone": "true", + "io.drone.build.number": "0", + "io.drone.created": "1571811065", + "io.drone.expires": "1571814665", + "io.drone.protected": "false", + "io.drone.repo.name": "", + "io.drone.repo.namespace": "", + "io.drone.repo.slug": "", + "io.drone.stage.name": "", + "io.drone.stage.number": "0", + "io.drone.system.host": "", + "io.drone.system.proto": "", + "io.drone.system.version": "", + "io.drone.ttl": "0s" + } + } } \ No newline at end of file diff --git a/engine/compiler/testdata/noclone_graph.json b/engine/compiler/testdata/noclone_graph.json index 6b4019d..1f7df27 100644 --- a/engine/compiler/testdata/noclone_graph.json +++ b/engine/compiler/testdata/noclone_graph.json @@ -1,83 +1,263 @@ { "platform": {}, - "token": "3DA541559918A808C2402BBA5012F6C60B27661C", - "server": { - "name": "drone-temp-random", - "image": "docker-18-04", - "region": "nyc1", - "size": "s-1vcpu-1gb", - "user": "root" - }, - "root": "/tmp/drone-random", - "files": [ - { - "path": "/tmp/drone-random/home", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/home/drone", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/drone", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/drone/src", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/opt", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/home/drone/.netrc", - "mode": 384, - "data": "bWFjaGluZSBnaXRodWIuY29tIGxvZ2luIG9jdG9jYXQgcGFzc3dvcmQgY29ycmVjdC1ob3JzZS1iYXR0ZXJ5LXN0YXBsZQ==" - } - ], "steps": [ { + "id": "random", "args": [ - "-e", - "/tmp/drone-random/opt/build" + "echo \"$DRONE_SCRIPT\" | /bin/sh" ], - "command": "/bin/sh", - "files": [ + "entrypoint": [ + "/bin/sh", + "-c" + ], + "environment": { + "CI": "true", + "DRONE": "true", + "DRONE_BRANCH": "master", + "DRONE_BUILD_ACTION": "", + "DRONE_BUILD_CREATED": "0", + "DRONE_BUILD_EVENT": "", + "DRONE_BUILD_FINISHED": "1571811036", + "DRONE_BUILD_LINK": ":////0", + "DRONE_BUILD_NUMBER": "0", + "DRONE_BUILD_PARENT": "0", + "DRONE_BUILD_STARTED": "1571811036", + "DRONE_BUILD_STATUS": "success", + "DRONE_COMMIT": "", + "DRONE_COMMIT_AFTER": "", + "DRONE_COMMIT_AUTHOR": "", + "DRONE_COMMIT_AUTHOR_AVATAR": "", + "DRONE_COMMIT_AUTHOR_EMAIL": "", + "DRONE_COMMIT_AUTHOR_NAME": "", + "DRONE_COMMIT_BEFORE": "", + "DRONE_COMMIT_BRANCH": "master", + "DRONE_COMMIT_LINK": "", + "DRONE_COMMIT_MESSAGE": "", + "DRONE_COMMIT_REF": "", + "DRONE_COMMIT_SHA": "", + "DRONE_DEPLOY_TO": "", + "DRONE_DOCKER_NETWORK_ID": "random", + "DRONE_DOCKER_VOLUME_ID": "random", + "DRONE_GIT_HTTP_URL": "", + "DRONE_GIT_SSH_URL": "", + "DRONE_NETRC_FILE": "machine github.com login octocat password correct-horse-battery-staple", + "DRONE_NETRC_MACHINE": "github.com", + "DRONE_NETRC_PASSWORD": "correct-horse-battery-staple", + "DRONE_NETRC_USERNAME": "octocat", + "DRONE_REMOTE_URL": "", + "DRONE_REPO": "", + "DRONE_REPO_BRANCH": "", + "DRONE_REPO_LINK": "", + "DRONE_REPO_NAME": "", + "DRONE_REPO_NAMESPACE": "", + "DRONE_REPO_OWNER": "", + "DRONE_REPO_PRIVATE": "false", + "DRONE_REPO_SCM": "", + "DRONE_REPO_VISIBILITY": "", + "DRONE_SCRIPT": "\n\nif [ ! -z \"${DRONE_NETRC_FILE}\" ]; then\n\techo $DRONE_NETRC_FILE \u003e $HOME/.netrc\nfi\n\nunset DRONE_SCRIPT\nunset DRONE_NETRC_MACHINE\nunset DRONE_NETRC_USERNAME\nunset DRONE_NETRC_PASSWORD\nunset DRONE_NETRC_FILE\n\nset -e\n\n\necho + \"go build\"\ngo build\n", + "DRONE_SOURCE_BRANCH": "", + "DRONE_STAGE_ARCH": "", + "DRONE_STAGE_DEPENDS_ON": "", + "DRONE_STAGE_FINISHED": "1571811036", + "DRONE_STAGE_KIND": "", + "DRONE_STAGE_MACHINE": "", + "DRONE_STAGE_NAME": "", + "DRONE_STAGE_NUMBER": "0", + "DRONE_STAGE_OS": "", + "DRONE_STAGE_STARTED": "1571811036", + "DRONE_STAGE_STATUS": "success", + "DRONE_STAGE_TYPE": "", + "DRONE_STAGE_VARIANT": "", + "DRONE_SYSTEM_HOST": "", + "DRONE_SYSTEM_HOSTNAME": "", + "DRONE_SYSTEM_PROTO": "", + "DRONE_SYSTEM_VERSION": "", + "DRONE_TARGET_BRANCH": "master", + "DRONE_WORKSPACE": "/drone/src", + "DRONE_WORKSPACE_BASE": "/drone/src", + "DRONE_WORKSPACE_PATH": "", + "GIT_AUTHOR_EMAIL": "noreply@drone", + "GIT_AUTHOR_NAME": "drone", + "GIT_COMMITTER_EMAIL": "noreply@drone", + "GIT_COMMITTER_NAME": "drone", + "GIT_TERMINAL_PROMPT": "0" + }, + "labels": { + "io.drone": "true", + "io.drone.build.number": "0", + "io.drone.created": "1571811036", + "io.drone.expires": "1571814636", + "io.drone.protected": "false", + "io.drone.repo.name": "", + "io.drone.repo.namespace": "", + "io.drone.repo.slug": "", + "io.drone.stage.name": "", + "io.drone.stage.number": "0", + "io.drone.system.host": "", + "io.drone.system.proto": "", + "io.drone.system.version": "", + "io.drone.ttl": "0s" + }, + "name": "build", + "volumes": [ { - "path": "/tmp/drone-random/opt/build", - "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQK" + "name": "_workspace", + "path": "/drone/src" } ], - "name": "build", - "secrets": [], - "working_dir": "/tmp/drone-random/drone/src" + "working_dir": "/drone/src" }, { + "id": "random", "args": [ - "-e", - "/tmp/drone-random/opt/test" + "echo \"$DRONE_SCRIPT\" | /bin/sh" ], - "command": "/bin/sh", "depends_on": [ "build" ], - "files": [ + "entrypoint": [ + "/bin/sh", + "-c" + ], + "environment": { + "CI": "true", + "DRONE": "true", + "DRONE_BRANCH": "master", + "DRONE_BUILD_ACTION": "", + "DRONE_BUILD_CREATED": "0", + "DRONE_BUILD_EVENT": "", + "DRONE_BUILD_FINISHED": "1571811036", + "DRONE_BUILD_LINK": ":////0", + "DRONE_BUILD_NUMBER": "0", + "DRONE_BUILD_PARENT": "0", + "DRONE_BUILD_STARTED": "1571811036", + "DRONE_BUILD_STATUS": "success", + "DRONE_COMMIT": "", + "DRONE_COMMIT_AFTER": "", + "DRONE_COMMIT_AUTHOR": "", + "DRONE_COMMIT_AUTHOR_AVATAR": "", + "DRONE_COMMIT_AUTHOR_EMAIL": "", + "DRONE_COMMIT_AUTHOR_NAME": "", + "DRONE_COMMIT_BEFORE": "", + "DRONE_COMMIT_BRANCH": "master", + "DRONE_COMMIT_LINK": "", + "DRONE_COMMIT_MESSAGE": "", + "DRONE_COMMIT_REF": "", + "DRONE_COMMIT_SHA": "", + "DRONE_DEPLOY_TO": "", + "DRONE_DOCKER_NETWORK_ID": "random", + "DRONE_DOCKER_VOLUME_ID": "random", + "DRONE_GIT_HTTP_URL": "", + "DRONE_GIT_SSH_URL": "", + "DRONE_NETRC_FILE": "machine github.com login octocat password correct-horse-battery-staple", + "DRONE_NETRC_MACHINE": "github.com", + "DRONE_NETRC_PASSWORD": "correct-horse-battery-staple", + "DRONE_NETRC_USERNAME": "octocat", + "DRONE_REMOTE_URL": "", + "DRONE_REPO": "", + "DRONE_REPO_BRANCH": "", + "DRONE_REPO_LINK": "", + "DRONE_REPO_NAME": "", + "DRONE_REPO_NAMESPACE": "", + "DRONE_REPO_OWNER": "", + "DRONE_REPO_PRIVATE": "false", + "DRONE_REPO_SCM": "", + "DRONE_REPO_VISIBILITY": "", + "DRONE_SCRIPT": "\n\nif [ ! -z \"${DRONE_NETRC_FILE}\" ]; then\n\techo $DRONE_NETRC_FILE \u003e $HOME/.netrc\nfi\n\nunset DRONE_SCRIPT\nunset DRONE_NETRC_MACHINE\nunset DRONE_NETRC_USERNAME\nunset DRONE_NETRC_PASSWORD\nunset DRONE_NETRC_FILE\n\nset -e\n\n\necho + \"go test\"\ngo test\n", + "DRONE_SOURCE_BRANCH": "", + "DRONE_STAGE_ARCH": "", + "DRONE_STAGE_DEPENDS_ON": "", + "DRONE_STAGE_FINISHED": "1571811036", + "DRONE_STAGE_KIND": "", + "DRONE_STAGE_MACHINE": "", + "DRONE_STAGE_NAME": "", + "DRONE_STAGE_NUMBER": "0", + "DRONE_STAGE_OS": "", + "DRONE_STAGE_STARTED": "1571811036", + "DRONE_STAGE_STATUS": "success", + "DRONE_STAGE_TYPE": "", + "DRONE_STAGE_VARIANT": "", + "DRONE_SYSTEM_HOST": "", + "DRONE_SYSTEM_HOSTNAME": "", + "DRONE_SYSTEM_PROTO": "", + "DRONE_SYSTEM_VERSION": "", + "DRONE_TARGET_BRANCH": "master", + "DRONE_WORKSPACE": "/drone/src", + "DRONE_WORKSPACE_BASE": "/drone/src", + "DRONE_WORKSPACE_PATH": "", + "GIT_AUTHOR_EMAIL": "noreply@drone", + "GIT_AUTHOR_NAME": "drone", + "GIT_COMMITTER_EMAIL": "noreply@drone", + "GIT_COMMITTER_NAME": "drone", + "GIT_TERMINAL_PROMPT": "0" + }, + "labels": { + "io.drone": "true", + "io.drone.build.number": "0", + "io.drone.created": "1571811036", + "io.drone.expires": "1571814636", + "io.drone.protected": "false", + "io.drone.repo.name": "", + "io.drone.repo.namespace": "", + "io.drone.repo.slug": "", + "io.drone.stage.name": "", + "io.drone.stage.number": "0", + "io.drone.system.host": "", + "io.drone.system.proto": "", + "io.drone.system.version": "", + "io.drone.ttl": "0s" + }, + "name": "test", + "volumes": [ { - "path": "/tmp/drone-random/opt/test", - "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyB0ZXN0IgpnbyB0ZXN0Cg==" + "name": "_workspace", + "path": "/drone/src" } ], - "name": "test", - "secrets": [], - "working_dir": "/tmp/drone-random/drone/src" + "working_dir": "/drone/src" } - ] + ], + "volumes": [ + { + "temp": { + "id": "random", + "name": "_workspace", + "labels": { + "io.drone": "true", + "io.drone.build.number": "0", + "io.drone.created": "1571811036", + "io.drone.expires": "1571814636", + "io.drone.protected": "false", + "io.drone.repo.name": "", + "io.drone.repo.namespace": "", + "io.drone.repo.slug": "", + "io.drone.stage.name": "", + "io.drone.stage.number": "0", + "io.drone.system.host": "", + "io.drone.system.proto": "", + "io.drone.system.version": "", + "io.drone.ttl": "0s" + } + } + } + ], + "network": { + "id": "random", + "labels": { + "io.drone": "true", + "io.drone.build.number": "0", + "io.drone.created": "1571811036", + "io.drone.expires": "1571814636", + "io.drone.protected": "false", + "io.drone.repo.name": "", + "io.drone.repo.namespace": "", + "io.drone.repo.slug": "", + "io.drone.stage.name": "", + "io.drone.stage.number": "0", + "io.drone.system.host": "", + "io.drone.system.proto": "", + "io.drone.system.version": "", + "io.drone.ttl": "0s" + } + } } \ No newline at end of file diff --git a/engine/compiler/testdata/noclone_serial.json b/engine/compiler/testdata/noclone_serial.json index 999cf11..fc3ab49 100644 --- a/engine/compiler/testdata/noclone_serial.json +++ b/engine/compiler/testdata/noclone_serial.json @@ -1,62 +1,154 @@ { "platform": {}, - "token": "3DA541559918A808C2402BBA5012F6C60B27661C", - "server": { - "name": "drone-temp-random", - "image": "docker-18-04", - "region": "nyc1", - "size": "s-1vcpu-1gb", - "user": "root" - }, - "root": "/tmp/drone-random", - "files": [ - { - "path": "/tmp/drone-random/home", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/home/drone", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/drone", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/drone/src", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/opt", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/home/drone/.netrc", - "mode": 384, - "data": "bWFjaGluZSBnaXRodWIuY29tIGxvZ2luIG9jdG9jYXQgcGFzc3dvcmQgY29ycmVjdC1ob3JzZS1iYXR0ZXJ5LXN0YXBsZQ==" - } - ], "steps": [ { + "id": "random", "args": [ - "-e", - "/tmp/drone-random/opt/build" + "echo \"$DRONE_SCRIPT\" | /bin/sh" ], - "command": "/bin/sh", - "files": [ + "entrypoint": [ + "/bin/sh", + "-c" + ], + "environment": { + "CI": "true", + "DRONE": "true", + "DRONE_BRANCH": "master", + "DRONE_BUILD_ACTION": "", + "DRONE_BUILD_CREATED": "0", + "DRONE_BUILD_EVENT": "", + "DRONE_BUILD_FINISHED": "1571811007", + "DRONE_BUILD_LINK": ":////0", + "DRONE_BUILD_NUMBER": "0", + "DRONE_BUILD_PARENT": "0", + "DRONE_BUILD_STARTED": "1571811007", + "DRONE_BUILD_STATUS": "success", + "DRONE_COMMIT": "", + "DRONE_COMMIT_AFTER": "", + "DRONE_COMMIT_AUTHOR": "", + "DRONE_COMMIT_AUTHOR_AVATAR": "", + "DRONE_COMMIT_AUTHOR_EMAIL": "", + "DRONE_COMMIT_AUTHOR_NAME": "", + "DRONE_COMMIT_BEFORE": "", + "DRONE_COMMIT_BRANCH": "master", + "DRONE_COMMIT_LINK": "", + "DRONE_COMMIT_MESSAGE": "", + "DRONE_COMMIT_REF": "", + "DRONE_COMMIT_SHA": "", + "DRONE_DEPLOY_TO": "", + "DRONE_DOCKER_NETWORK_ID": "random", + "DRONE_DOCKER_VOLUME_ID": "random", + "DRONE_GIT_HTTP_URL": "", + "DRONE_GIT_SSH_URL": "", + "DRONE_NETRC_FILE": "machine github.com login octocat password correct-horse-battery-staple", + "DRONE_NETRC_MACHINE": "github.com", + "DRONE_NETRC_PASSWORD": "correct-horse-battery-staple", + "DRONE_NETRC_USERNAME": "octocat", + "DRONE_REMOTE_URL": "", + "DRONE_REPO": "", + "DRONE_REPO_BRANCH": "", + "DRONE_REPO_LINK": "", + "DRONE_REPO_NAME": "", + "DRONE_REPO_NAMESPACE": "", + "DRONE_REPO_OWNER": "", + "DRONE_REPO_PRIVATE": "false", + "DRONE_REPO_SCM": "", + "DRONE_REPO_VISIBILITY": "", + "DRONE_SCRIPT": "\n\nif [ ! -z \"${DRONE_NETRC_FILE}\" ]; then\n\techo $DRONE_NETRC_FILE \u003e $HOME/.netrc\nfi\n\nunset DRONE_SCRIPT\nunset DRONE_NETRC_MACHINE\nunset DRONE_NETRC_USERNAME\nunset DRONE_NETRC_PASSWORD\nunset DRONE_NETRC_FILE\n\nset -e\n\n\necho + \"go build\"\ngo build\n\necho + \"go test\"\ngo test\n", + "DRONE_SOURCE_BRANCH": "", + "DRONE_STAGE_ARCH": "", + "DRONE_STAGE_DEPENDS_ON": "", + "DRONE_STAGE_FINISHED": "1571811007", + "DRONE_STAGE_KIND": "", + "DRONE_STAGE_MACHINE": "", + "DRONE_STAGE_NAME": "", + "DRONE_STAGE_NUMBER": "0", + "DRONE_STAGE_OS": "", + "DRONE_STAGE_STARTED": "1571811007", + "DRONE_STAGE_STATUS": "success", + "DRONE_STAGE_TYPE": "", + "DRONE_STAGE_VARIANT": "", + "DRONE_SYSTEM_HOST": "", + "DRONE_SYSTEM_HOSTNAME": "", + "DRONE_SYSTEM_PROTO": "", + "DRONE_SYSTEM_VERSION": "", + "DRONE_TARGET_BRANCH": "master", + "DRONE_WORKSPACE": "/drone/src", + "DRONE_WORKSPACE_BASE": "/drone/src", + "DRONE_WORKSPACE_PATH": "", + "GIT_AUTHOR_EMAIL": "noreply@drone", + "GIT_AUTHOR_NAME": "drone", + "GIT_COMMITTER_EMAIL": "noreply@drone", + "GIT_COMMITTER_NAME": "drone", + "GIT_TERMINAL_PROMPT": "0" + }, + "labels": { + "io.drone": "true", + "io.drone.build.number": "0", + "io.drone.created": "1571811007", + "io.drone.expires": "1571814607", + "io.drone.protected": "false", + "io.drone.repo.name": "", + "io.drone.repo.namespace": "", + "io.drone.repo.slug": "", + "io.drone.stage.name": "", + "io.drone.stage.number": "0", + "io.drone.system.host": "", + "io.drone.system.proto": "", + "io.drone.system.version": "", + "io.drone.ttl": "0s" + }, + "name": "build", + "volumes": [ { - "path": "/tmp/drone-random/opt/build", - "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQKCmVjaG8gKyAiZ28gdGVzdCIKZ28gdGVzdAo=" + "name": "_workspace", + "path": "/drone/src" } ], - "name": "build", - "working_dir": "/tmp/drone-random/drone/src" + "working_dir": "/drone/src" } - ] + ], + "volumes": [ + { + "temp": { + "id": "random", + "name": "_workspace", + "labels": { + "io.drone": "true", + "io.drone.build.number": "0", + "io.drone.created": "1571811007", + "io.drone.expires": "1571814607", + "io.drone.protected": "false", + "io.drone.repo.name": "", + "io.drone.repo.namespace": "", + "io.drone.repo.slug": "", + "io.drone.stage.name": "", + "io.drone.stage.number": "0", + "io.drone.system.host": "", + "io.drone.system.proto": "", + "io.drone.system.version": "", + "io.drone.ttl": "0s" + } + } + } + ], + "network": { + "id": "random", + "labels": { + "io.drone": "true", + "io.drone.build.number": "0", + "io.drone.created": "1571811007", + "io.drone.expires": "1571814607", + "io.drone.protected": "false", + "io.drone.repo.name": "", + "io.drone.repo.namespace": "", + "io.drone.repo.slug": "", + "io.drone.stage.name": "", + "io.drone.stage.number": "0", + "io.drone.system.host": "", + "io.drone.system.proto": "", + "io.drone.system.version": "", + "io.drone.ttl": "0s" + } + } } \ No newline at end of file diff --git a/engine/compiler/testdata/run_always.json b/engine/compiler/testdata/run_always.json index 94cebc4..cb45bf7 100644 --- a/engine/compiler/testdata/run_always.json +++ b/engine/compiler/testdata/run_always.json @@ -1,63 +1,39 @@ { "platform": {}, - "token": "3DA541559918A808C2402BBA5012F6C60B27661C", - "server": { - "name": "drone-temp-random", - "image": "docker-18-04", - "region": "nyc1", - "size": "s-1vcpu-1gb", - "user": "root" - }, - "root": "/tmp/drone-random", - "files": [ - { - "path": "/tmp/drone-random/home", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/home/drone", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/drone", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/drone/src", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/opt", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/home/drone/.netrc", - "mode": 384, - "data": "bWFjaGluZSBnaXRodWIuY29tIGxvZ2luIG9jdG9jYXQgcGFzc3dvcmQgY29ycmVjdC1ob3JzZS1iYXR0ZXJ5LXN0YXBsZQ==" - } - ], "steps": [ { + "id": "random", "args": [ - "-e", - "/tmp/drone-random/opt/build" + "echo \"$DRONE_SCRIPT\" | /bin/sh" ], - "command": "/bin/sh", - "files": [ + "entrypoint": [ + "/bin/sh", + "-c" + ], + "environment": {}, + "labels": {}, + "name": "build", + "run_policy": "always", + "volumes": [ { - "path": "/tmp/drone-random/opt/build", - "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQK" + "name": "_workspace", + "path": "/drone/src" } ], - "name": "build", - "run_policy": 2, - "working_dir": "/tmp/drone-random/drone/src" + "working_dir": "/drone/src" } - ] -} + ], + "volumes": [ + { + "temp": { + "id": "random", + "name": "_workspace", + "labels": {} + } + } + ], + "network": { + "id": "random", + "labels": {} + } +} \ No newline at end of file diff --git a/engine/compiler/testdata/run_failure.json b/engine/compiler/testdata/run_failure.json index 4422680..24d8fc3 100644 --- a/engine/compiler/testdata/run_failure.json +++ b/engine/compiler/testdata/run_failure.json @@ -1,63 +1,39 @@ { "platform": {}, - "token": "3DA541559918A808C2402BBA5012F6C60B27661C", - "server": { - "name": "drone-temp-random", - "image": "docker-18-04", - "region": "nyc1", - "size": "s-1vcpu-1gb", - "user": "root" - }, - "root": "/tmp/drone-random", - "files": [ - { - "path": "/tmp/drone-random/home", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/home/drone", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/drone", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/drone/src", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/opt", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/home/drone/.netrc", - "mode": 384, - "data": "bWFjaGluZSBnaXRodWIuY29tIGxvZ2luIG9jdG9jYXQgcGFzc3dvcmQgY29ycmVjdC1ob3JzZS1iYXR0ZXJ5LXN0YXBsZQ==" - } - ], "steps": [ { + "id": "random", "args": [ - "-e", - "/tmp/drone-random/opt/build" + "echo \"$DRONE_SCRIPT\" | /bin/sh" ], - "command": "/bin/sh", - "files": [ + "entrypoint": [ + "/bin/sh", + "-c" + ], + "environment": {}, + "labels": {}, + "name": "build", + "run_policy": "on-failure", + "volumes": [ { - "path": "/tmp/drone-random/opt/build", - "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQK" + "name": "_workspace", + "path": "/drone/src" } ], - "name": "build", - "run_policy": 1, - "working_dir": "/tmp/drone-random/drone/src" + "working_dir": "/drone/src" } - ] -} + ], + "volumes": [ + { + "temp": { + "id": "random", + "name": "_workspace", + "labels": { } + } + } + ], + "network": { + "id": "random", + "labels": {} + } +} \ No newline at end of file diff --git a/engine/compiler/testdata/serial.json b/engine/compiler/testdata/serial.json index 33e15cd..d422789 100644 --- a/engine/compiler/testdata/serial.json +++ b/engine/compiler/testdata/serial.json @@ -1,104 +1,366 @@ { "platform": {}, - "token": "3DA541559918A808C2402BBA5012F6C60B27661C", - "server": { - "name": "drone-temp-random", - "image": "docker-18-04", - "region": "nyc1", - "size": "s-1vcpu-1gb", - "user": "root" - }, - "root": "/tmp/drone-random", - "files": [ - { - "path": "/tmp/drone-random/home", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/home/drone", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/drone", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/drone/src", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/opt", - "mode": 448, - "is_dir": true - }, - { - "path": "/tmp/drone-random/home/drone/.netrc", - "mode": 384, - "data": "bWFjaGluZSBnaXRodWIuY29tIGxvZ2luIG9jdG9jYXQgcGFzc3dvcmQgY29ycmVjdC1ob3JzZS1iYXR0ZXJ5LXN0YXBsZQ==" - } - ], "steps": [ { - "args": [ - "-e", - "/tmp/drone-random/opt/clone" - ], - "command": "/bin/sh", - "files": [ + "id": "random", + "environment": { + "CI": "true", + "DRONE": "true", + "DRONE_BRANCH": "master", + "DRONE_BUILD_ACTION": "", + "DRONE_BUILD_CREATED": "0", + "DRONE_BUILD_EVENT": "", + "DRONE_BUILD_FINISHED": "1571810939", + "DRONE_BUILD_LINK": ":////0", + "DRONE_BUILD_NUMBER": "0", + "DRONE_BUILD_PARENT": "0", + "DRONE_BUILD_STARTED": "1571810939", + "DRONE_BUILD_STATUS": "success", + "DRONE_COMMIT": "", + "DRONE_COMMIT_AFTER": "", + "DRONE_COMMIT_AUTHOR": "", + "DRONE_COMMIT_AUTHOR_AVATAR": "", + "DRONE_COMMIT_AUTHOR_EMAIL": "", + "DRONE_COMMIT_AUTHOR_NAME": "", + "DRONE_COMMIT_BEFORE": "", + "DRONE_COMMIT_BRANCH": "master", + "DRONE_COMMIT_LINK": "", + "DRONE_COMMIT_MESSAGE": "", + "DRONE_COMMIT_REF": "", + "DRONE_COMMIT_SHA": "", + "DRONE_DEPLOY_TO": "", + "DRONE_DOCKER_NETWORK_ID": "random", + "DRONE_DOCKER_VOLUME_ID": "random", + "DRONE_GIT_HTTP_URL": "", + "DRONE_GIT_SSH_URL": "", + "DRONE_NETRC_FILE": "machine github.com login octocat password correct-horse-battery-staple", + "DRONE_NETRC_MACHINE": "github.com", + "DRONE_NETRC_PASSWORD": "correct-horse-battery-staple", + "DRONE_NETRC_USERNAME": "octocat", + "DRONE_REMOTE_URL": "", + "DRONE_REPO": "", + "DRONE_REPO_BRANCH": "", + "DRONE_REPO_LINK": "", + "DRONE_REPO_NAME": "", + "DRONE_REPO_NAMESPACE": "", + "DRONE_REPO_OWNER": "", + "DRONE_REPO_PRIVATE": "false", + "DRONE_REPO_SCM": "", + "DRONE_REPO_VISIBILITY": "", + "DRONE_SOURCE_BRANCH": "", + "DRONE_STAGE_ARCH": "", + "DRONE_STAGE_DEPENDS_ON": "", + "DRONE_STAGE_FINISHED": "1571810939", + "DRONE_STAGE_KIND": "", + "DRONE_STAGE_MACHINE": "", + "DRONE_STAGE_NAME": "", + "DRONE_STAGE_NUMBER": "0", + "DRONE_STAGE_OS": "", + "DRONE_STAGE_STARTED": "1571810939", + "DRONE_STAGE_STATUS": "success", + "DRONE_STAGE_TYPE": "", + "DRONE_STAGE_VARIANT": "", + "DRONE_SYSTEM_HOST": "", + "DRONE_SYSTEM_HOSTNAME": "", + "DRONE_SYSTEM_PROTO": "", + "DRONE_SYSTEM_VERSION": "", + "DRONE_TARGET_BRANCH": "master", + "DRONE_WORKSPACE": "/drone/src", + "DRONE_WORKSPACE_BASE": "/drone/src", + "DRONE_WORKSPACE_PATH": "", + "GIT_AUTHOR_EMAIL": "noreply@drone", + "GIT_AUTHOR_NAME": "drone", + "GIT_COMMITTER_EMAIL": "noreply@drone", + "GIT_COMMITTER_NAME": "drone", + "GIT_TERMINAL_PROMPT": "0" + }, + "image": "drone/git:1", + "labels": { + "io.drone": "true", + "io.drone.build.number": "0", + "io.drone.created": "1571810939", + "io.drone.expires": "1571814539", + "io.drone.protected": "false", + "io.drone.repo.name": "", + "io.drone.repo.namespace": "", + "io.drone.repo.slug": "", + "io.drone.stage.name": "", + "io.drone.stage.number": "0", + "io.drone.system.host": "", + "io.drone.system.proto": "", + "io.drone.system.version": "", + "io.drone.ttl": "0s" + }, + "name": "clone", + "run_policy": "always", + "volumes": [ { - "path": "/tmp/drone-random/opt/clone", - "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnaXQgaW5pdCIKZ2l0IGluaXQKCmVjaG8gKyAiZ2l0IHJlbW90ZSBhZGQgb3JpZ2luICIKZ2l0IHJlbW90ZSBhZGQgb3JpZ2luIAoKZWNobyArICJnaXQgZmV0Y2ggIG9yaWdpbiArcmVmcy9oZWFkcy9tYXN0ZXI6IgpnaXQgZmV0Y2ggIG9yaWdpbiArcmVmcy9oZWFkcy9tYXN0ZXI6CgplY2hvICsgImdpdCBjaGVja291dCAgLWIgbWFzdGVyIgpnaXQgY2hlY2tvdXQgIC1iIG1hc3Rlcgo=" + "name": "_workspace", + "path": "/drone/src" } ], - "secrets": [], - "name": "clone", - "run_policy": 2, - "working_dir": "/tmp/drone-random/drone/src" + "working_dir": "/drone/src" }, { + "id": "random", "args": [ - "-e", - "/tmp/drone-random/opt/build" + "echo \"$DRONE_SCRIPT\" | /bin/sh" ], - "command": "/bin/sh", "depends_on": [ "clone" ], - "files": [ + "entrypoint": [ + "/bin/sh", + "-c" + ], + "environment": { + "CI": "true", + "DRONE": "true", + "DRONE_BRANCH": "master", + "DRONE_BUILD_ACTION": "", + "DRONE_BUILD_CREATED": "0", + "DRONE_BUILD_EVENT": "", + "DRONE_BUILD_FINISHED": "1571810939", + "DRONE_BUILD_LINK": ":////0", + "DRONE_BUILD_NUMBER": "0", + "DRONE_BUILD_PARENT": "0", + "DRONE_BUILD_STARTED": "1571810939", + "DRONE_BUILD_STATUS": "success", + "DRONE_COMMIT": "", + "DRONE_COMMIT_AFTER": "", + "DRONE_COMMIT_AUTHOR": "", + "DRONE_COMMIT_AUTHOR_AVATAR": "", + "DRONE_COMMIT_AUTHOR_EMAIL": "", + "DRONE_COMMIT_AUTHOR_NAME": "", + "DRONE_COMMIT_BEFORE": "", + "DRONE_COMMIT_BRANCH": "master", + "DRONE_COMMIT_LINK": "", + "DRONE_COMMIT_MESSAGE": "", + "DRONE_COMMIT_REF": "", + "DRONE_COMMIT_SHA": "", + "DRONE_DEPLOY_TO": "", + "DRONE_DOCKER_NETWORK_ID": "random", + "DRONE_DOCKER_VOLUME_ID": "random", + "DRONE_GIT_HTTP_URL": "", + "DRONE_GIT_SSH_URL": "", + "DRONE_NETRC_FILE": "machine github.com login octocat password correct-horse-battery-staple", + "DRONE_NETRC_MACHINE": "github.com", + "DRONE_NETRC_PASSWORD": "correct-horse-battery-staple", + "DRONE_NETRC_USERNAME": "octocat", + "DRONE_REMOTE_URL": "", + "DRONE_REPO": "", + "DRONE_REPO_BRANCH": "", + "DRONE_REPO_LINK": "", + "DRONE_REPO_NAME": "", + "DRONE_REPO_NAMESPACE": "", + "DRONE_REPO_OWNER": "", + "DRONE_REPO_PRIVATE": "false", + "DRONE_REPO_SCM": "", + "DRONE_REPO_VISIBILITY": "", + "DRONE_SCRIPT": "\n\nif [ ! -z \"${DRONE_NETRC_FILE}\" ]; then\n\techo $DRONE_NETRC_FILE \u003e $HOME/.netrc\nfi\n\nunset DRONE_SCRIPT\nunset DRONE_NETRC_MACHINE\nunset DRONE_NETRC_USERNAME\nunset DRONE_NETRC_PASSWORD\nunset DRONE_NETRC_FILE\n\nset -e\n\n\necho + \"go build\"\ngo build\n", + "DRONE_SOURCE_BRANCH": "", + "DRONE_STAGE_ARCH": "", + "DRONE_STAGE_DEPENDS_ON": "", + "DRONE_STAGE_FINISHED": "1571810939", + "DRONE_STAGE_KIND": "", + "DRONE_STAGE_MACHINE": "", + "DRONE_STAGE_NAME": "", + "DRONE_STAGE_NUMBER": "0", + "DRONE_STAGE_OS": "", + "DRONE_STAGE_STARTED": "1571810939", + "DRONE_STAGE_STATUS": "success", + "DRONE_STAGE_TYPE": "", + "DRONE_STAGE_VARIANT": "", + "DRONE_SYSTEM_HOST": "", + "DRONE_SYSTEM_HOSTNAME": "", + "DRONE_SYSTEM_PROTO": "", + "DRONE_SYSTEM_VERSION": "", + "DRONE_TARGET_BRANCH": "master", + "DRONE_WORKSPACE": "/drone/src", + "DRONE_WORKSPACE_BASE": "/drone/src", + "DRONE_WORKSPACE_PATH": "", + "GIT_AUTHOR_EMAIL": "noreply@drone", + "GIT_AUTHOR_NAME": "drone", + "GIT_COMMITTER_EMAIL": "noreply@drone", + "GIT_COMMITTER_NAME": "drone", + "GIT_TERMINAL_PROMPT": "0" + }, + "labels": { + "io.drone": "true", + "io.drone.build.number": "0", + "io.drone.created": "1571810939", + "io.drone.expires": "1571814539", + "io.drone.protected": "false", + "io.drone.repo.name": "", + "io.drone.repo.namespace": "", + "io.drone.repo.slug": "", + "io.drone.stage.name": "", + "io.drone.stage.number": "0", + "io.drone.system.host": "", + "io.drone.system.proto": "", + "io.drone.system.version": "", + "io.drone.ttl": "0s" + }, + "name": "build", + "volumes": [ { - "path": "/tmp/drone-random/opt/build", - "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQK" + "name": "_workspace", + "path": "/drone/src" } ], - "secrets": [], - "name": "build", - "working_dir": "/tmp/drone-random/drone/src" + "working_dir": "/drone/src" }, { + "id": "random", "args": [ - "-e", - "/tmp/drone-random/opt/test" + "echo \"$DRONE_SCRIPT\" | /bin/sh" ], - "command": "/bin/sh", "depends_on": [ "build" ], - "files": [ + "entrypoint": [ + "/bin/sh", + "-c" + ], + "environment": { + "CI": "true", + "DRONE": "true", + "DRONE_BRANCH": "master", + "DRONE_BUILD_ACTION": "", + "DRONE_BUILD_CREATED": "0", + "DRONE_BUILD_EVENT": "", + "DRONE_BUILD_FINISHED": "1571810939", + "DRONE_BUILD_LINK": ":////0", + "DRONE_BUILD_NUMBER": "0", + "DRONE_BUILD_PARENT": "0", + "DRONE_BUILD_STARTED": "1571810939", + "DRONE_BUILD_STATUS": "success", + "DRONE_COMMIT": "", + "DRONE_COMMIT_AFTER": "", + "DRONE_COMMIT_AUTHOR": "", + "DRONE_COMMIT_AUTHOR_AVATAR": "", + "DRONE_COMMIT_AUTHOR_EMAIL": "", + "DRONE_COMMIT_AUTHOR_NAME": "", + "DRONE_COMMIT_BEFORE": "", + "DRONE_COMMIT_BRANCH": "master", + "DRONE_COMMIT_LINK": "", + "DRONE_COMMIT_MESSAGE": "", + "DRONE_COMMIT_REF": "", + "DRONE_COMMIT_SHA": "", + "DRONE_DEPLOY_TO": "", + "DRONE_DOCKER_NETWORK_ID": "random", + "DRONE_DOCKER_VOLUME_ID": "random", + "DRONE_GIT_HTTP_URL": "", + "DRONE_GIT_SSH_URL": "", + "DRONE_NETRC_FILE": "machine github.com login octocat password correct-horse-battery-staple", + "DRONE_NETRC_MACHINE": "github.com", + "DRONE_NETRC_PASSWORD": "correct-horse-battery-staple", + "DRONE_NETRC_USERNAME": "octocat", + "DRONE_REMOTE_URL": "", + "DRONE_REPO": "", + "DRONE_REPO_BRANCH": "", + "DRONE_REPO_LINK": "", + "DRONE_REPO_NAME": "", + "DRONE_REPO_NAMESPACE": "", + "DRONE_REPO_OWNER": "", + "DRONE_REPO_PRIVATE": "false", + "DRONE_REPO_SCM": "", + "DRONE_REPO_VISIBILITY": "", + "DRONE_SCRIPT": "\n\nif [ ! -z \"${DRONE_NETRC_FILE}\" ]; then\n\techo $DRONE_NETRC_FILE \u003e $HOME/.netrc\nfi\n\nunset DRONE_SCRIPT\nunset DRONE_NETRC_MACHINE\nunset DRONE_NETRC_USERNAME\nunset DRONE_NETRC_PASSWORD\nunset DRONE_NETRC_FILE\n\nset -e\n\n\necho + \"go test\"\ngo test\n", + "DRONE_SOURCE_BRANCH": "", + "DRONE_STAGE_ARCH": "", + "DRONE_STAGE_DEPENDS_ON": "", + "DRONE_STAGE_FINISHED": "1571810939", + "DRONE_STAGE_KIND": "", + "DRONE_STAGE_MACHINE": "", + "DRONE_STAGE_NAME": "", + "DRONE_STAGE_NUMBER": "0", + "DRONE_STAGE_OS": "", + "DRONE_STAGE_STARTED": "1571810939", + "DRONE_STAGE_STATUS": "success", + "DRONE_STAGE_TYPE": "", + "DRONE_STAGE_VARIANT": "", + "DRONE_SYSTEM_HOST": "", + "DRONE_SYSTEM_HOSTNAME": "", + "DRONE_SYSTEM_PROTO": "", + "DRONE_SYSTEM_VERSION": "", + "DRONE_TARGET_BRANCH": "master", + "DRONE_WORKSPACE": "/drone/src", + "DRONE_WORKSPACE_BASE": "/drone/src", + "DRONE_WORKSPACE_PATH": "", + "GIT_AUTHOR_EMAIL": "noreply@drone", + "GIT_AUTHOR_NAME": "drone", + "GIT_COMMITTER_EMAIL": "noreply@drone", + "GIT_COMMITTER_NAME": "drone", + "GIT_TERMINAL_PROMPT": "0" + }, + "labels": { + "io.drone": "true", + "io.drone.build.number": "0", + "io.drone.created": "1571810939", + "io.drone.expires": "1571814539", + "io.drone.protected": "false", + "io.drone.repo.name": "", + "io.drone.repo.namespace": "", + "io.drone.repo.slug": "", + "io.drone.stage.name": "", + "io.drone.stage.number": "0", + "io.drone.system.host": "", + "io.drone.system.proto": "", + "io.drone.system.version": "", + "io.drone.ttl": "0s" + }, + "name": "test", + "volumes": [ { - "path": "/tmp/drone-random/opt/test", - "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyB0ZXN0IgpnbyB0ZXN0Cg==" + "name": "_workspace", + "path": "/drone/src" } ], - "secrets": [], - "name": "test", - "working_dir": "/tmp/drone-random/drone/src" + "working_dir": "/drone/src" } - ] + ], + "volumes": [ + { + "temp": { + "id": "random", + "name": "_workspace", + "labels": { + "io.drone": "true", + "io.drone.build.number": "0", + "io.drone.created": "1571810939", + "io.drone.expires": "1571814539", + "io.drone.protected": "false", + "io.drone.repo.name": "", + "io.drone.repo.namespace": "", + "io.drone.repo.slug": "", + "io.drone.stage.name": "", + "io.drone.stage.number": "0", + "io.drone.system.host": "", + "io.drone.system.proto": "", + "io.drone.system.version": "", + "io.drone.ttl": "0s" + } + } + } + ], + "network": { + "id": "random", + "labels": { + "io.drone": "true", + "io.drone.build.number": "0", + "io.drone.created": "1571810939", + "io.drone.expires": "1571814539", + "io.drone.protected": "false", + "io.drone.repo.name": "", + "io.drone.repo.namespace": "", + "io.drone.repo.slug": "", + "io.drone.stage.name": "", + "io.drone.stage.number": "0", + "io.drone.system.host": "", + "io.drone.system.proto": "", + "io.drone.system.version": "", + "io.drone.ttl": "0s" + } + } } \ No newline at end of file diff --git a/engine/engine_impl.go b/engine/engine_impl.go index e8e8628..a3643cd 100644 --- a/engine/engine_impl.go +++ b/engine/engine_impl.go @@ -9,6 +9,7 @@ import ( "io" "io/ioutil" + "github.com/drone-runners/drone-runner-docker/internal/docker/image" "github.com/drone-runners/drone-runner-docker/internal/docker/stdcopy" "github.com/drone/runner-go/registry/auths" @@ -141,14 +142,6 @@ func (e *Docker) Run(ctx context.Context, spec *Spec, step *Step, output io.Writ // func (e *Docker) create(ctx context.Context, spec *Spec, step *Step, output io.Writer) error { - // parse the docker image name. We need to extract the - // image domain name and match to registry credentials - // stored in the .docker/config.json object. - _, _, latest, err := parseImage(step.Image) - if err != nil { - return err - } - // create pull options with encoded authorization credentials. pullopts := types.ImagePullOptions{} if step.Auth != nil { @@ -161,7 +154,7 @@ func (e *Docker) create(ctx context.Context, spec *Spec, step *Step, output io.W // automatically pull the latest version of the image if requested // by the process configuration, or if the image is :latest if step.Pull == PullAlways || - (step.Pull == PullDefault && latest) { + (step.Pull == PullDefault && image.IsLatest(step.Image)) { rc, pullerr := e.client.ImagePull(ctx, step.Image, pullopts) if pullerr == nil { io.Copy(ioutil.Discard, rc) @@ -172,7 +165,7 @@ func (e *Docker) create(ctx context.Context, spec *Spec, step *Step, output io.W } } - _, err = e.client.ContainerCreate(ctx, + _, err := e.client.ContainerCreate(ctx, toConfig(spec, step), toHostConfig(spec, step), toNetConfig(spec, step), diff --git a/engine/image.go b/engine/image.go deleted file mode 100644 index 3c21701..0000000 --- a/engine/image.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Polyform License -// that can be found in the LICENSE file. - -package engine - -import ( - "strings" - - "github.com/docker/distribution/reference" -) - -// helper function parses the image and returns the -// canonical image name, domain name, and whether or not -// the image tag is :latest. -func parseImage(s string) (canonical, domain string, latest bool, err error) { - // parse the docker image name. We need to extract the - // image domain name and match to registry credentials - // stored in the .docker/config.json object. - named, err := reference.ParseNormalizedNamed(s) - if err != nil { - return - } - // the canonical image name, for some reason, excludes - // the tag name. So we need to make sure it is included - // in the image name so we can determine if the :latest - // tag is specified - named = reference.TagNameOnly(named) - - return named.String(), - reference.Domain(named), - strings.HasSuffix(named.String(), ":latest"), - nil -} diff --git a/engine/image_test.go b/engine/image_test.go deleted file mode 100644 index 49d11b2..0000000 --- a/engine/image_test.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Polyform License -// that can be found in the LICENSE file. - -package engine - -import "testing" - -func TestParseImage(t *testing.T) { - tests := []struct { - image string - canonical string - domain string - latest bool - err bool - }{ - { - image: "golang", - canonical: "docker.io/library/golang:latest", - domain: "docker.io", - latest: true, - }, - { - image: "golang:1.11", - canonical: "docker.io/library/golang:1.11", - domain: "docker.io", - latest: false, - }, - { - image: "", - err: true, - }, - } - - for _, test := range tests { - canonical, domain, latest, err := parseImage(test.image) - if test.err { - if err == nil { - t.Errorf("Expect error parsing image %s", test.image) - } - continue - } - if err != nil { - t.Error(err) - } - if got, want := canonical, test.canonical; got != want { - t.Errorf("Want image %s, got %s", want, got) - } - if got, want := domain, test.domain; got != want { - t.Errorf("Want image domain %s, got %s", want, got) - } - if got, want := latest, test.latest; got != want { - t.Errorf("Want image latest %v, got %v", want, got) - } - } -} diff --git a/go.mod b/go.mod index 1ad6c15..978e826 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/drone/signal v1.0.0 github.com/ghodss/yaml v1.0.0 github.com/gogo/protobuf v0.0.0-20170307180453-100ba4e88506 // indirect + github.com/golang/mock v1.3.1 github.com/google/go-cmp v0.3.0 github.com/hashicorp/go-multierror v1.0.0 github.com/joho/godotenv v1.3.0 diff --git a/go.sum b/go.sum index cbdb0a2..bb6e9d6 100644 --- a/go.sum +++ b/go.sum @@ -39,6 +39,8 @@ github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gogo/protobuf v0.0.0-20170307180453-100ba4e88506 h1:zDlw+wgyXdfkRuvFCdEDUiPLmZp2cvf/dWHazY0a5VM= github.com/gogo/protobuf v0.0.0-20170307180453-100ba4e88506/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -79,6 +81,7 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 h1:ydJNl0ENAG67pFbB+9tfhiL2pYqLhfoaZFw/cjLhY4A= golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= @@ -90,6 +93,7 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/p golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/internal/docker/image/image.go b/internal/docker/image/image.go index 8545e0f..ac28991 100644 --- a/internal/docker/image/image.go +++ b/internal/docker/image/image.go @@ -4,7 +4,11 @@ package image -import "github.com/docker/distribution/reference" +import ( + "strings" + + "github.com/docker/distribution/reference" +) // Trim returns the short image name without tag. func Trim(name string) string { @@ -69,3 +73,9 @@ func MatchHostname(image, hostname string) bool { } return reference.Domain(named) == hostname } + +// IsLatest parses the image and returns true if +// the image uses the :latest tag. +func IsLatest(s string) bool { + return strings.HasSuffix(Expand(s), ":latest") +} diff --git a/internal/docker/image/image_test.go b/internal/docker/image/image_test.go index eb252f4..37fa3e2 100644 --- a/internal/docker/image/image_test.go +++ b/internal/docker/image/image_test.go @@ -297,3 +297,41 @@ func Test_matchTag(t *testing.T) { } } } + +func Test_isLatest(t *testing.T) { + testdata := []struct { + name string + want bool + }{ + { + name: "golang:1", + want: false, + }, + { + name: "golang", + want: true, + }, + { + name: "golang:latest", + want: true, + }, + { + name: "docker.io/library/golang", + want: true, + }, + { + name: "docker.io/library/golang:latest", + want: true, + }, + { + name: "docker.io/library/golang:1", + want: false, + }, + } + for _, test := range testdata { + got, want := IsLatest(test.name), test.want + if got != want { + t.Errorf("Want image %q isLatest %v", test.name, want) + } + } +} diff --git a/internal/mock/mock_engine_gen.go b/internal/mock/mock_engine_gen.go new file mode 100644 index 0000000..a6cd762 --- /dev/null +++ b/internal/mock/mock_engine_gen.go @@ -0,0 +1,79 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/drone-runners/drone-runner-docker/engine (interfaces: Engine) + +// Package mock is a generated GoMock package. +package mock + +import ( + context "context" + engine "github.com/drone-runners/drone-runner-docker/engine" + gomock "github.com/golang/mock/gomock" + io "io" + reflect "reflect" +) + +// MockEngine is a mock of Engine interface +type MockEngine struct { + ctrl *gomock.Controller + recorder *MockEngineMockRecorder +} + +// MockEngineMockRecorder is the mock recorder for MockEngine +type MockEngineMockRecorder struct { + mock *MockEngine +} + +// NewMockEngine creates a new mock instance +func NewMockEngine(ctrl *gomock.Controller) *MockEngine { + mock := &MockEngine{ctrl: ctrl} + mock.recorder = &MockEngineMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockEngine) EXPECT() *MockEngineMockRecorder { + return m.recorder +} + +// Destroy mocks base method +func (m *MockEngine) Destroy(arg0 context.Context, arg1 *engine.Spec) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Destroy", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// Destroy indicates an expected call of Destroy +func (mr *MockEngineMockRecorder) Destroy(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Destroy", reflect.TypeOf((*MockEngine)(nil).Destroy), arg0, arg1) +} + +// Run mocks base method +func (m *MockEngine) Run(arg0 context.Context, arg1 *engine.Spec, arg2 *engine.Step, arg3 io.Writer) (*engine.State, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Run", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(*engine.State) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Run indicates an expected call of Run +func (mr *MockEngineMockRecorder) Run(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Run", reflect.TypeOf((*MockEngine)(nil).Run), arg0, arg1, arg2, arg3) +} + +// Setup mocks base method +func (m *MockEngine) Setup(arg0 context.Context, arg1 *engine.Spec) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Setup", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// Setup indicates an expected call of Setup +func (mr *MockEngineMockRecorder) Setup(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Setup", reflect.TypeOf((*MockEngine)(nil).Setup), arg0, arg1) +} diff --git a/internal/mock/mock_execer_gen.go b/internal/mock/mock_execer_gen.go new file mode 100644 index 0000000..b0a2250 --- /dev/null +++ b/internal/mock/mock_execer_gen.go @@ -0,0 +1,50 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/drone-runners/drone-runner-docker/runtime (interfaces: Execer) + +// Package mock is a generated GoMock package. +package mock + +import ( + context "context" + engine "github.com/drone-runners/drone-runner-docker/engine" + pipeline "github.com/drone/runner-go/pipeline" + gomock "github.com/golang/mock/gomock" + reflect "reflect" +) + +// MockExecer is a mock of Execer interface +type MockExecer struct { + ctrl *gomock.Controller + recorder *MockExecerMockRecorder +} + +// MockExecerMockRecorder is the mock recorder for MockExecer +type MockExecerMockRecorder struct { + mock *MockExecer +} + +// NewMockExecer creates a new mock instance +func NewMockExecer(ctrl *gomock.Controller) *MockExecer { + mock := &MockExecer{ctrl: ctrl} + mock.recorder = &MockExecerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockExecer) EXPECT() *MockExecerMockRecorder { + return m.recorder +} + +// Exec mocks base method +func (m *MockExecer) Exec(arg0 context.Context, arg1 *engine.Spec, arg2 *pipeline.State) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Exec", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// Exec indicates an expected call of Exec +func (mr *MockExecerMockRecorder) Exec(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Exec", reflect.TypeOf((*MockExecer)(nil).Exec), arg0, arg1, arg2) +}