in container/go/cmd/create_image_config/create_image_config.go [56:131]
func main() {
flag.Var(&labelsArray, "labels", "Augment the Label of the previous layer.")
flag.Var(&ports, "ports", "Augment the ExposedPorts of the previous layer.")
flag.Var(&volumes, "volumes", "Augment the Volumes of the previous layer.")
flag.Var(&entrypointPrefix, "entrypointPrefix", "Prefix the Entrypoint with the specified arguments.")
flag.Var(&env, "env", "Augment the Env of the previous layer.")
flag.Var(&command, "command", "Override the Cmd of the previous layer.")
flag.Var(&entrypoint, "entrypoint", "Override the Entrypoint of the previous layer.")
flag.Var(&layerDigestFile, "layerDigestFile", "Layer sha256 hashes that make up this image. The order that these layers are specified matters.")
flag.Var(&stampInfoFile, "stampInfoFile", "A list of files from which to read substitutions to make in the provided fields.")
flag.Parse()
if *outputConfig == "" {
log.Fatalln("Required option -outputConfig was not specified.")
}
configFile := &v1.ConfigFile{}
if *baseConfig != "" {
configBlob, err := ioutil.ReadFile(*baseConfig)
if err != nil {
log.Fatalf("Failed to read the base image's config file: %v", err)
}
configFile, err = v1.ParseConfigFile(bytes.NewReader(configBlob))
if err != nil {
log.Fatalf("Failed to successfully parse config file json contents: %v", err)
}
}
stamper, err := compat.NewStamper(stampInfoFile)
if err != nil {
log.Fatalf("Failed to initialize the stamper: %v", err)
}
opts := compat.OverrideConfigOpts{
ConfigFile: configFile,
OutputConfig: *outputConfig,
CreationTimeString: *creationTimeString,
User: *user,
Workdir: *workdir,
NullEntryPoint: *nullEntryPoint,
NullCmd: *nullCmd,
Architecture: *architecture,
OperatingSystem: *operatingSystem,
OSVersion: *osVersion,
CreatedBy: "bazel build ...",
Author: "Bazel",
LabelsArray: labelsArray,
Ports: ports,
Volumes: volumes,
EntrypointPrefix: entrypointPrefix,
Env: env,
Command: command,
Entrypoint: entrypoint,
Layer: layerDigestFile,
Stamper: stamper,
}
// write out the updated config after overriding config content.
if err := compat.OverrideImageConfig(&opts); err != nil {
log.Fatalf("Failed to override values in old image config and write to dst %s: %v", err, *outputConfig)
}
manifestBlob := []byte("{}")
if *baseManifest != "" {
var err error
manifestBlob, err = ioutil.ReadFile(*baseManifest)
if err != nil {
log.Fatalf("Failed to read manifest file from %s: %v", *baseManifest, err)
}
}
if err := ioutil.WriteFile(*outputManifest, manifestBlob, os.ModePerm); err != nil {
log.Fatalf("Writing manifest to %s was unsuccessful: %v", *outputManifest, err)
}
}