Skip to content

Commit de717b4

Browse files
committed
Optionally set defaults file when minting images.
We want to ensure that static defaults are set when images run within particular environments, e.g., a particular GCE project. This occurs when there exists a file in `/etc/defaults/cuttlefish-integration` and contains `static_defaults_when=<condition>` (see #1859). We thus need to ensure that the `cuttlefish-integration` file is set appropriately; we just do this by uploading the file when minting the image.
1 parent 9de827e commit de717b4

File tree

1 file changed

+23
-7
lines changed
  • tools/baseimage/cmd/gce_install_cuttlefish_packages

1 file changed

+23
-7
lines changed

tools/baseimage/cmd/gce_install_cuttlefish_packages/main.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ import (
2929
)
3030

3131
const (
32-
outImageName = "amended-image"
33-
mountpoint = "/mnt/image"
32+
outImageName = "amended-image"
33+
mountpoint = "/mnt/image"
34+
defaultsCuttlefishIntegrationFile = "/etc/defaults/cuttlefish-integration"
3435
)
3536

3637
type DebSrcsFlag struct {
@@ -53,11 +54,12 @@ func (v *DebSrcsFlag) Set(s string) error {
5354
}
5455

5556
var (
56-
project = flag.String("project", "", "GCP project whose resources will be used for creating the amended image")
57-
zone = flag.String("zone", "us-central1-a", "GCP zone used for creating relevant resources")
58-
source_image_project = flag.String("source-image-project", "", "Source image GCP project")
59-
source_image = flag.String("source-image", "", "Source image name")
60-
deb_srcs = DebSrcsFlag{}
57+
project = flag.String("project", "", "GCP project whose resources will be used for creating the amended image")
58+
zone = flag.String("zone", "us-central1-a", "GCP zone used for creating relevant resources")
59+
source_image_project = flag.String("source-image-project", "", "Source image GCP project")
60+
source_image = flag.String("source-image", "", "Source image name")
61+
deb_srcs = DebSrcsFlag{}
62+
defaults_cuttlefish_integration_src = flag.String("defaults_cuttlefish_integration_src", "", "Path to file which will be written to /etc/defaults/cuttlefish-integration.")
6163
)
6264

6365
func init() {
@@ -111,6 +113,16 @@ func installCuttlefishDebs(project, zone, insName string, debSrcs []string) erro
111113
return nil
112114
}
113115

116+
func maybeSetDefaultsCuttlefishIntegrationFile(project, zone, insName string) error {
117+
if *defaults_cuttlefish_integration_src != "" {
118+
// The disk mountpoint is at /mnt/image, mounted in `installCuttlefishDebs`, and is not unmounted.
119+
if err := gce.UploadFile(project, zone, insName, *defaults_cuttlefish_integration_src, mountpoint+defaultsCuttlefishIntegrationFile); err != nil {
120+
return err
121+
}
122+
}
123+
return nil
124+
}
125+
114126
func cleanupDeleteDisk(h *gce.GceHelper, disk string) {
115127
log.Printf("cleanup: deleting disk %q...", disk)
116128
if err := h.DeleteDisk(disk); err != nil {
@@ -191,6 +203,10 @@ func amendImageMain(project, zone string, opts amendImageOpts) error {
191203
return fmt.Errorf("install cuttlefish debs error: %v", err)
192204
}
193205

206+
if err := maybeSetDefaultsCuttlefishIntegrationFile(project, zone, insName); err != nil {
207+
return fmt.Errorf("couldn't set %s: %v", defaultsCuttlefishIntegrationFile, err)
208+
}
209+
194210
// Reboot the instance to force a clean umount of the attached disk's file system.
195211
if err := gce.RunCmd(project, zone, insName, "sudo reboot"); err != nil {
196212
return err

0 commit comments

Comments
 (0)