diff --git a/cloudbuild_tag.yaml b/cloudbuild_tag.yaml index 576f0c29..607ed824 100644 --- a/cloudbuild_tag.yaml +++ b/cloudbuild_tag.yaml @@ -24,11 +24,13 @@ steps: for GOARCH in 386 amd64; do # Build binary with the new tag and with 'latest' GOOS=$$GOOS GOARCH=$$GOARCH /builder/bin/go.bash build -o container-builder-local_$${GOOS}_$${GOARCH}-$TAG_NAME github.com/GoogleCloudPlatform/container-builder-local + GOOS=$$GOOS GOARCH=$$GOARCH /builder/bin/go.bash build -o cloud-build-local_$${GOOS}_$${GOARCH}-$TAG_NAME github.com/GoogleCloudPlatform/container-builder-local done done tar -czvf container-builder-local_latest.tar.gz container-builder-local_* + tar -czvf cloud-build-local_latest.tar.gz cloud-build-local_* artifacts: objects: - location: 'gs://container-builder-local/' - paths: ['container-builder-local_*'] + location: 'gs://local-builder/' + paths: ['container-builder-local_*', 'cloud-build-local_*'] diff --git a/integration_tests/run_tests_on_vm.sh b/integration_tests/run_tests_on_vm.sh index c47d4735..bc49f234 100755 --- a/integration_tests/run_tests_on_vm.sh +++ b/integration_tests/run_tests_on_vm.sh @@ -1,7 +1,7 @@ # Have new buckets for each test. DATE=`date +%Y%m%d-%H%M%S` -GCS_PATH=gs://container-builder-local-test/$DATE -GCS_LOGS_PATH=gs://container-builder-local-test-logs/$DATE +GCS_PATH=gs://local-builder-test/$DATE +GCS_LOGS_PATH=gs://local-builder-test-logs/$DATE gsutil -m copy container-builder-local $GCS_PATH/ gsutil -m copy ./integration_tests/* $GCS_PATH/ diff --git a/validate/validate.go b/validate/validate.go index abe9a886..a3ad2eab 100644 --- a/validate/validate.go +++ b/validate/validate.go @@ -123,7 +123,7 @@ func CheckBuild(b *pb.Build) error { return fmt.Errorf("invalid .steps field: %v", err) } - if missingSubs, err := CheckSubstitutionTemplate(b.Images, b.Tags, b.Steps, b.Substitutions); err != nil { + if missingSubs, err := CheckSubstitutionTemplate(b); err != nil { return err } else if len(missingSubs) > 0 { // If the user doesn't specifically allow loose substitutions, the warnings @@ -200,15 +200,15 @@ func CheckSubstitutionsLoose(substitutions map[string]string) error { } // CheckSubstitutionTemplate checks that all the substitution variables are used -// and all the variables found in the template are used too. It may returns an +// and all the variables found in the template are used too. It may return an // error and a list of string warnings. -func CheckSubstitutionTemplate(images, tags []string, steps []*pb.BuildStep, substitutions map[string]string) ([]string, error) { +func CheckSubstitutionTemplate(b *pb.Build) ([]string, error) { warnings := []string{} // substitutionsUsed is used to check that all the substitution variables // are used in the template. substitutionsUsed := make(map[string]bool) - for k := range substitutions { + for k := range b.Substitutions { substitutionsUsed[k] = false } @@ -218,9 +218,9 @@ func CheckSubstitutionTemplate(images, tags []string, steps []*pb.BuildStep, sub if p.Escape { continue } - if _, ok := substitutions[p.Key]; !ok { + if _, ok := b.Substitutions[p.Key]; !ok { if validUserSubstKeyRE.MatchString(p.Key) { - warnings = append(warnings, fmt.Sprintf("key in the template %q is not matched in the substitution data", p.Key)) + warnings = append(warnings, fmt.Sprintf("key in the template %q is not matched in the substitution data; substitutions = %+v", p.Key, b.Substitutions)) continue } if _, ok := validBuiltInSubstitutions[p.Key]; !ok { @@ -232,7 +232,7 @@ func CheckSubstitutionTemplate(images, tags []string, steps []*pb.BuildStep, sub return nil } - for _, step := range steps { + for _, step := range b.Steps { if err := checkParameters(step.Name); err != nil { return warnings, err } @@ -253,17 +253,29 @@ func CheckSubstitutionTemplate(images, tags []string, steps []*pb.BuildStep, sub return warnings, err } } - for _, img := range images { + for _, img := range b.Images { if err := checkParameters(img); err != nil { return warnings, err } } - for _, t := range tags { + for _, t := range b.Tags { if err := checkParameters(t); err != nil { return warnings, err } } + if b.Artifacts != nil && b.Artifacts.GetObjects() != nil { + objects := b.Artifacts.Objects + if err := checkParameters(objects.Location); err != nil { + return warnings, err + } + for _, p := range objects.Paths { + if err := checkParameters(p); err != nil { + return warnings, err + } + } + } + for k, v := range substitutionsUsed { if v == false { warnings = append(warnings, fmt.Sprintf("key %q in the substitution data is not matched in the template", k)) diff --git a/validate/validate_test.go b/validate/validate_test.go index a0208350..cd6ddf00 100644 --- a/validate/validate_test.go +++ b/validate/validate_test.go @@ -138,42 +138,67 @@ func TestCheckSubstitutionsLoose(t *testing.T) { func TestCheckSubstitutionTemplate(t *testing.T) { for _, c := range []struct { images, tags []string + build *pb.Build steps []*pb.BuildStep + artifacts *pb.Artifacts substitutions map[string]string wantErr bool wantWarnings int }{{ - steps: []*pb.BuildStep{{Name: "$_FOO"}}, - substitutions: map[string]string{ - "_FOO": "Bar", + build: &pb.Build{ + Steps: []*pb.BuildStep{{Name: "$_FOO"}}, + Substitutions: map[string]string{ + "_FOO": "Bar", + }, }, wantWarnings: 0, }, { - steps: []*pb.BuildStep{{Name: "$$FOO"}}, + build: &pb.Build{ + Steps: []*pb.BuildStep{{Name: "$$FOO"}}, + }, wantWarnings: 0, }, { - steps: []*pb.BuildStep{{Name: "$_FOO"}}, - substitutions: map[string]string{}, // missing substitution - wantWarnings: 1, + build: &pb.Build{ + Steps: []*pb.BuildStep{{Name: "$_FOO"}}, + Substitutions: map[string]string{}, // missing substitution + }, + wantWarnings: 1, }, { - steps: []*pb.BuildStep{{Name: "Baz"}}, // missing variable in template - substitutions: map[string]string{ - "_FOO": "Bar", + build: &pb.Build{ + Steps: []*pb.BuildStep{{Name: "Baz"}}, // missing variable in template + Substitutions: map[string]string{ + "_FOO": "Bar", + }, }, wantWarnings: 1, }, { - // missing variable in template and missing variable in map - steps: []*pb.BuildStep{{Name: "$_BAZ"}}, - substitutions: map[string]string{ - "_FOO": "Bar", + build: &pb.Build{ + // missing variable in template and missing variable in map + Steps: []*pb.BuildStep{{Name: "$_BAZ"}}, + Substitutions: map[string]string{ + "_FOO": "Bar", + }, }, wantWarnings: 2, }, { - steps: []*pb.BuildStep{{Name: "$FOO"}}, // invalid built-in substitution - substitutions: map[string]string{}, - wantErr: true, + build: &pb.Build{ + Steps: []*pb.BuildStep{{Name: "$FOO"}}, // invalid built-in substitution + Substitutions: map[string]string{}, + }, + wantErr: true, + }, { + build: &pb.Build{ + Artifacts: &pb.Artifacts{ + Objects: &pb.Artifacts_ArtifactObjects{ + Location: "gs://some-bucket/$_FOO", + Paths: []string{"$_FOO"}, + }}, + Substitutions: map[string]string{ + "_FOO": "Bar", + }, + }, }} { - warnings, err := CheckSubstitutionTemplate(c.images, c.tags, c.steps, c.substitutions) + warnings, err := CheckSubstitutionTemplate(c.build) if err == nil && c.wantErr { t.Errorf("CheckSubstitutionTemplate(%v,%v,%v) did not return error", c.images, c.steps, c.substitutions) } else if err != nil && !c.wantErr {