Skip to content

Commit

Permalink
Supporting --build-arg for docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
dinesh committed Mar 2, 2018
1 parent 8d96dc4 commit 1266ce7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cloud/aws/templates.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions cloud/aws/templates/app.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
},
"Environment": {
"ComputeType": "BUILD_GENERAL1_MEDIUM",
"Image": "aws/codebuild/docker:1.12.1",
"Image": "aws/codebuild/docker:17.09.0",
"Type": "LINUX_CONTAINER",
"EnvironmentVariables": [{
"Name": "IMAGE_REPO_NAME",
Expand Down Expand Up @@ -156,6 +156,12 @@
"Value": {
"Ref": "AppName"
}
},
{
"Name": "BUCKET",
"Value": {
"Ref": "BucketPrefix"
}
}
]
},
Expand All @@ -182,12 +188,14 @@
" pre_build:",
" commands:",
" - echo Logging into Amazon ECR...",
" - $(aws ecr get-login --region $REGION)",
" - $(aws ecr get-login --no-include-email --region $REGION)",
" build:",
" commands:",
" - echo Build started on `date`",
" - echo Building the Docker image",
" - docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .",
" - aws s3 cp s3://$BUCKET/.env docker.env && echo fetched env vars || touch docker.env",
" - echo `cat docker.env | awk '{print \"--build-arg \" $0}' ORS=' '`",
" - docker build `cat docker.env | awk '{print \"--build-arg \" $0}' ORS=' '` -t $IMAGE_REPO_NAME:$IMAGE_TAG .",
" - docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG",
" - echo ***** Build completed *****",
" post_build:",
Expand Down
12 changes: 10 additions & 2 deletions cloud/google/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ func (g *GCPCloud) BuildImport(id, filename string) error {
tag := fmt.Sprintf("gcr.io/$PROJECT_ID/%v:%v", app, id)
latestTag := fmt.Sprintf("gcr.io/$PROJECT_ID/%v:latest", app)

stepBuildArgs := []string{"build", "-t", tag, "-t", latestTag}
envVars, _ := g.EnvironmentGet(app)
for key, val := range envVars {
if val != "" {
stepBuildArgs = append(stepBuildArgs, fmt.Sprintf("--build-arg=%s=%s", key, val))
}
}

op, err := cb.Projects.Builds.Create(g.Project, &cloudbuild.Build{
LogsBucket: bucket,
Source: &cloudbuild.Source{
Expand All @@ -137,8 +145,8 @@ func (g *GCPCloud) BuildImport(id, filename string) error {
},
Steps: []*cloudbuild.BuildStep{
{
Name: "gcr.io/cloud-builders/docker:17.05",
Args: []string{"build", "-t", tag, "-t", latestTag, "."},
Name: "gcr.io/cloud-builders/docker:17.06.1",
Args: append(stepBuildArgs, "."),
},
},
Images: []string{tag},
Expand Down

0 comments on commit 1266ce7

Please sign in to comment.