Skip to content
This repository has been archived by the owner on Apr 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #71 from GoogleCloudPlatform/release
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
codrienne authored May 30, 2018
2 parents 6ac903c + 4a44a36 commit c7d311b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 31 deletions.
6 changes: 4 additions & 2 deletions cloudbuild_tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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_*']
4 changes: 2 additions & 2 deletions integration_tests/run_tests_on_vm.sh
Original file line number Diff line number Diff line change
@@ -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/

Expand Down
30 changes: 21 additions & 9 deletions validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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 {
Expand All @@ -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
}
Expand All @@ -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))
Expand Down
61 changes: 43 additions & 18 deletions validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c7d311b

Please sign in to comment.