Skip to content

Commit 5586e21

Browse files
committed
Add a MUSL image
Closes #10
1 parent e652235 commit 5586e21

File tree

4 files changed

+90
-6
lines changed

4 files changed

+90
-6
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ env:
77
- VERSION=1.37.0 VARIANT=stretch/slim
88
- VERSION=1.37.0 VARIANT=buster
99
- VERSION=1.37.0 VARIANT=buster/slim
10+
- VERSION=1.37.0 VARIANT=alpine3.10
1011
#VERSIONS
1112

1213
install:

1.37.0/alpine3.10/Dockerfile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM alpine:3.10
2+
3+
RUN apk add --no-cache \
4+
ca-certificates \
5+
gcc
6+
7+
ENV RUSTUP_HOME=/usr/local/rustup \
8+
CARGO_HOME=/usr/local/cargo \
9+
PATH=/usr/local/cargo/bin:$PATH \
10+
RUST_VERSION=1.37.0
11+
12+
RUN set -eux; \
13+
url="https://static.rust-lang.org/rustup/archive/1.19.0/x86_64-unknown-linux-musl/rustup-init"; \
14+
wget "$url"; \
15+
echo "b535be813cd89000044764806f569a8c1428417d4226f16ee9993867f0c4ea4e *rustup-init" | sha256sum -c -; \
16+
chmod +x rustup-init; \
17+
./rustup-init -y --no-modify-path --default-toolchain $RUST_VERSION; \
18+
rm rustup-init; \
19+
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
20+
rustup --version; \
21+
cargo --version; \
22+
rustc --version;

Dockerfile-alpine.template

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM alpine:%%TAG%%
2+
3+
RUN apk add --no-cache \
4+
ca-certificates \
5+
gcc
6+
7+
ENV RUSTUP_HOME=/usr/local/rustup \
8+
CARGO_HOME=/usr/local/cargo \
9+
PATH=/usr/local/cargo/bin:$PATH \
10+
RUST_VERSION=%%RUST-VERSION%%
11+
12+
RUN set -eux; \
13+
url="https://static.rust-lang.org/rustup/archive/%%RUSTUP-VERSION%%/x86_64-unknown-linux-musl/rustup-init"; \
14+
wget "$url"; \
15+
echo "%%RUSTUP-SHA256%% *rustup-init" | sha256sum -c -; \
16+
chmod +x rustup-init; \
17+
./rustup-init -y --no-modify-path --default-toolchain $RUST_VERSION; \
18+
rm rustup-init; \
19+
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
20+
rustup --version; \
21+
cargo --version; \
22+
rustc --version;

x.py

+45-6
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@
2323
"buster",
2424
]
2525

26-
default_variant = "buster"
26+
default_debian_variant = "buster"
2727

28-
def rustup_hash(arch):
29-
url = f"https://static.rust-lang.org/rustup/archive/{rustup_version}/{arch.rust}/rustup-init.sha256"
28+
alpine_versions = [
29+
"3.10",
30+
]
31+
32+
default_alpine_version = "3.10"
33+
34+
def rustup_hash(arch, version=None):
35+
if version is None:
36+
version = rustup_version
37+
url = f"https://static.rust-lang.org/rustup/archive/{version}/{arch}/rustup-init.sha256"
3038
with request.urlopen(url) as f:
3139
return f.read().decode('utf-8').split()[0]
3240

@@ -45,7 +53,7 @@ def update_debian():
4553
arch_case = 'dpkgArch="$(dpkg --print-architecture)"; \\\n'
4654
arch_case += ' case "${dpkgArch##*-}" in \\\n'
4755
for arch in debian_arches:
48-
hash = rustup_hash(arch)
56+
hash = rustup_hash(arch.rust)
4957
arch_case += f" {arch.dpkg}) rustArch='{arch.rust}'; rustupSha256='{hash}' ;; \\\n"
5058
arch_case += ' *) echo >&2 "unsupported architecture: ${dpkgArch}"; exit 1 ;; \\\n'
5159
arch_case += ' esac'
@@ -68,6 +76,18 @@ def update_debian():
6876
.replace("%%ARCH-CASE%%", arch_case)
6977
write_file(f"{rust_version}/{variant}/slim/Dockerfile", rendered)
7078

79+
def update_alpine():
80+
template = read_file("Dockerfile-alpine.template")
81+
alpine_rustup_version = "1.19.0"
82+
83+
for version in alpine_versions:
84+
rendered = template \
85+
.replace("%%RUST-VERSION%%", rust_version) \
86+
.replace("%%RUSTUP-VERSION%%", alpine_rustup_version) \
87+
.replace("%%TAG%%", version) \
88+
.replace("%%RUSTUP-SHA256%%", rustup_hash("x86_64-unknown-linux-musl", alpine_rustup_version))
89+
write_file(f"{rust_version}/alpine{version}/Dockerfile", rendered)
90+
7191
def update_travis():
7292
file = ".travis.yml"
7393
config = read_file(file)
@@ -77,6 +97,9 @@ def update_travis():
7797
versions += f" - VERSION={rust_version} VARIANT={variant}\n"
7898
versions += f" - VERSION={rust_version} VARIANT={variant}/slim\n"
7999

100+
for version in alpine_versions:
101+
versions += f" - VERSION={rust_version} VARIANT=alpine{version}\n"
102+
80103
marker = "#VERSIONS\n"
81104
split = config.split(marker)
82105
rendered = split[0] + marker + versions + marker + split[2]
@@ -120,7 +143,7 @@ def generate_stackbrew_library():
120143
for version_tag in version_tags():
121144
tags.append(f"{version_tag}-{variant}")
122145
tags.append(variant)
123-
if variant == default_variant:
146+
if variant == default_debian_variant:
124147
for version_tag in version_tags():
125148
tags.append(version_tag)
126149
tags.append("latest")
@@ -134,7 +157,7 @@ def generate_stackbrew_library():
134157
for version_tag in version_tags():
135158
tags.append(f"{version_tag}-slim-{variant}")
136159
tags.append(f"slim-{variant}")
137-
if variant == default_variant:
160+
if variant == default_debian_variant:
138161
for version_tag in version_tags():
139162
tags.append(f"{version_tag}-slim")
140163
tags.append("slim")
@@ -144,6 +167,21 @@ def generate_stackbrew_library():
144167
map(lambda a: a.bashbrew, debian_arches),
145168
os.path.join(rust_version, variant, "slim"))
146169

170+
for version in alpine_versions:
171+
tags = []
172+
for version_tag in version_tags():
173+
tags.append(f"{version_tag}-alpine{version}")
174+
tags.append(f"alpine{version}")
175+
if version == default_alpine_version:
176+
for version_tag in version_tags():
177+
tags.append(f"{version_tag}-alpine")
178+
tags.append("alpine")
179+
180+
library += single_library(
181+
tags,
182+
["amd64"],
183+
os.path.join(rust_version, f"alpine{version}"))
184+
147185
print(library)
148186

149187
def usage():
@@ -157,6 +195,7 @@ def usage():
157195
task = sys.argv[1]
158196
if task == "update":
159197
update_debian()
198+
update_alpine()
160199
update_travis()
161200
elif task == "generate-stackbrew-library":
162201
generate_stackbrew_library()

0 commit comments

Comments
 (0)