From 844ab611db45cb19f0ca65913a91746886daf628 Mon Sep 17 00:00:00 2001 From: Philippe Modard Date: Fri, 28 Jul 2017 04:34:56 -0400 Subject: [PATCH] Project import generated by Copybara. (#20) PiperOrigin-RevId: 162346017 --- README.md | 11 ++++++ integration_tests/gce_startup_script.sh | 5 +++ integration_tests/test_script.sh | 3 ++ localbuilder_main.go | 50 ++++++++++++------------- 4 files changed, 44 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 7c1aa52b..8190d7de 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,17 @@ and integration into local build and test workflows. ---- +## Using Local Builder + +### Prerequisites +- gcloud +- docker +- go (if you build the tool yourself) + +If you want to access private GCR during the local build (either pulling or +pushing an image), use the +[Docker credential helper for GCR users](https://github.com/GoogleCloudPlatform/docker-credential-gcr). + ## Developing Local Builder To build and develop Local Builder, you need a working [Go environment]. diff --git a/integration_tests/gce_startup_script.sh b/integration_tests/gce_startup_script.sh index 6db519cf..bb069037 100644 --- a/integration_tests/gce_startup_script.sh +++ b/integration_tests/gce_startup_script.sh @@ -29,8 +29,13 @@ function install_sdk() { # We use the public installer. rm -rf "$CLOUDSDK_INSTALL_DIR/google-cloud-sdk" curl https://sdk.cloud.google.com | bash || exit + + # Install needed components. + gcloud components install docker-credential-gcr --quiet || exit } install_sdk& +export PATH=$PATH:/usr/lib/google-cloud-sdk/bin + # add the install_sdk PID to the list for waiting. pids="$! $pids" diff --git a/integration_tests/test_script.sh b/integration_tests/test_script.sh index 11644cc7..5b4b604a 100755 --- a/integration_tests/test_script.sh +++ b/integration_tests/test_script.sh @@ -3,6 +3,9 @@ # Set project. gcloud config set project $PROJECT_ID +# Configure docker with gcr credentials. +docker-credential-gcr configure-docker || exit + # Flags tests. container-builder-local --version || exit container-builder-local --help || exit diff --git a/localbuilder_main.go b/localbuilder_main.go index c939f4a4..9e4a4dd7 100644 --- a/localbuilder_main.go +++ b/localbuilder_main.go @@ -187,33 +187,33 @@ func run(source string) error { } metadataUpdater.SetProjectInfo(projectInfo) - // Set initial Docker credentials. - tok, err := gcloud.AccessToken(r) - if err != nil { - return fmt.Errorf("Error getting access token to set docker credentials: %v", err) - } - if err := b.SetDockerAccessToken(tok); err != nil { - return fmt.Errorf("Error setting docker credentials: %v", err) - } - - // Write initial docker credentials for GCR. This writes the initial - // ~/.docker/config.json which is made available to build steps. - - go func() { - for ; ; time.Sleep(tokenRefreshDur) { - tok, err := gcloud.AccessToken(r) - if err != nil { - log.Printf("Error getting access token to update docker credentials: %v", err) - continue - } - if err := b.UpdateDockerAccessToken(tok); err != nil { - log.Printf("Error updating docker credentials: %v", err) - } - } - }() - go supplyTokenToMetadata(metadataUpdater, r) } + + // Set initial Docker credentials. + tok, err := gcloud.AccessToken(r) + if err != nil { + return fmt.Errorf("Error getting access token to set docker credentials: %v", err) + } + if err := b.SetDockerAccessToken(tok); err != nil { + return fmt.Errorf("Error setting docker credentials: %v", err) + } + + // Write initial docker credentials for GCR. This writes the initial + // ~/.docker/config.json which is made available to build steps. + + go func() { + for ; ; time.Sleep(tokenRefreshDur) { + tok, err := gcloud.AccessToken(r) + if err != nil { + log.Printf("Error getting access token to update docker credentials: %v", err) + continue + } + if err := b.UpdateDockerAccessToken(tok); err != nil { + log.Printf("Error updating docker credentials: %v", err) + } + } + }() } b.Start()