diff --git a/contrib/rootfs-builder/.gitignore b/contrib/rootfs-builder/.gitignore new file mode 100644 index 00000000..10d00b57 --- /dev/null +++ b/contrib/rootfs-builder/.gitignore @@ -0,0 +1 @@ +*.gz diff --git a/contrib/rootfs-builder/Makefile b/contrib/rootfs-builder/Makefile index 296b0fca..ca8042a9 100644 --- a/contrib/rootfs-builder/Makefile +++ b/contrib/rootfs-builder/Makefile @@ -1,26 +1,32 @@ -rootfs.tar.gz: rootfs/bin/echo - tar -czf $@ -C rootfs . +ARCHES ?= amd64 -rootfs/bin/busybox: downloads/stage3-amd64-current.tar.bz2 rootfs-files +all: $(ARCHES:%=rootfs-%.tar.gz) + +rootfs-%.tar.gz: rootfs/%/bin/echo + tar -czf $@ -C rootfs/$* . + +.PRECIOUS: rootfs/%/bin/busybox +rootfs/%/bin/busybox: downloads/stage3-%-current.tar.bz2 rootfs-files gpg --verify $<.DIGESTS.asc (cd downloads && \ - grep -A1 '^# SHA512 HASH' stage3-amd64-current.tar.bz2.DIGESTS.asc | \ + grep -A1 '^# SHA512 HASH' stage3-$*-current.tar.bz2.DIGESTS.asc | \ grep -v '^--' | \ sha512sum -c) - sudo rm -rf rootfs - sudo mkdir rootfs - sudo tar -xvf downloads/stage3-amd64-current.tar.bz2 -C rootfs \ + sudo rm -rf rootfs/$* + sudo mkdir -p rootfs/$* + sudo tar -xvf downloads/stage3-$*-current.tar.bz2 -C rootfs/$* \ --no-recursion --wildcards $$(< rootfs-files) sudo touch $@ -rootfs/bin/echo: rootfs/bin/busybox - sudo sh -c 'for COMMAND in $$($< --list); do \ - ln -rs $< "rootfs/bin/$${COMMAND}"; \ +.PRECIOUS: rootfs/%/bin/echo +rootfs/%/bin/echo: rootfs/%/bin/busybox + sudo sh -c 'COMMANDS=$$($< --list) || exit 1; for COMMAND in $${COMMANDS}; do \ + test -L "rootfs/$*/bin/$${COMMAND}" || ln -rs $< "rootfs/$*/bin/$${COMMAND}" || exit; \ done' -downloads/stage3-amd64-current.tar.bz2: get-stage3.sh - ./$< - touch downloads/stage3-amd64-*.tar.bz2 +downloads/stage3-%-current.tar.bz2: get-stage3.sh + STAGE3_ARCH=$* ./$< + touch downloads/stage3-$*-*.tar.bz2 clean: rm -f downloads/* diff --git a/contrib/rootfs-builder/README.md b/contrib/rootfs-builder/README.md index cb5efd24..28809ffd 100644 --- a/contrib/rootfs-builder/README.md +++ b/contrib/rootfs-builder/README.md @@ -1,21 +1,43 @@ -Building `rootfs.tar.gz` ------------------------- +# Building `rootfs-*.tar.gz` -The root filesystem tarball is based on [Gentoo][]'s [amd64 -stage3][stage3-amd64] (which we check for a valid [GnuPG +The root filesystem tarball is based on [Gentoo][]'s stage3s (e.g. the +[amd64 stage3][stage3-amd64]). We check for a valid [GnuPG signature][gentoo-signatures]), copying a [minimal subset](rootfs-files) to the root filesytem, and adding symlinks for -all BusyBox commands. To rebuild the tarball based on a newer stage3, -just run: +all BusyBox commands. To rebuild the tarball based on a newer stage3, +run: ``` $ touch get-stage3.sh -$ make rootfs.tar.gz +$ make rootfs-amd64.tar.gz ``` -### Getting Gentoo's Release Engineering public key +## Platform tarballs -If `make rootfs.tar.gz` gives an error like: +The extraction requires a local machine capable of executing the +extracted BusyBox. Extraction assumes amd64, but if your local +machine is a different platform, set `ARCHES`. For example: + +``` +$ make ARCHES='i486 i686 amd64' +``` + +The architecture identifiers can be found by browsing Gentoo's +[releases][] for `autobuilds/latest-stage3-{arch}.txt`. Examples +include: + +* `amd64` (the default) +* `arm64` +* `arm7a` +* `i486` +* `i686` +* `ppc64-64ul` + +and many more. + +## Getting Gentoo's Release Engineering public key + +If `make rootfs-….tar.gz` gives an error like: ``` gpg --verify downloads/stage3-amd64-current.tar.bz2.DIGESTS.asc @@ -32,6 +54,7 @@ $ gpg --keyserver pool.sks-keyservers.net --recv-keys 2D182910 ``` [Gentoo]: https://www.gentoo.org/ -[stage3-amd64]: http://distfiles.gentoo.org/releases/amd64/autobuilds/ [gentoo-signatures]: https://www.gentoo.org/downloads/signatures/ [recv-keys]: https://www.gnupg.org/documentation/manuals/gnupg/Operational-GPG-Commands.html +[releases]: http://distfiles.gentoo.org/releases/ +[stage3-amd64]: http://distfiles.gentoo.org/releases/amd64/autobuilds/ diff --git a/contrib/rootfs-builder/get-stage3.sh b/contrib/rootfs-builder/get-stage3.sh index dfd68166..6828f017 100755 --- a/contrib/rootfs-builder/get-stage3.sh +++ b/contrib/rootfs-builder/get-stage3.sh @@ -17,11 +17,31 @@ # limitations under the License. MIRROR="${MIRROR:-http://distfiles.gentoo.org/}" -BASE_ARCH_URL="${BASE_ARCH_URL:-${MIRROR}releases/amd64/autobuilds/}" +STAGE3_ARCH="${STAGE3_ARCH:-amd64}" + +if test -z "${BASE_ARCH}" +then + case "${STAGE3_ARCH}" in + arm*) + BASE_ARCH=arm + ;; + i[46]86) + BASE_ARCH=x86 + ;; + ppc*) + BASE_ARCH=ppc + ;; + *) + BASE_ARCH="${STAGE3_ARCH}" + ;; + esac +fi + +BASE_ARCH_URL="${BASE_ARCH_URL:-${MIRROR}releases/${BASE_ARCH}/autobuilds/}" LATEST=$(wget -O - "${BASE_ARCH_URL}latest-stage3.txt") -DATE=$(echo "${LATEST}" | sed -n 's|/stage3-amd64-[0-9]*[.]tar[.]bz2.*||p') +DATE=$(echo "${LATEST}" | sed -n "s|/stage3-${STAGE3_ARCH}-[0-9]*[.]tar[.]bz2.*||p") ARCH_URL="${ARCH_URL:-${BASE_ARCH_URL}${DATE}/}" -STAGE3="${STAGE3:-stage3-amd64-${DATE}.tar.bz2}" +STAGE3="${STAGE3:-stage3-${STAGE3_ARCH}-${DATE}.tar.bz2}" STAGE3_CONTENTS="${STAGE3_CONTENTS:-${STAGE3}.CONTENTS}" STAGE3_DIGESTS="${STAGE3_DIGESTS:-${STAGE3}.DIGESTS.asc}" diff --git a/rootfs-386.tar.gz b/rootfs-386.tar.gz new file mode 100644 index 00000000..9e52effe Binary files /dev/null and b/rootfs-386.tar.gz differ diff --git a/rootfs.tar.gz b/rootfs-amd64.tar.gz similarity index 100% rename from rootfs.tar.gz rename to rootfs-amd64.tar.gz diff --git a/validation/validation_test.go b/validation/validation_test.go index c85bbec2..775190da 100644 --- a/validation/validation_test.go +++ b/validation/validation_test.go @@ -6,6 +6,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "testing" "github.com/mrunalp/fileutils" @@ -18,13 +19,13 @@ import ( ) var ( - runtime = "runc" + runtimeCommand = "runc" ) func init() { runtimeInEnv := os.Getenv("RUNTIME") if runtimeInEnv != "" { - runtime = runtimeInEnv + runtimeCommand = runtimeInEnv } } @@ -36,7 +37,7 @@ func prepareBundle() (string, error) { } // Untar the root fs - untarCmd := exec.Command("tar", "-xf", "../rootfs.tar.gz", "-C", bundleDir) + untarCmd := exec.Command("tar", "-xf", fmt.Sprintf("../rootfs-%s.tar.gz", runtime.GOARCH), "-C", bundleDir) _, err = untarCmd.CombinedOutput() if err != nil { os.RemoveAll(bundleDir) @@ -58,7 +59,7 @@ func runtimeInsideValidate(g *generate.Generator) error { if err != nil { return err } - r, err := NewRuntime(runtime, bundleDir) + r, err := NewRuntime(runtimeCommand, bundleDir) if err != nil { os.RemoveAll(bundleDir) return err @@ -102,7 +103,7 @@ func TestValidateCreate(t *testing.T) { bundleDir, err := prepareBundle() assert.Nil(t, err) - r, err := NewRuntime(runtime, bundleDir) + r, err := NewRuntime(runtimeCommand, bundleDir) assert.Nil(t, err) defer r.Clean(true)