From 5586e216d828d2d8ab0a784eac32cacf38eae438 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Wed, 11 Sep 2019 17:54:52 -0700 Subject: [PATCH] Add a MUSL image Closes #10 --- .travis.yml | 1 + 1.37.0/alpine3.10/Dockerfile | 22 ++++++++++++++++ Dockerfile-alpine.template | 22 ++++++++++++++++ x.py | 51 +++++++++++++++++++++++++++++++----- 4 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 1.37.0/alpine3.10/Dockerfile create mode 100644 Dockerfile-alpine.template diff --git a/.travis.yml b/.travis.yml index 5353923..896c14b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ env: - VERSION=1.37.0 VARIANT=stretch/slim - VERSION=1.37.0 VARIANT=buster - VERSION=1.37.0 VARIANT=buster/slim + - VERSION=1.37.0 VARIANT=alpine3.10 #VERSIONS install: diff --git a/1.37.0/alpine3.10/Dockerfile b/1.37.0/alpine3.10/Dockerfile new file mode 100644 index 0000000..5ea80f4 --- /dev/null +++ b/1.37.0/alpine3.10/Dockerfile @@ -0,0 +1,22 @@ +FROM alpine:3.10 + +RUN apk add --no-cache \ + ca-certificates \ + gcc + +ENV RUSTUP_HOME=/usr/local/rustup \ + CARGO_HOME=/usr/local/cargo \ + PATH=/usr/local/cargo/bin:$PATH \ + RUST_VERSION=1.37.0 + +RUN set -eux; \ + url="https://static.rust-lang.org/rustup/archive/1.19.0/x86_64-unknown-linux-musl/rustup-init"; \ + wget "$url"; \ + echo "b535be813cd89000044764806f569a8c1428417d4226f16ee9993867f0c4ea4e *rustup-init" | sha256sum -c -; \ + chmod +x rustup-init; \ + ./rustup-init -y --no-modify-path --default-toolchain $RUST_VERSION; \ + rm rustup-init; \ + chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \ + rustup --version; \ + cargo --version; \ + rustc --version; diff --git a/Dockerfile-alpine.template b/Dockerfile-alpine.template new file mode 100644 index 0000000..5bb3328 --- /dev/null +++ b/Dockerfile-alpine.template @@ -0,0 +1,22 @@ +FROM alpine:%%TAG%% + +RUN apk add --no-cache \ + ca-certificates \ + gcc + +ENV RUSTUP_HOME=/usr/local/rustup \ + CARGO_HOME=/usr/local/cargo \ + PATH=/usr/local/cargo/bin:$PATH \ + RUST_VERSION=%%RUST-VERSION%% + +RUN set -eux; \ + url="https://static.rust-lang.org/rustup/archive/%%RUSTUP-VERSION%%/x86_64-unknown-linux-musl/rustup-init"; \ + wget "$url"; \ + echo "%%RUSTUP-SHA256%% *rustup-init" | sha256sum -c -; \ + chmod +x rustup-init; \ + ./rustup-init -y --no-modify-path --default-toolchain $RUST_VERSION; \ + rm rustup-init; \ + chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \ + rustup --version; \ + cargo --version; \ + rustc --version; diff --git a/x.py b/x.py index 2a5b900..a365a7a 100755 --- a/x.py +++ b/x.py @@ -23,10 +23,18 @@ "buster", ] -default_variant = "buster" +default_debian_variant = "buster" -def rustup_hash(arch): - url = f"https://static.rust-lang.org/rustup/archive/{rustup_version}/{arch.rust}/rustup-init.sha256" +alpine_versions = [ + "3.10", +] + +default_alpine_version = "3.10" + +def rustup_hash(arch, version=None): + if version is None: + version = rustup_version + url = f"https://static.rust-lang.org/rustup/archive/{version}/{arch}/rustup-init.sha256" with request.urlopen(url) as f: return f.read().decode('utf-8').split()[0] @@ -45,7 +53,7 @@ def update_debian(): arch_case = 'dpkgArch="$(dpkg --print-architecture)"; \\\n' arch_case += ' case "${dpkgArch##*-}" in \\\n' for arch in debian_arches: - hash = rustup_hash(arch) + hash = rustup_hash(arch.rust) arch_case += f" {arch.dpkg}) rustArch='{arch.rust}'; rustupSha256='{hash}' ;; \\\n" arch_case += ' *) echo >&2 "unsupported architecture: ${dpkgArch}"; exit 1 ;; \\\n' arch_case += ' esac' @@ -68,6 +76,18 @@ def update_debian(): .replace("%%ARCH-CASE%%", arch_case) write_file(f"{rust_version}/{variant}/slim/Dockerfile", rendered) +def update_alpine(): + template = read_file("Dockerfile-alpine.template") + alpine_rustup_version = "1.19.0" + + for version in alpine_versions: + rendered = template \ + .replace("%%RUST-VERSION%%", rust_version) \ + .replace("%%RUSTUP-VERSION%%", alpine_rustup_version) \ + .replace("%%TAG%%", version) \ + .replace("%%RUSTUP-SHA256%%", rustup_hash("x86_64-unknown-linux-musl", alpine_rustup_version)) + write_file(f"{rust_version}/alpine{version}/Dockerfile", rendered) + def update_travis(): file = ".travis.yml" config = read_file(file) @@ -77,6 +97,9 @@ def update_travis(): versions += f" - VERSION={rust_version} VARIANT={variant}\n" versions += f" - VERSION={rust_version} VARIANT={variant}/slim\n" + for version in alpine_versions: + versions += f" - VERSION={rust_version} VARIANT=alpine{version}\n" + marker = "#VERSIONS\n" split = config.split(marker) rendered = split[0] + marker + versions + marker + split[2] @@ -120,7 +143,7 @@ def generate_stackbrew_library(): for version_tag in version_tags(): tags.append(f"{version_tag}-{variant}") tags.append(variant) - if variant == default_variant: + if variant == default_debian_variant: for version_tag in version_tags(): tags.append(version_tag) tags.append("latest") @@ -134,7 +157,7 @@ def generate_stackbrew_library(): for version_tag in version_tags(): tags.append(f"{version_tag}-slim-{variant}") tags.append(f"slim-{variant}") - if variant == default_variant: + if variant == default_debian_variant: for version_tag in version_tags(): tags.append(f"{version_tag}-slim") tags.append("slim") @@ -144,6 +167,21 @@ def generate_stackbrew_library(): map(lambda a: a.bashbrew, debian_arches), os.path.join(rust_version, variant, "slim")) + for version in alpine_versions: + tags = [] + for version_tag in version_tags(): + tags.append(f"{version_tag}-alpine{version}") + tags.append(f"alpine{version}") + if version == default_alpine_version: + for version_tag in version_tags(): + tags.append(f"{version_tag}-alpine") + tags.append("alpine") + + library += single_library( + tags, + ["amd64"], + os.path.join(rust_version, f"alpine{version}")) + print(library) def usage(): @@ -157,6 +195,7 @@ def usage(): task = sys.argv[1] if task == "update": update_debian() + update_alpine() update_travis() elif task == "generate-stackbrew-library": generate_stackbrew_library()