Skip to content

Commit

Permalink
Add a MUSL image
Browse files Browse the repository at this point in the history
Closes #10
  • Loading branch information
sfackler committed Sep 12, 2019
1 parent e652235 commit 5586e21
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 6 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 22 additions & 0 deletions 1.37.0/alpine3.10/Dockerfile
Original file line number Diff line number Diff line change
@@ -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;
22 changes: 22 additions & 0 deletions Dockerfile-alpine.template
Original file line number Diff line number Diff line change
@@ -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;
51 changes: 45 additions & 6 deletions x.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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'
Expand All @@ -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)
Expand All @@ -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]
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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():
Expand All @@ -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()
Expand Down

0 comments on commit 5586e21

Please sign in to comment.