Skip to content

Commit

Permalink
Add user and privileged to step (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehotinger authored Aug 8, 2018
1 parent dd6f228 commit 549cb48
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
4 changes: 2 additions & 2 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ func (b *Builder) runStep(ctx context.Context, step *graph.Step) error {
step.Run = replacePositionalContext(step.Run, ".")
}

args = b.getDockerRunArgs(volName, step.ID, workDir, step.Ports, true, step.Detach)
args = b.getDockerRunArgs(volName, workDir, step)
args = append(args, "docker")
args = append(args, strings.Fields(step.Run)...)
} else {
args = b.getDockerRunArgs(b.workspaceDir, step.ID, step.WorkDir, step.Ports, step.Rm, step.Detach)
args = b.getDockerRunArgs(b.workspaceDir, step.WorkDir, step)
for _, env := range step.Envs {
args = append(args, "--env", env)
}
Expand Down
22 changes: 14 additions & 8 deletions builder/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"regexp"
"strings"

"github.com/Azure/acr-builder/graph"
"github.com/Azure/acr-builder/util"

"github.com/Azure/acr-builder/baseimages/scanner/models"
Expand All @@ -26,27 +27,32 @@ var (
// getDockerRunArgs populates the args for running a Docker container.
func (b *Builder) getDockerRunArgs(
volName string,
stepID string,
stepWorkDir string,
ports []string,
rmContainer bool,
detach bool) []string {
step *graph.Step) []string {
args := []string{"docker", "run"}

if rmContainer {
if step.Rm {
args = append(args, "--rm")
}

if detach {
if step.Detach {
args = append(args, "--detach")
}

for _, port := range ports {
for _, port := range step.Ports {
args = append(args, "-p", port)
}

if step.Privileged {
args = append(args, "--privileged")
}

if step.User != "" {
args = append(args, "--user", step.User)
}

args = append(args,
"--name", stepID,
"--name", step.ID,
"--volume", volName+":"+containerWorkspaceDir,

// Mount home
Expand Down
2 changes: 2 additions & 0 deletions graph/dag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ func TestDagCreation_ValidFile(t *testing.T) {
Run: "azure/images/acr-builder build -f Dockerfile https://github.com/ehotinger/qaz --cache-from=ubuntu",
StepStatus: Skipped,
Timeout: defaultStepTimeoutInSeconds,
Privileged: true,
User: "root",
}

dict := make(map[string]*Step)
Expand Down
6 changes: 5 additions & 1 deletion graph/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type Step struct {
Rm bool `yaml:"rm"`
Detach bool `yaml:"detach"`
StartDelay int `yaml:"startDelay"`
Privileged bool `yaml:"privileged"`
User string `yaml:"user"`

StartTime time.Time
EndTime time.Time
Expand Down Expand Up @@ -95,7 +97,9 @@ func (s *Step) Equals(t *Step) bool {
s.StartDelay != t.StartDelay ||
s.StartTime != t.StartTime ||
s.EndTime != t.EndTime ||
s.StepStatus != t.StepStatus {
s.StepStatus != t.StepStatus ||
s.Privileged != t.Privileged ||
s.User != t.User {
return false
}

Expand Down
4 changes: 3 additions & 1 deletion graph/testdata/rally.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ steps:
secretEnvs: [someAkvSecretEnv]

- id: build-qaz
run: "azure/images/acr-builder build -f Dockerfile https://github.com/ehotinger/qaz --cache-from=ubuntu"
run: "azure/images/acr-builder build -f Dockerfile https://github.com/ehotinger/qaz --cache-from=ubuntu"
privileged: true
user: root

0 comments on commit 549cb48

Please sign in to comment.