Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions command/daemon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type Config struct {
NetworkOpts map[string]string `envconfig:"DRONE_RUNNER_NETWORK_OPTS"`
Privileged []string `envconfig:"DRONE_RUNNER_PRIVILEGED_IMAGES"`
Clone string `envconfig:"DRONE_RUNNER_CLONE_IMAGE"`
DNS []string `envconfig:"DRONE_RUNNER_DNS"`
}

Platform struct {
Expand Down
1 change: 1 addition & 0 deletions command/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func (c *daemonCommand) run(*kingpin.ParseContext) error {
Networks: config.Runner.Networks,
NetworkOpts: config.Runner.NetworkOpts,
NetrcCloneOnly: config.Netrc.CloneOnly,
DNS: config.Runner.DNS,
Volumes: config.Runner.Volumes,
Resources: compiler.Resources{
Memory: config.Resources.Memory,
Expand Down
10 changes: 10 additions & 0 deletions engine/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ type Compiler struct {
// the netrc file into the clone step.
NetrcCloneOnly bool

// DNS providers should set up a set of DNS to each pipeline container
DNS []string

// Volumes provides a set of volumes that should be
// mounted to each pipeline container.
Volumes map[string]string
Expand Down Expand Up @@ -538,6 +541,13 @@ func (c *Compiler) Compile(ctx context.Context, args runtime.CompilerArgs) runti
}
spec.Volumes = append(spec.Volumes, src)
}

// append global dns to the steps
if len(c.DNS) > 0 {
for _, step := range spec.Steps {
step.DNS = append(step.DNS, c.DNS...)
}
}
return spec
}

Expand Down
67 changes: 48 additions & 19 deletions engine/compiler/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,30 @@ func TestCompile_StepLabels(t *testing.T) {
// helper function parses and compiles the source file and then
// compares to a golden json file.
func testCompile(t *testing.T, source, golden string) *engine.Spec {
compiler := &Compiler{
Environ: provider.Static(nil),
Registry: registry.Static(nil),
Secret: secret.StaticVars(map[string]string{
"token": "3DA541559918A808C2402BBA5012F6C60B27661C",
"password": "password",
"my_username": "octocat",
}),
}
args := runtime.CompilerArgs{
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"},
Secret: secret.Static(nil),
}

return testCompileWithCompiler(t, source, golden, compiler, args)
}

// helper function parses and compiles the source file and then
// compares to a golden json file.
func testCompileWithCompiler(t *testing.T, source, golden string, compiler *Compiler, args runtime.CompilerArgs) *engine.Spec {
// replace the default random function with one that
// is deterministic, for testing purposes.
random = notRandom
Expand All @@ -258,25 +282,8 @@ func testCompile(t *testing.T, source, golden string) *engine.Spec {
return nil
}

compiler := &Compiler{
Environ: provider.Static(nil),
Registry: registry.Static(nil),
Secret: secret.StaticVars(map[string]string{
"token": "3DA541559918A808C2402BBA5012F6C60B27661C",
"password": "password",
"my_username": "octocat",
}),
}
args := runtime.CompilerArgs{
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),
}
args.Manifest = manifest
args.Pipeline = manifest.Resources[0].(*resource.Pipeline)

got := compiler.Compile(nocontext, args)

Expand Down Expand Up @@ -347,3 +354,25 @@ func TestIsPrivileged(t *testing.T) {
t.Errorf("Enable privileged mode for privileged image")
}
}

func TestDns(t *testing.T) {
compiler := &Compiler{
Environ: provider.Static(nil),
Registry: registry.Static(nil),
DNS: []string{"222.222.222.111"},
Secret: secret.StaticVars(map[string]string{
"token": "3DA541559918A808C2402BBA5012F6C60B27661C",
"password": "password",
"my_username": "octocat",
}),
}
args := runtime.CompilerArgs{
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"},
Secret: secret.Static(nil),
}
testCompileWithCompiler(t, "testdata/dns.yml", "testdata/dns.json", compiler, args)
}
93 changes: 93 additions & 0 deletions engine/compiler/testdata/dns.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"platform": {},
"steps": [
{
"id": "random",
"environment": {},
"image": "drone/git:latest",
"labels": {},
"name": "clone",
"run_policy": "always",
"pull": "if-not-exists",
"dns": [
"222.222.222.111"
],
"volumes": [
{
"name": "_workspace",
"path": "/drone/src"
}
],
"working_dir": "/drone/src"
},
{
"id": "random",
"args": [
"echo \"$DRONE_SCRIPT\" | /bin/sh"
],
"depends_on": [
"clone"
],
"entrypoint": [
"/bin/sh",
"-c"
],
"environment": {},
"labels": {},
"name": "build",
"image": "docker.io/library/golang:latest",
"dns": [
"1.2.3.4",
"5.6.7.8",
"222.222.222.111"
],
"volumes": [
{
"name": "_workspace",
"path": "/drone/src"
}
],
"working_dir": "/drone/src"
},
{
"id": "random",
"args": [
"echo \"$DRONE_SCRIPT\" | /bin/sh"
],
"depends_on": [
"build"
],
"entrypoint": [
"/bin/sh",
"-c"
],
"environment": {},
"labels": {},
"name": "test",
"image": "docker.io/library/golang:latest",
"dns": [
"222.222.222.111"
],
"volumes": [
{
"name": "_workspace",
"path": "/drone/src"
}
],
"working_dir": "/drone/src"
}
],
"volumes": [
{
"temp": {
"id": "random",
"name": "_workspace",
"labels": {}
}
}
],
"network": {
"id": "random",
"labels": {}
}
}
15 changes: 15 additions & 0 deletions engine/compiler/testdata/dns.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
kind: pipeline
type: docker
name: default

steps:
- name: build
image: golang
dns: [ 1.2.3.4, 5.6.7.8 ]
commands:
- go build

- name: test
image: golang
commands:
- go test