Skip to content

Commit 40d5094

Browse files
authored
Merge pull request GoogleCloudPlatform#31 from GoogleCloudPlatform/release
Project import generated by Copybara.
2 parents cffd332 + b0fe571 commit 40d5094

File tree

6 files changed

+77
-31
lines changed

6 files changed

+77
-31
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ gcloud config set project my-project
2525
```
2626
gcloud components install container-builder-local
2727
```
28+
After successful installation, you will have ``container-builder-local`` setup
29+
on your PATH (as part of the Google Cloud SDK binaries), so you will be able to
30+
run it with:
31+
32+
```
33+
$ container-builder-local
34+
```
2835

2936
## Download the latest binaries
3037

integration_tests/test_script.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ container-builder-local --config=cloudbuild_nil.yaml . || exit # happy dryrun ca
1616

1717
# End to end tests.
1818
container-builder-local --config=cloudbuild_nil.yaml --dryrun=false . || exit
19+
container-builder-local --config=cloudbuild_nil.yaml --dryrun=false --no-source=true || exit
20+
container-builder-local --config=cloudbuild_nil.yaml --dryrun=false --no-source=true . && exit
1921
container-builder-local --config=cloudbuild_dockerfile.yaml --dryrun=false . || exit
2022
container-builder-local --config=cloudbuild_gcr.yaml --dryrun=false --push=true . || exit
2123
container-builder-local --config=cloudbuild_big.yaml --dryrun=false --push=true . || exit

localbuilder_main.go

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242

4343
const (
4444
volumeNamePrefix = "cloudbuild_vol_"
45-
gcbDockerVersion = "17.05-ce"
45+
gcbDockerVersion = "17.06.1-ce"
4646
metadataImageName = "gcr.io/cloud-builders/metadata"
4747
)
4848

@@ -51,6 +51,7 @@ var (
5151
substitutions = flag.String("substitutions", "", `substitutions key=value pairs separated by comma; for example _FOO=bar,_BAZ=baz`)
5252
dryRun = flag.Bool("dryrun", true, "If true, nothing will be run")
5353
push = flag.Bool("push", false, "If true, the images will be pushed")
54+
noSource = flag.Bool("no-source", false, "Specify that no source should be used for this build.")
5455
help = flag.Bool("help", false, "If true, print the help message")
5556
versionFlag = flag.Bool("version", false, "If true, print the local builder version")
5657
)
@@ -72,12 +73,25 @@ func main() {
7273
return
7374
}
7475

