Skip to content

Commit

Permalink
cmd/coordinator: don't snapshot in dev mode
Browse files Browse the repository at this point in the history
In dev mode, we have no GCS storage client, so attempting to write a
snapshot will panic.

For golang/go#48803

Change-Id: Id37264ebd765f914a55acf2fd18274020850331f
Reviewed-on: https://go-review.googlesource.com/c/build/+/353909
Trust: Michael Pratt <[email protected]>
Run-TryBot: Michael Pratt <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
  • Loading branch information
prattmic committed Oct 6, 2021
1 parent 1409edd commit 8630382
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cmd/coordinator/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2557,6 +2557,10 @@ func (st *buildStatus) doSnapshot(bc *buildlet.Client) error {
if st.conf.SkipSnapshot {
return nil
}
if pool.NewGCEConfiguration().BuildEnv().SnapBucket == "" {
// Build environment isn't configured to do snapshots.
return nil
}
if err := st.cleanForSnapshot(bc); err != nil {
return fmt.Errorf("cleanForSnapshot: %v", err)
}
Expand Down Expand Up @@ -2624,7 +2628,15 @@ func (st *buildStatus) writeSnapshot(bc *buildlet.Client) (err error) {
}
defer tgz.Close()

wr := pool.NewGCEConfiguration().StorageClient().Bucket(pool.NewGCEConfiguration().BuildEnv().SnapBucket).Object(st.SnapshotObjectName()).NewWriter(ctx)
sc := pool.NewGCEConfiguration().StorageClient()
if sc == nil {
return errors.New("GCE configuration missing storage client")
}
bucket := pool.NewGCEConfiguration().BuildEnv().SnapBucket
if bucket == "" {
return errors.New("build environment missing snapshot bucket")
}
wr := sc.Bucket(bucket).Object(st.SnapshotObjectName()).NewWriter(ctx)
wr.ContentType = "application/octet-stream"
wr.ACL = append(wr.ACL, storage.ACLRule{Entity: storage.AllUsers, Role: storage.RoleReader})
if _, err := io.Copy(wr, tgz); err != nil {
Expand Down

0 comments on commit 8630382

Please sign in to comment.