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

Commit

Permalink
Release (#24)
Browse files Browse the repository at this point in the history
* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017
  • Loading branch information
Philmod authored Aug 10, 2017
1 parent 3ef6136 commit 3675404
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 19 deletions.
6 changes: 4 additions & 2 deletions cloudbuild_tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ steps:
# Set TAG_NAME as version.
- name: 'ubuntu'
args: ['sed', '-i', 's/HEAD/$TAG_NAME/g', 'version.go']
# Create binaries.
# Create binaries for each pair of OS/Arch.
# Create an archive with the latest binaries; that enables a single download url.
- name: 'gcr.io/cloud-builders/go:wheezy'
entrypoint: 'bash'
args:
- '-c'
- |
for GOOS in darwin linux windows; do
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
done
done
# Copy binaries to GCS.
tar -czvf container-builder-local_latest.tar.gz container-builder-local_*
- name: 'gcr.io/cloud-builders/gsutil'
args: ['-m', 'cp', 'container-builder-local_*', 'gs://container-builder-local/']
4 changes: 2 additions & 2 deletions integration_tests/cloudbuild_dockerfile.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/argo-local-builder/test', '.']
args: ['build', '-t', 'gcr.io/$PROJECT_ID/test', '.']

images: ['gcr.io/argo-local-builder/test']
images: ['gcr.io/$PROJECT_ID/test']
8 changes: 4 additions & 4 deletions integration_tests/cloudbuild_gcr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['pull', 'gcr.io/argo-local-builder/test']
args: ['pull', 'gcr.io/$PROJECT_ID/test']
- name: 'gcr.io/cloud-builders/docker'
args:
- 'build'
- '--cache-from'
- 'gcr.io/argo-local-builder/test'
- 'gcr.io/$PROJECT_ID/test'
- '-t'
- 'gcr.io/argo-local-builder/test'
- 'gcr.io/$PROJECT_ID/test'
- '.'

images: ['gcr.io/argo-local-builder/test']
images: ['gcr.io/$PROJECT_ID/test']
33 changes: 26 additions & 7 deletions localbuilder_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const (
)

var (
configFile = flag.String("config", "cloudconfig.yaml", "cloud build config file path")
configFile = flag.String("config", "cloudbuild.yaml", "cloud build config file path")
substitutions = flag.String("substitutions", "", `substitutions key=value pairs separated by comma; for example _FOO=bar,_BAZ=argo`)
dryRun = flag.Bool("dryrun", true, "If true, nothing will be run")
push = flag.Bool("push", false, "If true, the images will be pushed")
Expand Down Expand Up @@ -98,6 +98,11 @@ func run(source string) error {
DryRun: *dryRun,
}

// Channel to tell goroutines to stop.
// Do not defer the close() because we want this stop to happen before other
// defer functions.
stopchan := make(chan struct{})

// Clean leftovers from a previous build.
if err := common.Clean(r); err != nil {
return fmt.Errorf("Error cleaning: %v", err)
Expand Down Expand Up @@ -191,7 +196,7 @@ func run(source string) error {
// Feed the project info to the metadata server.
metadataUpdater.SetProjectInfo(projectInfo)

go supplyTokenToMetadata(metadataUpdater, r)
go supplyTokenToMetadata(metadataUpdater, r, stopchan)
}

// Set initial Docker credentials.
Expand All @@ -206,8 +211,8 @@ func run(source string) error {
// 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) {
go func(stopchan <-chan struct{}) {
for {
tok, err := gcloud.AccessToken(r)
if err != nil {
log.Printf("Error getting access token to update docker credentials: %v", err)
Expand All @@ -216,13 +221,21 @@ func run(source string) error {
if err := b.UpdateDockerAccessToken(tok); err != nil {
log.Printf("Error updating docker credentials: %v", err)
}
select {
case <-time.After(tokenRefreshDur):
continue
case <-stopchan:
return
}
}
}()
}(stopchan)
}

b.Start()
<-b.Done

close(stopchan)

if b.Summary().Status == build.StatusError {
return fmt.Errorf("Build finished with ERROR status")
}
Expand All @@ -234,8 +247,8 @@ func run(source string) error {
}

// supplyTokenToMetadata gets gcloud token and supply it to the metadata server.
func supplyTokenToMetadata(metadataUpdater metadata.RealUpdater, r runner.Runner) {
for ; ; time.Sleep(tokenRefreshDur) {
func supplyTokenToMetadata(metadataUpdater metadata.RealUpdater, r runner.Runner, stopchan <-chan struct{}) {
for {
accessToken, err := gcloud.AccessToken(r)
if err != nil {
log.Printf("Error getting gcloud token: %v", err)
Expand All @@ -251,6 +264,12 @@ func supplyTokenToMetadata(metadataUpdater metadata.RealUpdater, r runner.Runner
log.Printf("Error updating token in metadata server: %v", err)
continue
}
select {
case <-time.After(tokenRefreshDur):
continue
case <-stopchan:
return
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func StartCloudServer(r runner.Runner, metadataImage string) error {
// builds.
func CreateCloudbuildNetwork(r runner.Runner, subnet string) error {
cmd := []string{"docker", "network", "create", "cloudbuild", "--subnet=" + subnet}
return r.Run(cmd, nil, os.Stdout, os.Stderr, "")
return r.Run(cmd, nil, nil, os.Stderr, "")
}

func startServer(r runner.Runner, metadataImage string, iptables bool, ip, subnet string) error {
Expand All @@ -220,14 +220,12 @@ func startServer(r runner.Runner, metadataImage string, iptables bool, ip, subne
} else {
cmd = []string{"docker", "run", "-d", "--name=metadata", metadataImage}
}
log.Println(cmd)
if err := r.Run(cmd, nil, nil, os.Stderr, ""); err != nil {
return err
}

// Redirect requests to metadata.google.internal and the fixed metadata IP to the metadata container.
cmd = []string{"docker", "network", "connect", "--alias=metadata", "--alias=metadata.google.internal", "--ip=" + ip, "cloudbuild", "metadata"}
log.Println(cmd)
if err := r.Run(cmd, nil, nil, os.Stderr, ""); err != nil {
return fmt.Errorf("Error connecting metadata to network: %v", err)
}
Expand All @@ -243,7 +241,6 @@ func startServer(r runner.Runner, metadataImage string, iptables bool, ip, subne
"-j", "DNAT", // This rule does destination NATting,
"--to-destination", metadataHostedIP, // to our spoofed metadata container.
}
log.Println(cmd)
if err := r.Run(cmd, nil, os.Stdout, os.Stderr, ""); err != nil {
return fmt.Errorf("Error updating iptables: %v", err)
}
Expand Down

0 comments on commit 3675404

Please sign in to comment.