diff --git a/engine/compiler/compiler.go b/engine/compiler/compiler.go index 1b8dfb1a..d188b445 100644 --- a/engine/compiler/compiler.go +++ b/engine/compiler/compiler.go @@ -50,16 +50,12 @@ func (c *Compiler) Compile(ctx context.Context, args runtime.CompilerArgs) runti spec.Name = pipeline.Name - // create system labels - systemLabels := labels.Combine( - labels.FromRepo(args.Repo), - labels.FromBuild(args.Build), - labels.FromStage(args.Stage), - labels.FromSystem(args.System), - labels.WithTimeout(args.Repo), - ) + // get OS and the root directory where the work directory and everything else will be placed targetPool := pipeline.Pool.Use pool := c.PoolManager.Get(targetPool) + if pool == nil { + return spec + } pipelineOS := pool.GetOS() pipelineRoot := pool.GetRootDir() @@ -67,67 +63,32 @@ func (c *Compiler) Compile(ctx context.Context, args runtime.CompilerArgs) runti // move the pool from the `mapping of pools` into the spec of this pipeline. spec.CloudInstance.PoolName = targetPool - // creates a home directory in the root. - // note: mkdirall fails on windows so we need to create all directories in the tree. - homedir := oshelp.JoinPaths(pipelineOS, pipelineRoot, "home", "drone") - spec.Files = append(spec.Files, - &lespec.File{ - Path: oshelp.JoinPaths(pipelineOS, pipelineRoot, "home"), - Mode: 0700, - IsDir: true, - }, &lespec.File{ - Path: homedir, - Mode: 0700, - IsDir: true, - }) - - // creates a source directory in the root. - // note: mkdirall fails on windows so we need to create all - // directories in the tree. - sourceDir := oshelp.JoinPaths(pipelineOS, pipelineRoot, "drone", "src") - scriptDir := oshelp.JoinPaths(pipelineOS, pipelineRoot, "opt") - spec.Files = append(spec.Files, - &lespec.File{ - Path: oshelp.JoinPaths(pipelineOS, pipelineRoot, "drone"), - Mode: 0700, - IsDir: true, - }, - &lespec.File{ - Path: sourceDir, - Mode: 0700, - IsDir: true, - }, - &lespec.File{ - Path: scriptDir, - Mode: 0700, - IsDir: true, - }) + // create directories + // * homeDir is home directory on the host machine where netrc file will be placed + // * sourceDir is directory on the host machine where source code will be pulled + // * scriptDir is directory on the host machine where script files (with commands) will be placed + directories, homeDir, sourceDir, scriptDir := createDirectories(pipelineOS, pipelineRoot) + spec.Files = append(spec.Files, directories...) - // creates the netrc file - if args.Netrc != nil && args.Netrc.Password != "" { + // create netrc file if needed + if netrc := args.Netrc; netrc != nil && netrc.Password != "" { netrcfile := oshelp.GetNetrc(pipelineOS) - netrcpath := oshelp.JoinPaths(pipelineOS, homedir, netrcfile) + netrcpath := oshelp.JoinPaths(pipelineOS, homeDir, netrcfile) netrcdata := fmt.Sprintf( "machine %s login %s password %s", - args.Netrc.Machine, - args.Netrc.Login, - args.Netrc.Password, + netrc.Machine, + netrc.Login, + netrc.Password, ) - spec.Files = append(spec.Files, - &lespec.File{ - Path: netrcpath, - Mode: 0600, - Data: netrcdata, - }) + + spec.Files = append(spec.Files, &lespec.File{Path: netrcpath, Mode: 0600, Data: netrcdata}) } - // list the global environment variables + // create the default environment variables. globals, _ := c.Environ.List(ctx, &provider.Request{ Build: args.Build, Repo: args.Repo, }) - - // create the default environment variables. envs := environ.Combine( provider.ToMap( provider.FilterUnmasked(globals), @@ -149,30 +110,18 @@ func (c *Compiler) Compile(ctx context.Context, args runtime.CompilerArgs) runti }, }), map[string]string{ - "HOME": homedir, - "HOMEPATH": homedir, // for windows - "USERPROFILE": homedir, // for windows + "HOME": homeDir, + "HOMEPATH": homeDir, // for windows + "USERPROFILE": homeDir, // for windows "DRONE_HOME": sourceDir, "DRONE_WORKSPACE": sourceDir, "GIT_TERMINAL_PROMPT": "0", }, ) - match := manifest.Match{ - Action: args.Build.Action, - Cron: args.Build.Cron, - Ref: args.Build.Ref, - Repo: args.Repo.Slug, - Instance: args.System.Host, - Target: args.Build.Deploy, - Event: args.Build.Event, - Branch: args.Build.Target, - } - // create the clone step, maybe if !pipeline.Clone.Disable { - clonepath := oshelp.JoinPaths(pipelineOS, pipelineRoot, "opt", oshelp.GetExt(pipelineOS, "clone")) - clonefile := oshelp.GenScript(pipelineOS, + cloneScript := oshelp.GenScript(pipelineOS, clone.Commands( clone.Args{ Branch: args.Build.Target, @@ -182,26 +131,25 @@ func (c *Compiler) Compile(ctx context.Context, args runtime.CompilerArgs) runti }, ), ) - var cloneEntrypoint []string - if pipelineOS == oshelp.OSWindows { - cloneEntrypoint = []string{"powershell"} - } else { - cloneEntrypoint = []string{"sh", "-c"} - } + clonePath := oshelp.JoinPaths(pipelineOS, pipelineRoot, "opt", oshelp.GetExt(pipelineOS, "clone")) + + entrypoint := getEntrypoint(pipelineOS) + command := []string{clonePath} + spec.Steps = append(spec.Steps, &engine.Step{ Step: lespec.Step{ ID: random(), Name: "clone", - Entrypoint: cloneEntrypoint, - Command: []string{clonefile}, + Entrypoint: entrypoint, + Command: command, Envs: envs, Secrets: []*lespec.Secret{}, WorkingDir: sourceDir, Files: []*lespec.File{ { - Path: clonepath, + Path: clonePath, Mode: 0700, - Data: clonefile, + Data: cloneScript, }, }, }, @@ -210,135 +158,80 @@ func (c *Compiler) Compile(ctx context.Context, args runtime.CompilerArgs) runti RunPolicy: runtime.RunAlways, }) } - // create volumes map, name of volume and real life path - for _, v := range pipeline.Volumes { - id := random() - path := "" - src := new(lespec.Volume) - if v.EmptyDir != nil { - src.EmptyDir = &lespec.VolumeEmptyDir{ - ID: id, - Name: v.Name, - Labels: systemLabels, - } - } else if v.HostPath != nil { - path = v.HostPath.Path - src.HostPath = &lespec.VolumeHostPath{ - ID: id, - Name: v.Name, - Path: path, - Labels: systemLabels, - } - } else { - continue - } - - spec.Volumes = append(spec.Volumes, src) - } - // now we need to create a source volume, used by every container step - SourceVolume := lespec.VolumeHostPath{ - ID: fmt.Sprintf("source_dir_%s", random()), - Name: "source_dir", - Path: sourceDir, - } - spec.Volumes = append(spec.Volumes, &lespec.Volume{ - HostPath: &SourceVolume, - }) - // now we need to create a script volume, used by every container step - ScriptVolume := lespec.VolumeHostPath{ - ID: fmt.Sprintf("script_dir_%s", random()), - Name: "script_dir", - Path: scriptDir, + // match object is used to determine is a step should be executed or not + match := manifest.Match{ + Action: args.Build.Action, + Cron: args.Build.Cron, + Ref: args.Build.Ref, + Repo: args.Repo.Slug, + Instance: args.System.Host, + Target: args.Build.Deploy, + Event: args.Build.Event, + Branch: args.Build.Target, } - spec.Volumes = append(spec.Volumes, &lespec.Volume{ - HostPath: &ScriptVolume, - }) - // services are the same as steps, but are executed first and are detached. + + // create steps + containerSourcePath := getContainerSourcePath(pipelineOS) + haveImageSteps := false // should be true if there is at least one step that uses an image for _, src := range pipeline.Services { - src.Detach = true + src.Detach = true // services are the same as steps, but are executed first and are detached } - // combine steps + services - combinedSteps := append(pipeline.Services, pipeline.Steps...) //nolint:gocritic // creating a new slice is ok - // create steps - for _, src := range combinedSteps { + for _, src := range append(pipeline.Services, pipeline.Steps...) { // combine: services+steps + stepID := random() + stepEnv := environ.Combine(envs, environ.Expand(convertStaticEnv(src.Environment))) + stepSecrets := convertSecretEnv(src.Environment) - var files []*lespec.File - var volumes []*lespec.VolumeMount - var command []string var entrypoint []string - stepID := random() + var command []string + var files []*lespec.File + + // set entrypoint if running on the host or if the container has commands + if src.Image == "" || (src.Image != "" && len(src.Commands) > 0) { + entrypoint = getEntrypoint(pipelineOS) + } + // build the script of commands we will execute if len(src.Commands) > 0 { - // build the script of commands we will execute scriptToExecute := oshelp.GenScript(pipelineOS, src.Commands) scriptPath := oshelp.JoinPaths(pipelineOS, pipelineRoot, "opt", oshelp.GetExt(pipelineOS, stepID)) + files = append(files, &lespec.File{ Path: scriptPath, Mode: 0700, Data: scriptToExecute, }) + + // the command is actually a file name where combined script for the step is located command = append(command, scriptPath) } - // set entrypoint if running on the host or if the container has commands - if src.Image == "" || (src.Image != "" && len(src.Commands) > 0) { - if pipelineOS == oshelp.OSWindows { - entrypoint = []string{"powershell"} - } else { - entrypoint = []string{"sh", "-c"} + + // set working directory for the step and volume mount locations for steps that use an image + var volumeMounts []*lespec.VolumeMount + var workingDir string + if src.Image != "" { + haveImageSteps = true + + // add the volumes + for _, v := range src.Volumes { + volumeMounts = append(volumeMounts, &lespec.VolumeMount{Name: v.Name, Path: v.MountPath}) } - } - // add the volumes - for _, v := range src.Volumes { - volumes = append(volumes, &lespec.VolumeMount{ - Name: v.Name, - Path: v.MountPath, - }) - } - // finally mount the source directory in the container - var containerSourcePath string - if pipelineOS == oshelp.OSWindows { - containerSourcePath = "c:/drone/src" + + // mount the source directory in the container + volumeMounts = append(volumeMounts, &lespec.VolumeMount{Name: "source_dir", Path: containerSourcePath}) + + // mount the script directory, but only if the steps has commands defined + if len(src.Commands) > 0 { + volumeMounts = append(volumeMounts, &lespec.VolumeMount{Name: "script_dir", Path: scriptDir}) + } + + workingDir = containerSourcePath // steps that use an image use mounted directory as working directory } else { - containerSourcePath = "/drone/src" - } - // container change working dir and add source volume, otherwise use sourcedir - workingDir := sourceDir - if src.Image != "" { - volumes = append(volumes, &lespec.VolumeMount{ - Name: "source_dir", - Path: containerSourcePath, - }) - workingDir = containerSourcePath - // now add the script volume - volumes = append(volumes, &lespec.VolumeMount{ - Name: "script_dir", - Path: scriptDir, - }) - } - // create the step - dst := &engine.Step{ - Step: lespec.Step{ - ID: stepID, - Name: src.Name, - Command: command, - Detach: src.Detach, - Envs: stepEnv, - Entrypoint: entrypoint, - Files: files, - Image: src.Image, - Secrets: convertSecretEnv(src.Environment), - WorkingDir: workingDir, - Volumes: volumes, - Privileged: true, - }, - DependsOn: src.DependsOn, - RunPolicy: runtime.RunOnSuccess, + workingDir = sourceDir } - // appends the settings variables to the - // container definition. + // appends the settings variables to the container definition. for key, value := range src.Settings { if value == nil { continue @@ -351,7 +244,7 @@ func (c *Compiler) Compile(ctx context.Context, args runtime.CompilerArgs) runti // if the setting parameter is sources from the // secret we create a secret environment variable. if value.Secret != "" { - dst.Secrets = append(dst.Secrets, &lespec.Secret{ + stepSecrets = append(stepSecrets, &lespec.Secret{ Name: value.Secret, Mask: true, Env: key, @@ -360,25 +253,94 @@ func (c *Compiler) Compile(ctx context.Context, args runtime.CompilerArgs) runti // else if the setting parameter is opaque // we inject as a string-encoded environment // variable. - dst.Envs[key] = encoder.Encode(value.Value) + stepEnv[key] = encoder.Encode(value.Value) } } - spec.Steps = append(spec.Steps, dst) - // set the pipeline step run policy. steps run on success by default, but may be optionally configured to run on failure. + runPolicy := runtime.RunOnSuccess if isRunAlways(src) { - dst.RunPolicy = runtime.RunAlways + runPolicy = runtime.RunAlways } else if isRunOnFailure(src) { - dst.RunPolicy = runtime.RunOnFailure + runPolicy = runtime.RunOnFailure } // if the pipeline step has unmet conditions the step is automatically skipped. if !src.When.Match(match) { - dst.RunPolicy = runtime.RunNever + runPolicy = runtime.RunNever + } + + // create the step + spec.Steps = append(spec.Steps, &engine.Step{ + Step: lespec.Step{ + Command: command, + Detach: src.Detach, + Envs: stepEnv, + Entrypoint: entrypoint, + Files: files, + ID: stepID, + Image: src.Image, + Name: src.Name, + Privileged: src.Image != "", // all steps that use images, run in privileged mode + Secrets: stepSecrets, + WorkingDir: workingDir, + Volumes: volumeMounts, + }, + DependsOn: src.DependsOn, + RunPolicy: runPolicy, + }) + } + + // create volumes + systemLabels := labels.Combine( + labels.FromRepo(args.Repo), + labels.FromBuild(args.Build), + labels.FromStage(args.Stage), + labels.FromSystem(args.System), + labels.WithTimeout(args.Repo), + ) + for _, v := range pipeline.Volumes { + if v.EmptyDir != nil { + spec.Volumes = append(spec.Volumes, &lespec.Volume{ + EmptyDir: &lespec.VolumeEmptyDir{ + ID: random(), + Name: v.Name, + Labels: systemLabels, + }, + }) + } else if v.HostPath != nil { + spec.Volumes = append(spec.Volumes, &lespec.Volume{ + HostPath: &lespec.VolumeHostPath{ + ID: random(), + Name: v.Name, + Path: v.HostPath.Path, + Labels: systemLabels, + }, + }) } } + if haveImageSteps { + // source dir and script dir will be added as volumes only if there is at least on step that uses an image. + spec.Volumes = append(spec.Volumes, + &lespec.Volume{ // a source volume, used by every container step + HostPath: &lespec.VolumeHostPath{ + ID: "source_dir_" + random(), + Name: "source_dir", + Path: sourceDir, + Labels: systemLabels, + }, + }, + &lespec.Volume{ // a script volume, used by every container step + HostPath: &lespec.VolumeHostPath{ + ID: "script_dir_" + random(), + Name: "script_dir", + Path: scriptDir, + Labels: systemLabels, + }, + }) + } + // set step dependencies if !isGraph(spec) { configureSerial(spec) } else if !pipeline.Clone.Disable { @@ -387,6 +349,7 @@ func (c *Compiler) Compile(ctx context.Context, args runtime.CompilerArgs) runti removeCloneDeps(spec) } + // set secret values for _, step := range spec.Steps { for _, s := range step.Secrets { actualSecret, ok := c.findSecret(ctx, args, s.Name) @@ -424,3 +387,39 @@ func (c *Compiler) findSecret(ctx context.Context, args runtime.CompilerArgs, na } return found.Data, true } + +func createDirectories(pipelineOS, pipelineRoot string) (directories []*lespec.File, homeDir, sourceDir, scriptDir string) { + homeRootDir := oshelp.JoinPaths(pipelineOS, pipelineRoot, "home") + homeDir = oshelp.JoinPaths(pipelineOS, homeRootDir, "drone") + + droneDir := oshelp.JoinPaths(pipelineOS, pipelineRoot, "drone") + sourceDir = oshelp.JoinPaths(pipelineOS, droneDir, "src") + + scriptDir = oshelp.JoinPaths(pipelineOS, pipelineRoot, "opt") + + directories = []*lespec.File{ + {Path: homeRootDir, Mode: 0700, IsDir: true}, + {Path: homeDir, Mode: 0700, IsDir: true}, + {Path: droneDir, Mode: 0700, IsDir: true}, + {Path: sourceDir, Mode: 0700, IsDir: true}, + {Path: scriptDir, Mode: 0700, IsDir: true}, + } + + return +} + +func getEntrypoint(pipelineOS string) []string { + if pipelineOS == oshelp.OSWindows { + return []string{"powershell"} + } + + return []string{"sh", "-c"} +} + +func getContainerSourcePath(pipelineOS string) string { + if pipelineOS == oshelp.OSWindows { + return "c:/drone/src" + } + + return "/drone/src" +} diff --git a/engine/compiler/_compiler_test.go b/engine/compiler/compiler_test.go similarity index 72% rename from engine/compiler/_compiler_test.go rename to engine/compiler/compiler_test.go index 77e2ce7b..68a052a2 100644 --- a/engine/compiler/_compiler_test.go +++ b/engine/compiler/compiler_test.go @@ -6,22 +6,23 @@ package compiler import ( "context" + "encoding/base64" "encoding/json" "os" + "sort" "testing" - "github.com/drone-runners/drone-runner-aws/internal/vmpool/cloudaws" - - "github.com/drone-runners/drone-runner-aws/internal/vmpool" - "github.com/drone-runners/drone-runner-aws/engine" "github.com/drone-runners/drone-runner-aws/engine/resource" + "github.com/drone-runners/drone-runner-aws/internal/vmpool" + "github.com/drone-runners/drone-runner-aws/internal/vmpool/cloudaws" "github.com/drone/drone-go/drone" "github.com/drone/runner-go/environ/provider" "github.com/drone/runner-go/manifest" "github.com/drone/runner-go/pipeline/runtime" "github.com/drone/runner-go/secret" + lespec "github.com/harness/lite-engine/engine/spec" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" @@ -97,48 +98,49 @@ func TestCompile_RunFailure(t *testing.T) { } } -// This test verifies that secrets defined in the yaml are -// requested and stored in the intermediate representation -// at compile time. -func TestCompile_Secrets(t *testing.T) { - mnfst, _ := manifest.ParseFile("testdata/secret.yml") +// This test verifies the pipelines with container images and services. +func TestCompile_Image(t *testing.T) { + testCompile(t, "testdata/image.yml", "testdata/image.json") +} - pools, err := cloudaws.ProcessPoolFile("testdata/drone_pool.yml", &defaultPoolSettings) - if err != nil { - t.Error(err) - return +// This test verifies the pipelines with container images that use volumes. +func TestCompile_Plugin(t *testing.T) { + ir := testCompile(t, "testdata/plugins.yml", "testdata/plugins.json") + if ir.Steps[1].Envs["PLUGIN_LOCATION"] != "production" { + t.Error("incorrect or missing 'location' setting from the step environment") } - - poolManager := &vmpool.Manager{} - err = poolManager.Add(pools...) - if err != nil { - t.Error(err) - return + if ir.Steps[1].Envs["PLUGIN_LOCATION"] != "production" { + t.Error("incorrect or missing 'location' setting from the step environment") } - - compiler := &Compiler{ - Environ: provider.Static(nil), - Secret: secret.StaticVars(map[string]string{ - "token": "3DA541559918A808C2402BBA5012F6C60B27661C", - "password": "password", - "my_username": "octocat", - }), - PoolManager: poolManager, + var username, password string + for _, s := range ir.Steps[1].Secrets { + if s.Env == "PLUGIN_USERNAME" { + username = string(s.Data) + } else if s.Env == "PLUGIN_PASSWORD" { + password = string(s.Data) + } } - args := runtime.CompilerArgs{ - Repo: &drone.Repo{}, - Build: &drone.Build{}, - Stage: &drone.Stage{}, - System: &drone.System{}, - Netrc: &drone.Netrc{}, - Manifest: mnfst, - Pipeline: mnfst.Resources[0].(*resource.Pipeline), - Secret: secret.Static(nil), + if username != "octocat" { + t.Error("incorrect or missing 'username' setting from the step secrets") + } + if password != "password" { + t.Error("incorrect or missing 'password' setting from the step secrets") } +} + +// This test verifies the pipelines with container images that use volumes. +func TestCompile_Image_Volumes(t *testing.T) { + testCompile(t, "testdata/volumes.yml", "testdata/volumes.json") +} + +// This test verifies that secrets defined in the yaml are +// requested and stored in the intermediate representation +// at compile time. +func TestCompile_Secrets(t *testing.T) { + ir := testCompile(t, "testdata/secret.yml", "testdata/secret.json") - ir := compiler.Compile(nocontext, args).(*engine.Spec) got := ir.Steps[0].Secrets - want := []*engine.Secret{ + want := []*lespec.Secret{ { Name: "my_password", Env: "PASSWORD", @@ -152,10 +154,16 @@ func TestCompile_Secrets(t *testing.T) { Mask: true, }, } + + sort.Slice(got, func(i, j int) bool { + return got[i].Name < got[j].Name + }) + sort.Slice(want, func(i, j int) bool { + return want[i].Name < want[j].Name + }) + if diff := cmp.Diff(got, want); diff != "" { - // BUG(bradrydzewski) ordering is not guaranteed. this - // unit tests needs to be adjusted accordingly. - t.Skipf(diff) + t.Errorf(diff) } } @@ -220,11 +228,27 @@ func testCompile(t *testing.T, source, golden string) *engine.Spec { err = json.Unmarshal(raw, want) if err != nil { t.Error(err) + return want + } + + // convert file data to base64 for easier comparison + for _, f := range got.(*engine.Spec).Files { + if !f.IsDir { + f.Data = base64.StdEncoding.EncodeToString([]byte(f.Data)) + } + } + for _, step := range got.(*engine.Spec).Steps { + for _, f := range step.Files { + if !f.IsDir { + f.Data = base64.StdEncoding.EncodeToString([]byte(f.Data)) + } + } } opts := cmp.Options{ - cmpopts.IgnoreUnexported(engine.Spec{}), cmpopts.IgnoreFields(engine.Step{}, "Envs", "Secrets"), + cmpopts.IgnoreFields(lespec.VolumeHostPath{}, "Labels"), + cmpopts.IgnoreFields(lespec.VolumeEmptyDir{}, "Labels"), } if diff := cmp.Diff(got, want, opts...); diff != "" { t.Errorf("%s\n%v", t.Name(), diff) diff --git a/engine/compiler/testdata/graph.json b/engine/compiler/testdata/graph.json index 2d72ca4f..654bf58f 100644 --- a/engine/compiler/testdata/graph.json +++ b/engine/compiler/testdata/graph.json @@ -1,11 +1,7 @@ { - "root": "/tmp/aws", "name": "default", "cloud_instance": { - "pool_name": "ubuntu", - "cloud": "", - "id": "", - "ip": "" + "pool_name": "ubuntu" }, "files": [ { @@ -41,11 +37,10 @@ ], "steps": [ { - "args": [ - "-e", - "/tmp/aws/opt/clone" - ], - "command": "/bin/sh", + "id": "random", + "name": "clone", + "entrypoint": ["sh", "-c"], + "args": ["/tmp/aws/opt/clone"], "environment": {}, "files": [ { @@ -54,49 +49,40 @@ "data": "CnNldCAtZQoKZWNobyArICJnaXQgaW5pdCIKZ2l0IGluaXQKCmVjaG8gKyAiZ2l0IHJlbW90ZSBhZGQgb3JpZ2luICIKZ2l0IHJlbW90ZSBhZGQgb3JpZ2luIAoKZWNobyArICJnaXQgZmV0Y2ggIG9yaWdpbiArcmVmcy9oZWFkcy9tYXN0ZXI6IgpnaXQgZmV0Y2ggIG9yaWdpbiArcmVmcy9oZWFkcy9tYXN0ZXI6CgplY2hvICsgImdpdCBjaGVja291dCAgLWIgbWFzdGVyIgpnaXQgY2hlY2tvdXQgIC1iIG1hc3Rlcgo=" } ], - "name": "clone", "run_policy": "always", "working_dir": "/tmp/aws/drone/src" }, { - "args": [ - "-e", - "/tmp/aws/opt/build" - ], - "command": "/bin/sh", - "depends_on": [ - "clone" - ], + "id": "random", + "name": "build", + "entrypoint": ["sh", "-c"], + "args": ["/tmp/aws/opt/random"], + "depends_on": ["clone"], "environment": {}, "files": [ { - "path": "/tmp/aws/opt/build", + "path": "/tmp/aws/opt/random", "mode": 448, "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQK" } ], - "name": "build", "working_dir": "/tmp/aws/drone/src" }, { - "args": [ - "-e", - "/tmp/aws/opt/test" - ], - "command": "/bin/sh", - "depends_on": [ - "build" - ], + "id": "random", + "name": "test", + "entrypoint": ["sh", "-c"], + "args": ["/tmp/aws/opt/random"], + "depends_on": ["build"], "environment": {}, "files": [ { - "path": "/tmp/aws/opt/test", + "path": "/tmp/aws/opt/random", "mode": 448, "data": "CnNldCAtZQoKZWNobyArICJnbyB0ZXN0IgpnbyB0ZXN0Cg==" } ], - "name": "test", "working_dir": "/tmp/aws/drone/src" } ] -} \ No newline at end of file +} diff --git a/engine/compiler/testdata/graph.yml b/engine/compiler/testdata/graph.yml index b159ab45..ef8e1c7b 100644 --- a/engine/compiler/testdata/graph.yml +++ b/engine/compiler/testdata/graph.yml @@ -4,13 +4,13 @@ name: default pool: use: ubuntu - + steps: -- name: build - commands: - - go build + - name: build + commands: + - go build -- name: test - commands: - - go test - depends_on: [ build ] + - name: test + commands: + - go test + depends_on: [ build ] diff --git a/engine/compiler/testdata/image.json b/engine/compiler/testdata/image.json new file mode 100644 index 00000000..657c8140 --- /dev/null +++ b/engine/compiler/testdata/image.json @@ -0,0 +1,97 @@ +{ + "name": "default", + "cloud_instance": { + "pool_name": "ubuntu" + }, + "files": [ + { + "path": "/tmp/aws/home", + "mode": 448, + "is_dir": true + }, + { + "path": "/tmp/aws/home/drone", + "mode": 448, + "is_dir": true + }, + { + "path": "/tmp/aws/drone", + "mode": 448, + "is_dir": true + }, + { + "path": "/tmp/aws/drone/src", + "mode": 448, + "is_dir": true + }, + { + "path": "/tmp/aws/opt", + "mode": 448, + "is_dir": true + }, + { + "path": "/tmp/aws/home/drone/.netrc", + "mode": 384, + "data": "bWFjaGluZSBnaXRodWIuY29tIGxvZ2luIG9jdG9jYXQgcGFzc3dvcmQgY29ycmVjdC1ob3JzZS1iYXR0ZXJ5LXN0YXBsZQ==" + } + ], + "steps": [ + { + "id": "random", + "name": "clone", + "entrypoint": ["sh", "-c"], + "args": ["/tmp/aws/opt/clone"], + "files": [ + { + "path": "/tmp/aws/opt/clone", + "mode": 448, + "data": "CnNldCAtZQoKZWNobyArICJnaXQgaW5pdCIKZ2l0IGluaXQKCmVjaG8gKyAiZ2l0IHJlbW90ZSBhZGQgb3JpZ2luICIKZ2l0IHJlbW90ZSBhZGQgb3JpZ2luIAoKZWNobyArICJnaXQgZmV0Y2ggIG9yaWdpbiArcmVmcy9oZWFkcy9tYXN0ZXI6IgpnaXQgZmV0Y2ggIG9yaWdpbiArcmVmcy9oZWFkcy9tYXN0ZXI6CgplY2hvICsgImdpdCBjaGVja291dCAgLWIgbWFzdGVyIgpnaXQgY2hlY2tvdXQgIC1iIG1hc3Rlcgo=" + } + ], + "run_policy": "always", + "working_dir": "/tmp/aws/drone/src" + }, + { + "id": "random", + "name": "redis", + "run_policy": "on-success", + "depends_on": ["clone"], + "detach": true, + "image": "redis", + "privileged": true, + "working_dir": "/drone/src", + "volumes": [ + {"name": "source_dir", "path": "/drone/src"} + ] + }, + { + "id": "random", + "name": "build", + "entrypoint": ["sh", "-c"], + "args": ["/tmp/aws/opt/random"], + "depends_on": ["redis"], + "files": [ + { + "path": "/tmp/aws/opt/random", + "mode": 448, + "data": "CnNldCAtZQoKZWNobyArICJnbyB0ZXN0IgpnbyB0ZXN0CgplY2hvICsgImdvIGJ1aWxkIgpnbyBidWlsZAo=" + } + ], + "image": "golang:latest", + "privileged": true, + "working_dir": "/drone/src", + "volumes": [ + {"name": "source_dir", "path": "/drone/src"}, + {"name": "script_dir", "path": "/tmp/aws/opt"} + ] + } + ], + "volumes": [ + { + "host": {"id": "source_dir_random", "name": "source_dir", "path": "/tmp/aws/drone/src"} + }, + { + "host": {"id": "script_dir_random", "name": "script_dir", "path": "/tmp/aws/opt"} + } + ] +} diff --git a/engine/compiler/testdata/image.yml b/engine/compiler/testdata/image.yml new file mode 100644 index 00000000..190ccb12 --- /dev/null +++ b/engine/compiler/testdata/image.yml @@ -0,0 +1,17 @@ +kind: pipeline +type: aws +name: default + +pool: + use: ubuntu + +steps: + - name: build + image: golang:latest + commands: + - go test + - go build + +services: + - name: redis + image: redis diff --git a/engine/compiler/testdata/match.json b/engine/compiler/testdata/match.json index 3180ef49..546a8e4b 100644 --- a/engine/compiler/testdata/match.json +++ b/engine/compiler/testdata/match.json @@ -1,11 +1,7 @@ { - "root": "/tmp/aws", "name": "default", "cloud_instance": { - "pool_name": "ubuntu", - "cloud": "", - "id": "", - "ip": "" + "pool_name": "ubuntu" }, "files": [ { @@ -41,40 +37,32 @@ ], "steps": [ { - "args": [ - "-e", - "/tmp/aws/opt/build" - ], - "command": "/bin/sh", - "environment": {}, + "id": "random", + "name": "build", + "entrypoint": ["sh", "-c"], + "args": ["/tmp/aws/opt/random"], "files": [ { - "path": "/tmp/aws/opt/build", + "path": "/tmp/aws/opt/random", "mode": 448, "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQK" } ], - "name": "build", "working_dir": "/tmp/aws/drone/src" }, { - "args": [ - "-e", - "/tmp/aws/opt/test" - ], - "command": "/bin/sh", - "depends_on": [ - "build" - ], - "environment": {}, + "id": "random", + "name": "test", + "entrypoint": ["sh", "-c"], + "args": ["/tmp/aws/opt/random"], + "depends_on": ["build"], "files": [ { - "path": "/tmp/aws/opt/test", + "path": "/tmp/aws/opt/random", "mode": 448, "data": "CnNldCAtZQoKZWNobyArICJnbyB0ZXN0IgpnbyB0ZXN0Cg==" } ], - "name": "test", "run_policy": "never", "working_dir": "/tmp/aws/drone/src" } diff --git a/engine/compiler/testdata/match.yml b/engine/compiler/testdata/match.yml index db563dae..b64befa8 100644 --- a/engine/compiler/testdata/match.yml +++ b/engine/compiler/testdata/match.yml @@ -4,19 +4,19 @@ name: default pool: use: ubuntu - + clone: disable: true steps: -- name: build - commands: - - go build - when: - branch: [ master ] + - name: build + commands: + - go build + when: + branch: [ master ] -- name: test - commands: - - go test - when: - branch: [ develop ] + - name: test + commands: + - go test + when: + branch: [ develop ] diff --git a/engine/compiler/testdata/noclone_graph.json b/engine/compiler/testdata/noclone_graph.json index ee4edc76..969b9918 100644 --- a/engine/compiler/testdata/noclone_graph.json +++ b/engine/compiler/testdata/noclone_graph.json @@ -1,11 +1,7 @@ { - "root": "/tmp/aws", "name": "default", "cloud_instance": { - "pool_name": "ubuntu", - "cloud": "", - "id": "", - "ip": "" + "pool_name": "ubuntu" }, "files": [ { @@ -41,41 +37,35 @@ ], "steps": [ { - "args": [ - "-e", - "/tmp/aws/opt/build" - ], - "command": "/bin/sh", - "environment": {}, + "id": "random", + "name": "build", + "entrypoint": ["sh", "-c"], + "args": ["/tmp/aws/opt/random"], "files": [ { - "path": "/tmp/aws/opt/build", + "path": "/tmp/aws/opt/random", "mode": 448, "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQK" } ], - "name": "build", "working_dir": "/tmp/aws/drone/src" }, { - "args": [ - "-e", - "/tmp/aws/opt/test" - ], - "command": "/bin/sh", + "id": "random", + "name": "test", + "entrypoint": ["sh", "-c"], + "args": ["/tmp/aws/opt/random"], "depends_on": [ "build" ], - "environment": {}, "files": [ { - "path": "/tmp/aws/opt/test", + "path": "/tmp/aws/opt/random", "mode": 448, "data": "CnNldCAtZQoKZWNobyArICJnbyB0ZXN0IgpnbyB0ZXN0Cg==" } ], - "name": "test", "working_dir": "/tmp/aws/drone/src" } ] -} \ No newline at end of file +} diff --git a/engine/compiler/testdata/noclone_graph.yml b/engine/compiler/testdata/noclone_graph.yml index b2348151..1861708f 100644 --- a/engine/compiler/testdata/noclone_graph.yml +++ b/engine/compiler/testdata/noclone_graph.yml @@ -4,16 +4,16 @@ name: default pool: use: ubuntu - + clone: disable: true steps: -- name: build - commands: - - go build + - name: build + commands: + - go build -- name: test - commands: - - go test - depends_on: [ build ] \ No newline at end of file + - name: test + commands: + - go test + depends_on: [ build ] \ No newline at end of file diff --git a/engine/compiler/testdata/noclone_serial.json b/engine/compiler/testdata/noclone_serial.json index a5ddead4..3963dabf 100644 --- a/engine/compiler/testdata/noclone_serial.json +++ b/engine/compiler/testdata/noclone_serial.json @@ -1,11 +1,7 @@ { - "root": "/tmp/aws", "name": "default", "cloud_instance": { - "pool_name": "ubuntu", - "cloud": "", - "id": "", - "ip": "" + "pool_name": "ubuntu" }, "files": [ { @@ -41,20 +37,17 @@ ], "steps": [ { - "args": [ - "-e", - "/tmp/aws/opt/build" - ], - "command": "/bin/sh", - "environment": {}, + "id": "random", + "name": "build", + "entrypoint": ["sh", "-c"], + "args": ["/tmp/aws/opt/random"], "files": [ { - "path": "/tmp/aws/opt/build", + "path": "/tmp/aws/opt/random", "mode": 448, "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQKCmVjaG8gKyAiZ28gdGVzdCIKZ28gdGVzdAo=" } ], - "name": "build", "working_dir": "/tmp/aws/drone/src" } ] diff --git a/engine/compiler/testdata/noclone_serial.yml b/engine/compiler/testdata/noclone_serial.yml index c0031cdc..d63fcea2 100644 --- a/engine/compiler/testdata/noclone_serial.yml +++ b/engine/compiler/testdata/noclone_serial.yml @@ -4,12 +4,12 @@ name: default pool: use: ubuntu - + clone: disable: true steps: -- name: build - commands: - - go build - - go test + - name: build + commands: + - go build + - go test diff --git a/engine/compiler/testdata/plugins.json b/engine/compiler/testdata/plugins.json new file mode 100644 index 00000000..da69c955 --- /dev/null +++ b/engine/compiler/testdata/plugins.json @@ -0,0 +1,73 @@ +{ + "name": "default", + "cloud_instance": { + "pool_name": "ubuntu" + }, + "files": [ + { + "path": "/tmp/aws/home", + "mode": 448, + "is_dir": true + }, + { + "path": "/tmp/aws/home/drone", + "mode": 448, + "is_dir": true + }, + { + "path": "/tmp/aws/drone", + "mode": 448, + "is_dir": true + }, + { + "path": "/tmp/aws/drone/src", + "mode": 448, + "is_dir": true + }, + { + "path": "/tmp/aws/opt", + "mode": 448, + "is_dir": true + }, + { + "path": "/tmp/aws/home/drone/.netrc", + "mode": 384, + "data": "bWFjaGluZSBnaXRodWIuY29tIGxvZ2luIG9jdG9jYXQgcGFzc3dvcmQgY29ycmVjdC1ob3JzZS1iYXR0ZXJ5LXN0YXBsZQ==" + } + ], + "steps": [ + { + "id": "random", + "name": "build", + "entrypoint": ["sh", "-c"], + "args": ["/tmp/aws/opt/random"], + "files": [ + { + "path": "/tmp/aws/opt/random", + "mode": 448, + "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQKCmVjaG8gKyAiZ28gdGVzdCIKZ28gdGVzdAo=" + } + ], + "working_dir": "/tmp/aws/drone/src" + }, + { + "id": "random", + "name": "deploy", + "image": "deploy-project:latest", + "depends_on": ["build"], + "privileged": true, + "working_dir": "/drone/src", + "volumes": [ + {"name": "source_dir", "path": "/drone/src"} + ] + } + ], + "volumes": [ + { + "host": {"id": "source_dir_random", "name": "source_dir", "path": "/tmp/aws/drone/src"} + }, + { + "host": {"id": "script_dir_random", "name": "script_dir", "path": "/tmp/aws/opt"} + } + ] +} diff --git a/engine/compiler/testdata/plugins.yml b/engine/compiler/testdata/plugins.yml new file mode 100644 index 00000000..a2b62af2 --- /dev/null +++ b/engine/compiler/testdata/plugins.yml @@ -0,0 +1,23 @@ +kind: pipeline +type: aws +name: default + +pool: + use: ubuntu + +clone: + disable: true + +steps: + - name: build + commands: + - go build + - go test + - name: deploy + image: deploy-project:latest + settings: + location: production + password: + from_secret: password + username: + from_secret: my_username diff --git a/engine/compiler/testdata/run_always.json b/engine/compiler/testdata/run_always.json index eba3d806..4b58d247 100644 --- a/engine/compiler/testdata/run_always.json +++ b/engine/compiler/testdata/run_always.json @@ -1,11 +1,7 @@ { - "root": "/tmp/aws", "name": "default", "cloud_instance": { - "pool_name": "ubuntu", - "cloud": "", - "id": "", - "ip": "" + "pool_name": "ubuntu" }, "files": [ { @@ -41,22 +37,19 @@ ], "steps": [ { - "args": [ - "-e", - "/tmp/aws/opt/build" - ], - "command": "/bin/sh", - "environment": {}, + "id": "random", + "name": "build", + "entrypoint": ["sh", "-c"], + "args": ["/tmp/aws/opt/random"], "files": [ { - "path": "/tmp/aws/opt/build", + "path": "/tmp/aws/opt/random", "mode": 448, "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQK" } ], - "name": "build", "run_policy": "always", "working_dir": "/tmp/aws/drone/src" } ] -} \ No newline at end of file +} diff --git a/engine/compiler/testdata/run_always.yml b/engine/compiler/testdata/run_always.yml index f838f936..b0726093 100644 --- a/engine/compiler/testdata/run_always.yml +++ b/engine/compiler/testdata/run_always.yml @@ -4,13 +4,13 @@ name: default pool: use: ubuntu - + clone: disable: true steps: -- name: build - commands: - - go build - when: - status: [ success, failure ] + - name: build + commands: + - go build + when: + status: [ success, failure ] diff --git a/engine/compiler/testdata/run_failure.json b/engine/compiler/testdata/run_failure.json index 6d0ce3e2..0d8545d3 100644 --- a/engine/compiler/testdata/run_failure.json +++ b/engine/compiler/testdata/run_failure.json @@ -1,11 +1,7 @@ { - "root": "/tmp/aws", "name": "default", "cloud_instance": { - "pool_name": "ubuntu", - "cloud": "", - "id": "", - "ip": "" + "pool_name": "ubuntu" }, "files": [ { @@ -41,20 +37,17 @@ ], "steps": [ { - "args": [ - "-e", - "/tmp/aws/opt/build" - ], - "command": "/bin/sh", - "environment": {}, + "id": "random", + "name": "build", + "entrypoint": ["sh", "-c"], + "args": ["/tmp/aws/opt/random"], "files": [ { - "path": "/tmp/aws/opt/build", + "path": "/tmp/aws/opt/random", "mode": 448, "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQK" } ], - "name": "build", "run_policy": "on-failure", "working_dir": "/tmp/aws/drone/src" } diff --git a/engine/compiler/testdata/run_failure.yml b/engine/compiler/testdata/run_failure.yml index 10eb28e1..0b07ca6d 100644 --- a/engine/compiler/testdata/run_failure.yml +++ b/engine/compiler/testdata/run_failure.yml @@ -4,13 +4,13 @@ name: default pool: use: ubuntu - + clone: disable: true steps: -- name: build - commands: - - go build - when: - status: [ failure ] + - name: build + commands: + - go build + when: + status: [ failure ] diff --git a/engine/compiler/testdata/secret.json b/engine/compiler/testdata/secret.json new file mode 100644 index 00000000..6fddc497 --- /dev/null +++ b/engine/compiler/testdata/secret.json @@ -0,0 +1,54 @@ +{ + "name": "default", + "cloud_instance": { + "pool_name": "ubuntu" + }, + "files": [ + { + "path": "/tmp/aws/home", + "mode": 448, + "is_dir": true + }, + { + "path": "/tmp/aws/home/drone", + "mode": 448, + "is_dir": true + }, + { + "path": "/tmp/aws/drone", + "mode": 448, + "is_dir": true + }, + { + "path": "/tmp/aws/drone/src", + "mode": 448, + "is_dir": true + }, + { + "path": "/tmp/aws/opt", + "mode": 448, + "is_dir": true + }, + { + "path": "/tmp/aws/home/drone/.netrc", + "mode": 384, + "data": "bWFjaGluZSBnaXRodWIuY29tIGxvZ2luIG9jdG9jYXQgcGFzc3dvcmQgY29ycmVjdC1ob3JzZS1iYXR0ZXJ5LXN0YXBsZQ==" + } + ], + "steps": [ + { + "id": "random", + "name": "build", + "entrypoint": ["sh", "-c"], + "args": ["/tmp/aws/opt/random"], + "files": [ + { + "path": "/tmp/aws/opt/random", + "mode": 448, + "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQKCmVjaG8gKyAiZ28gdGVzdCIKZ28gdGVzdAo=" + } + ], + "working_dir": "/tmp/aws/drone/src" + } + ] +} diff --git a/engine/compiler/testdata/secret.yml b/engine/compiler/testdata/secret.yml index 7fcebb1c..d085fd49 100644 --- a/engine/compiler/testdata/secret.yml +++ b/engine/compiler/testdata/secret.yml @@ -4,17 +4,17 @@ name: default pool: use: ubuntu - + clone: disable: true steps: -- name: build - environment: - PASSWORD: - from_secret: my_password - USERNAME: - from_secret: my_username - commands: - - go build - - go test + - name: build + environment: + PASSWORD: + from_secret: my_password + USERNAME: + from_secret: my_username + commands: + - go build + - go test diff --git a/engine/compiler/testdata/serial.json b/engine/compiler/testdata/serial.json index 34b558a9..45e7ee02 100644 --- a/engine/compiler/testdata/serial.json +++ b/engine/compiler/testdata/serial.json @@ -5,56 +5,42 @@ }, "files": [ { - "file": { - "path": "/tmp/aws/home", - "mode": 448, - "is_dir": true - } + "path": "/tmp/aws/home", + "mode": 448, + "is_dir": true }, { - "file": { - "path": "/tmp/aws/home/drone", - "mode": 448, - "is_dir": true - } + "path": "/tmp/aws/home/drone", + "mode": 448, + "is_dir": true }, { - "file": { - "path": "/tmp/aws/drone", - "mode": 448, - "is_dir": true - } + "path": "/tmp/aws/drone", + "mode": 448, + "is_dir": true }, { - "file": { - "path": "/tmp/aws/drone/src", - "mode": 448, - "is_dir": true - } + "path": "/tmp/aws/drone/src", + "mode": 448, + "is_dir": true }, { - "file": { - "path": "/tmp/aws/opt", - "mode": 448, - "is_dir": true - } + "path": "/tmp/aws/opt", + "mode": 448, + "is_dir": true }, { - "file": { - "path": "/tmp/aws/home/drone/.netrc", - "mode": 384, - "data": "bWFjaGluZSBnaXRodWIuY29tIGxvZ2luIG9jdG9jYXQgcGFzc3dvcmQgY29ycmVjdC1ob3JzZS1iYXR0ZXJ5LXN0YXBsZQ==" - } + "path": "/tmp/aws/home/drone/.netrc", + "mode": 384, + "data": "bWFjaGluZSBnaXRodWIuY29tIGxvZ2luIG9jdG9jYXQgcGFzc3dvcmQgY29ycmVjdC1ob3JzZS1iYXR0ZXJ5LXN0YXBsZQ==" } ], "steps": [ { - "args": [ - "-e", - "/tmp/aws/opt/clone" - ], - "command": "/bin/sh", - "environment": {}, + "id": "random", + "name": "clone", + "entrypoint": ["sh", "-c"], + "args": ["/tmp/aws/opt/clone"], "files": [ { "path": "/tmp/aws/opt/clone", @@ -62,49 +48,38 @@ "data": "CnNldCAtZQoKZWNobyArICJnaXQgaW5pdCIKZ2l0IGluaXQKCmVjaG8gKyAiZ2l0IHJlbW90ZSBhZGQgb3JpZ2luICIKZ2l0IHJlbW90ZSBhZGQgb3JpZ2luIAoKZWNobyArICJnaXQgZmV0Y2ggIG9yaWdpbiArcmVmcy9oZWFkcy9tYXN0ZXI6IgpnaXQgZmV0Y2ggIG9yaWdpbiArcmVmcy9oZWFkcy9tYXN0ZXI6CgplY2hvICsgImdpdCBjaGVja291dCAgLWIgbWFzdGVyIgpnaXQgY2hlY2tvdXQgIC1iIG1hc3Rlcgo=" } ], - "name": "clone", "run_policy": "always", "working_dir": "/tmp/aws/drone/src" }, { - "args": [ - "-e", - "/tmp/aws/opt/build" - ], - "command": "/bin/sh", - "depends_on": [ - "clone" - ], - "environment": {}, + "id": "random", + "name": "build", + "entrypoint": ["sh", "-c"], + "args": ["/tmp/aws/opt/random"], + "depends_on": ["clone"], "files": [ { - "path": "/tmp/aws/opt/build", + "path": "/tmp/aws/opt/random", "mode": 448, "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQK" } ], - "name": "build", "working_dir": "/tmp/aws/drone/src" }, { - "args": [ - "-e", - "/tmp/aws/opt/test" - ], - "command": "/bin/sh", - "depends_on": [ - "build" - ], - "environment": {}, + "id": "random", + "name": "test", + "entrypoint": ["sh", "-c"], + "args": ["/tmp/aws/opt/random"], + "depends_on": ["build"], "files": [ { - "path": "/tmp/aws/opt/test", + "path": "/tmp/aws/opt/random", "mode": 448, "data": "CnNldCAtZQoKZWNobyArICJnbyB0ZXN0IgpnbyB0ZXN0Cg==" } ], - "name": "test", "working_dir": "/tmp/aws/drone/src" } ] -} \ No newline at end of file +} diff --git a/engine/compiler/testdata/serial.yml b/engine/compiler/testdata/serial.yml index 22b69b1e..7ed15d69 100644 --- a/engine/compiler/testdata/serial.yml +++ b/engine/compiler/testdata/serial.yml @@ -4,12 +4,12 @@ name: default pool: use: ubuntu - + steps: -- name: build - commands: - - go build + - name: build + commands: + - go build -- name: test - commands: - - go test + - name: test + commands: + - go test diff --git a/engine/compiler/testdata/volumes.json b/engine/compiler/testdata/volumes.json new file mode 100644 index 00000000..c4cd3960 --- /dev/null +++ b/engine/compiler/testdata/volumes.json @@ -0,0 +1,114 @@ +{ + "name": "default", + "cloud_instance": { + "pool_name": "ubuntu" + }, + "files": [ + { + "path": "/tmp/aws/home", + "mode": 448, + "is_dir": true + }, + { + "path": "/tmp/aws/home/drone", + "mode": 448, + "is_dir": true + }, + { + "path": "/tmp/aws/drone", + "mode": 448, + "is_dir": true + }, + { + "path": "/tmp/aws/drone/src", + "mode": 448, + "is_dir": true + }, + { + "path": "/tmp/aws/opt", + "mode": 448, + "is_dir": true + }, + { + "path": "/tmp/aws/home/drone/.netrc", + "mode": 384, + "data": "bWFjaGluZSBnaXRodWIuY29tIGxvZ2luIG9jdG9jYXQgcGFzc3dvcmQgY29ycmVjdC1ob3JzZS1iYXR0ZXJ5LXN0YXBsZQ==" + } + ], + "steps": [ + { + "id": "random", + "name": "clone", + "entrypoint": ["sh", "-c"], + "args": ["/tmp/aws/opt/clone"], + "files": [ + { + "path": "/tmp/aws/opt/clone", + "mode": 448, + "data": "CnNldCAtZQoKZWNobyArICJnaXQgaW5pdCIKZ2l0IGluaXQKCmVjaG8gKyAiZ2l0IHJlbW90ZSBhZGQgb3JpZ2luICIKZ2l0IHJlbW90ZSBhZGQgb3JpZ2luIAoKZWNobyArICJnaXQgZmV0Y2ggIG9yaWdpbiArcmVmcy9oZWFkcy9tYXN0ZXI6IgpnaXQgZmV0Y2ggIG9yaWdpbiArcmVmcy9oZWFkcy9tYXN0ZXI6CgplY2hvICsgImdpdCBjaGVja291dCAgLWIgbWFzdGVyIgpnaXQgY2hlY2tvdXQgIC1iIG1hc3Rlcgo=" + } + ], + "run_policy": "always", + "working_dir": "/tmp/aws/drone/src" + }, + { + "id": "random", + "name": "test", + "entrypoint": ["sh", "-c"], + "args": ["/tmp/aws/opt/random"], + "depends_on": ["clone"], + "files": [ + { + "path": "/tmp/aws/opt/random", + "mode": 448, + "data": "CnNldCAtZQoKZWNobyArICJnbyB0ZXN0IgpnbyB0ZXN0Cg==" + } + ], + "image": "golang:latest", + "privileged": true, + "working_dir": "/drone/src", + "volumes": [ + {"name": "gomodcache", "path": "/go/pkg/mod"}, + {"name": "source_dir", "path": "/drone/src"}, + {"name": "script_dir", "path": "/tmp/aws/opt"} + ] + }, + { + "id": "random", + "name": "build", + "entrypoint": ["sh", "-c"], + "args": ["/tmp/aws/opt/random"], + "depends_on": ["test"], + "files": [ + { + "path": "/tmp/aws/opt/random", + "mode": 448, + "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCAtbyBwcm9qZWN0LmV4ZSIKZ28gYnVpbGQgLW8gcHJvamVjdC5leGUKCmVjaG8gKyAiY3AgcHJvamVjdC5leGUgL291dHB1dCIKY3AgcHJvamVjdC5leGUgL291dHB1dAo=" + } + ], + "image": "golang:latest", + "privileged": true, + "working_dir": "/drone/src", + "volumes": [ + {"name": "gomodcache", "path": "/go/pkg/mod"}, + {"name": "output", "path": "/output"}, + {"name": "source_dir", "path": "/drone/src"}, + {"name": "script_dir", "path": "/tmp/aws/opt"} + ] + } + ], + "volumes": [ + { + "host": {"id": "random", "name": "output", "path": "/root"} + }, + { + "temp": {"id": "random", "name": "gomodcache"} + }, + { + "host": {"id": "source_dir_random", "name": "source_dir", "path": "/tmp/aws/drone/src"} + }, + { + "host": {"id": "script_dir_random", "name": "script_dir", "path": "/tmp/aws/opt"} + } + ] +} diff --git a/engine/compiler/testdata/volumes.yml b/engine/compiler/testdata/volumes.yml new file mode 100644 index 00000000..55242e1b --- /dev/null +++ b/engine/compiler/testdata/volumes.yml @@ -0,0 +1,32 @@ +kind: pipeline +type: aws +name: default + +pool: + use: ubuntu + +steps: + - name: test + image: golang:latest + commands: + - go test + volumes: + - name: gomodcache + path: /go/pkg/mod + - name: build + image: golang:latest + commands: + - go build -o project.exe + - cp project.exe /output + volumes: + - name: gomodcache + path: /go/pkg/mod + - name: output + path: /output + +volumes: + - name: output + host: + path: /root + - name: gomodcache + temp: {} \ No newline at end of file