75-
if len(args) == 0 {
76+
nbSource := 1
77+
if *noSource {
78+
nbSource = 0
79+
}
80+
81+
if len(args) < nbSource {
7682
exitUsage("Specify a source")
77-
} else if len(args) > 1 {
78-
exitUsage("There should be only one positional argument. Pass all the flags before the source.")
83+
} else if len(args) > nbSource {
84+
if nbSource == 1 {
85+
exitUsage("There should be only one positional argument. Pass all the flags before the source.")
86+
} else {
87+
exitUsage("no-source flag can't be used along with source.")
88+
}
89+
}
90+
source := ""
91+
if nbSource == 1 {
92+
source = args[0]
7993
}
80-
source := args[0]
94+
8195
if *configFile == "" {
8296
exitUsage("Specify a config file")
8397
}
@@ -160,14 +174,16 @@ func run(source string) error {
160174
if err := vol.Setup(); err != nil {
161175
return fmt.Errorf("Error creating docker volume: %v", err)
162176
}
163-
// If the source is a directory, only copy the inner content.
164-
if isDir, err := isDirectory(source); err != nil {
165-
return fmt.Errorf("Error getting directory: %v", err)
166-
} else if isDir {
167-
source = filepath.Clean(source) + "/."
168-
}
169-
if err := vol.Copy(source); err != nil {
170-
return fmt.Errorf("Error copying source to docker volume: %v", err)
177+
if source != "" {
178+
// If the source is a directory, only copy the inner content.
179+
if isDir, err := isDirectory(source); err != nil {
180+
return fmt.Errorf("Error getting directory: %v", err)
181+
} else if isDir {
182+
source = filepath.Clean(source) + "/."
183+
}
184+
if err := vol.Copy(source); err != nil {
185+
return fmt.Errorf("Error copying source to docker volume: %v", err)
186+
}
171187
}
172188
defer vol.Close()
173189
}

metadata/metadata.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ func (r RealUpdater) SetProjectInfo(b ProjectInfo) error {
178178
// The container listens on local port 8082, which is where RealUpdater POSTs
179179
// to.
180180
func StartLocalServer(r runner.Runner, metadataImage string) error {
181+
// Unlike the hosted container builder service, the user's local machine is
182+
// not guaranteed to have the latest version, so we explicitly pull it.
183+
if err := r.Run([]string{"docker", "pull", metadataImage}, nil, os.Stdout, os.Stderr, ""); err != nil {
184+
return err
185+
}
181186
return startServer(r, metadataImage, false, fixedMetadataIP, metadataLocalSubnet)
182187
}
183188

validate/validate.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const (
4545
maxNumSubstitutions = 100 // max number of user-defined substitutions.
4646
maxSubstKeyLength = 100 // max length of a substitution key.
4747
maxSubstValueLength = 4000 // max length of a substitution value.
48+
maxNumSecretEnvs = 100 // max number of unique secret env values.
4849

4950
// Name of the permission required to use a key to decrypt data.
5051
// Documented at https://cloud.google.com/kms/docs/reference/permissions-and-roles
@@ -396,8 +397,8 @@ func checkSecrets(b *cb.Build) error {
396397
return fmt.Errorf("secretEnv %q is defined without being used", defined)
397398
}
398399
}
399-
if len(definedSecretEnvs) > 10 {
400-
return errors.New("build defines more than ten secret values")
400+
if len(definedSecretEnvs) > maxNumSecretEnvs {
401+
return fmt.Errorf("build defines more than %d secret values", maxNumSecretEnvs)
401402
}
402403

403404
// Check secret_env max size.

validate/validate_test.go

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package validate
1616

1717
import (
1818
"errors"
19+
"fmt"
1920
"math/rand"
2021
"strings"
2122
"testing"
@@ -622,6 +623,21 @@ func makeTestBuild(buildID string) *cb.Build {
622623
}
623624

624625
func TestCheckSecrets(t *testing.T) {
626+
makeSecretEnvs := func(n int) []string {
627+
var s []string
628+
for i := 0; i < n; i++ {
629+
s = append(s, fmt.Sprintf("MY_SECRET_%d", i))
630+
}
631+
return s
632+
}
633+
makeSecrets := func(n int) map[string][]byte {
634+
m := map[string][]byte{}
635+
for i := 0; i < n; i++ {
636+
m[fmt.Sprintf("MY_SECRET_%d", i)] = []byte("hunter2")
637+
}
638+
return m
639+
}
640+
625641
for _, c := range []struct {
626642
desc string
627643
b *cb.Build
@@ -730,29 +746,28 @@ func TestCheckSecrets(t *testing.T) {
730746
},
731747
wantErr: errors.New(`secretEnv value for "MY_SECRET" cannot exceed 1KB`),
732748
}, {
733-
desc: "Build with >10 secret values",
749+
desc: "Happy case: Build with acceptable secret values",
734750
b: &cb.Build{
735751
Steps: []*cb.BuildStep{{
736-
SecretEnv: []string{"MY_SECRET_1", "MY_SECRET_2", "MY_SECRET_3", "MY_SECRET_4", "MY_SECRET_5", "MY_SECRET_6", "MY_SECRET_7", "MY_SECRET_8", "MY_SECRET_9", "MY_SECRET_10", "MY_SECRET_11"},
752+
SecretEnv: makeSecretEnvs(maxNumSecretEnvs),
737753
}},
738754
Secrets: []*cb.Secret{{
739755
KmsKeyName: kmsKeyName,
740-
SecretEnv: map[string][]byte{
741-
"MY_SECRET_1": []byte("hunter1"),
742-
"MY_SECRET_2": []byte("hunter1"),
743-
"MY_SECRET_3": []byte("hunter1"),
744-
"MY_SECRET_4": []byte("hunter1"),
745-
"MY_SECRET_5": []byte("hunter1"),
746-
"MY_SECRET_6": []byte("hunter1"),
747-
"MY_SECRET_7": []byte("hunter1"),
748-
"MY_SECRET_8": []byte("hunter1"),
749-
"MY_SECRET_9": []byte("hunter1"),
750-
"MY_SECRET_10": []byte("hunter1"),
751-
"MY_SECRET_11": []byte("hunter1"),
752-
},
756+
SecretEnv: makeSecrets(maxNumSecretEnvs),
757+
}},
758+
},
759+
}, {
760+
desc: "Build with too many secret values",
761+
b: &cb.Build{
762+
Steps: []*cb.BuildStep{{
763+
SecretEnv: makeSecretEnvs(maxNumSecretEnvs + 1),
764+
}},
765+
Secrets: []*cb.Secret{{
766+
KmsKeyName: kmsKeyName,
767+
SecretEnv: makeSecrets(maxNumSecretEnvs + 1),
753768
}},
754769
},
755-
wantErr: errors.New("build defines more than ten secret values"),
770+
wantErr: errors.New("build defines more than 100 secret values"),
756771
}, {
757772
desc: "Step has env and secret_env collision",
758773
b: &cb.Build{

0 commit comments

Comments
 (0)