From 10beb3920debb0be135ae6cecee2ca55fbc43169 Mon Sep 17 00:00:00 2001 From: Jonathan Boulle Date: Thu, 12 Feb 2015 12:35:43 -0800 Subject: [PATCH] build: allow setting of stage1 image path This introduces the ability to set the default stage1 image path for `rkt run` by setting the environment variable RKT_STAGE1_IMAGE at build time (i.e when invoking ./build). The variable should be set to the fully qualified path at which rkt can find the stage1 image - for example: RKT_STAGE1_IMAGE=/usr/lib/rkt/stage1.aci ./build Rocket will use this environment variable to set the default value for the stage1-image flag. If the value is _not_ set, it will continue to use the heuristic it does today to guess the location of the stage1 image, by looking for a file called stage1.aci that is in the same directory as rkt itself. --- build | 4 +++- rkt/run.go | 15 +++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/build b/build index 472f6e6..3bd178a 100755 --- a/build +++ b/build @@ -14,7 +14,9 @@ export GOPATH=${PWD}/gopath eval $(go env) echo "Building rkt (stage0)..." -go build -o $GOBIN/rkt ${REPO_PATH}/rkt +go build -o ${GOBIN}/rkt \ + ${RKT_STAGE1_IMAGE:+-ldflags "-X main.defaultStage1Image '${RKT_STAGE1_IMAGE}'"} \ + ${REPO_PATH}/rkt if [[ "$OSTYPE" == "linux-gnu" ]]; then echo "Building network plugins..." diff --git a/rkt/run.go b/rkt/run.go index 8fbf9fc..fb9bb0d 100644 --- a/rkt/run.go +++ b/rkt/run.go @@ -31,6 +31,8 @@ import ( ) var ( + defaultStage1Image string // either set by linker, or guessed in init() + flagStage1Image string flagVolumes volumeList flagPrivateNet bool @@ -48,14 +50,15 @@ They will be checked in that order and the first match will be used.`, func init() { commands = append(commands, cmdRun) - // try discover the directory rkt is running from, assume the default stage1.aci is stored alongside it. - defaultStage1Image := "" - exePath, err := os.Readlink("/proc/self/exe") - if err == nil { - defaultStage1Image = filepath.Join(filepath.Dir(exePath), "stage1.aci") + // if not set by linker, try discover the directory rkt is running + // from, and assume the default stage1.aci is stored alongside it. + if defaultStage1Image == "" { + if exePath, err := os.Readlink("/proc/self/exe"); err == nil { + defaultStage1Image = filepath.Join(filepath.Dir(exePath), "stage1.aci") + } } - cmdRun.Flags.StringVar(&flagStage1Image, "stage1-image", defaultStage1Image, `image to use as stage1. Local paths and http/https URLs are supported. By default, Rocket will look for a file called "stage1.aci" in the same directory as rkt itself`) + cmdRun.Flags.StringVar(&flagStage1Image, "stage1-image", defaultStage1Image, `image to use as stage1. Local paths and http/https URLs are supported. If empty, Rocket will look for a file called "stage1.aci" in the same directory as rkt itself`) cmdRun.Flags.Var(&flagVolumes, "volume", "volumes to mount into the shared container environment") cmdRun.Flags.BoolVar(&flagPrivateNet, "private-net", false, "give container a private network") cmdRun.Flags.BoolVar(&flagSpawnMetadataSvc, "spawn-metadata-svc", false, "launch metadata svc if not running")