Skip to content

Commit da9ed4f

Browse files
committed
Add alpine and distroless images
1 parent 78317fc commit da9ed4f

File tree

6 files changed

+153
-55
lines changed

6 files changed

+153
-55
lines changed

dockerhub/Dockerfile-alpine

Lines changed: 0 additions & 29 deletions
This file was deleted.

dockerhub/alpine/Dockerfile

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
FROM alpine:3.18 AS build
2+
3+
# https://github.com/oven-sh/bun/releases
4+
ARG BUN_VERSION=latest
5+
6+
# TODO: Instead of downloading glibc from a third-party source, we should
7+
# build it from source. This is a temporary solution.
8+
# See: https://github.com/sgerrand/alpine-pkg-glibc
9+
10+
# https://github.com/sgerrand/alpine-pkg-glibc/releases
11+
# https://github.com/sgerrand/alpine-pkg-glibc/issues/176
12+
ARG GLIBC_VERSION=2.34-r0
13+
14+
# https://github.com/oven-sh/bun/issues/5545#issuecomment-1722461083
15+
ARG GLIBC_VERSION_AARCH64=2.26-r1
16+
17+
RUN apk --no-cache add \
18+
ca-certificates \
19+
curl \
20+
dirmngr \
21+
gpg \
22+
gpg-agent \
23+
unzip \
24+
&& arch="$(apk --print-arch)" \
25+
&& case "${arch##*-}" in \
26+
x86_64) build="x64-baseline";; \
27+
aarch64) build="aarch64";; \
28+
*) echo "error: unsupported architecture: $arch"; exit 1 ;; \
29+
esac \
30+
&& version="$BUN_VERSION" \
31+
&& case "$version" in \
32+
latest | canary | bun-v*) tag="$version"; ;; \
33+
v*) tag="bun-$version"; ;; \
34+
*) tag="bun-v$version"; ;; \
35+
esac \
36+
&& case "$tag" in \
37+
latest) release="latest/download"; ;; \
38+
*) release="download/$tag"; ;; \
39+
esac \
40+
&& curl "https://github.com/oven-sh/bun/releases/$release/bun-linux-$build.zip" \
41+
-fsSLO \
42+
--compressed \
43+
--retry 5 \
44+
|| (echo "error: failed to download: $tag" && exit 1) \
45+
&& for key in \
46+
"F3DCC08A8572C0749B3E18888EAB4D40A7B22B59" \
47+
; do \
48+
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" \
49+
|| gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \
50+
done \
51+
&& curl "https://github.com/oven-sh/bun/releases/$release/SHASUMS256.txt.asc" \
52+
-fsSLO \
53+
--compressed \
54+
--retry 5 \
55+
&& gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
56+
|| (echo "error: failed to verify: $tag" && exit 1) \
57+
&& grep " bun-linux-$build.zip\$" SHASUMS256.txt | sha256sum -c - \
58+
|| (echo "error: failed to verify: $tag" && exit 1) \
59+
&& unzip "bun-linux-$build.zip" \
60+
&& mv "bun-linux-$build/bun" /usr/local/bin/bun \
61+
&& rm -f "bun-linux-$build.zip" SHASUMS256.txt.asc SHASUMS256.txt \
62+
&& chmod +x /usr/local/bin/bun \
63+
&& cd /tmp \
64+
&& case "${arch##*-}" in \
65+
x86_64) curl "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-${GLIBC_VERSION}.apk" \
66+
-fsSLO \
67+
--compressed \
68+
--retry 5 \
69+
|| (echo "error: failed to download: glibc v${GLIBC_VERSION}" && exit 1) \
70+
&& mv "glibc-${GLIBC_VERSION}.apk" glibc.apk \
71+
&& curl "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-bin-${GLIBC_VERSION}.apk" \
72+
-fsSLO \
73+
--compressed \
74+
--retry 5 \
75+
|| (echo "error: failed to download: glibc-bin v${GLIBC_VERSION}" && exit 1) \
76+
&& mv "glibc-bin-${GLIBC_VERSION}.apk" glibc-bin.apk ;; \
77+
aarch64) curl "https://raw.githubusercontent.com/squishyu/alpine-pkg-glibc-aarch64-bin/master/glibc-${GLIBC_VERSION}.apk" \
78+
-fsSLO \
79+
--compressed \
80+
--retry 5 \
81+
|| (echo "error: failed to download: glibc v${GLIBC_VERSION}" && exit 1) \
82+
&& mv "glibc-${GLIBC_VERSION}.apk" glibc.apk \
83+
&& curl "https://raw.githubusercontent.com/squishyu/alpine-pkg-glibc-aarch64-bin/master/glibc-bin-${GLIBC_VERSION}.apk" \
84+
-fsSLO \
85+
--compressed \
86+
--retry 5 \
87+
|| (echo "error: failed to download: glibc-bin v${GLIBC_VERSION}" && exit 1) \
88+
&& mv "glibc-bin-${GLIBC_VERSION}.apk" glibc-bin.apk ;; \
89+
*) echo "error: unsupported architecture '$arch'"; exit 1 ;; \
90+
esac
91+
92+
FROM alpine:3.18
93+
94+
COPY --from=build /tmp/glibc.apk /tmp/
95+
COPY --from=build /tmp/glibc-bin.apk /tmp/
96+
COPY --from=build /usr/local/bin/bun /usr/local/bin/
97+
COPY docker-entrypoint.sh /usr/local/bin/
98+
99+
RUN addgroup -g 1000 bun \
100+
&& adduser -u 1000 -G bun -s /bin/sh -D bun \
101+
&& apk --no-cache --force-overwrite --allow-untrusted add \
102+
/tmp/glibc.apk \
103+
/tmp/glibc-bin.apk \
104+
&& rm /tmp/glibc.apk \
105+
&& rm /tmp/glibc-bin.apk \
106+
&& ln /usr/local/bin/bun /usr/local/bin/bunx \
107+
&& which bun \
108+
&& which bunx \
109+
&& bun --version
110+
111+
WORKDIR /home/bun/app
112+
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
113+
CMD ["/usr/local/bin/bun"]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
set -e
3+
4+
if [ "${1#-}" != "${1}" ] || [ -z "$(command -v "${1}")" ] || { [ -f "${1}" ] && ! [ -x "${1}" ]; }; then
5+
set -- /usr/local/bin/bun "$@"
6+
fi
7+
8+
exec "$@"

dockerhub/debian-slim/Dockerfile

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ RUN apt-get update -qq \
1717
&& case "${arch##*-}" in \
1818
amd64) build="x64-baseline";; \
1919
arm64) build="aarch64";; \
20-
*) echo "error: unsupported architecture: ($arch)"; exit 1 ;; \
20+
*) echo "error: unsupported architecture: $arch"; exit 1 ;; \
2121
esac \
2222
&& version="$BUN_VERSION" \
2323
&& case "$version" in \
@@ -33,7 +33,7 @@ RUN apt-get update -qq \
3333
-fsSLO \
3434
--compressed \
3535
--retry 5 \
36-
|| (echo "error: unknown release: ($tag)" && exit 1) \
36+
|| (echo "error: failed to download: $tag" && exit 1) \
3737
&& for key in \
3838
"F3DCC08A8572C0749B3E18888EAB4D40A7B22B59" \
3939
; do \
@@ -45,9 +45,9 @@ RUN apt-get update -qq \
4545
--compressed \
4646
--retry 5 \
4747
&& gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
48-
|| (echo "error: failed to verify release: ($tag)" && exit 1) \
48+
|| (echo "error: failed to verify: $tag" && exit 1) \
4949
&& grep " bun-linux-$build.zip\$" SHASUMS256.txt | sha256sum -c - \
50-
|| (echo "error: failed to verify release: ($tag)" && exit 1) \
50+
|| (echo "error: failed to verify: $tag" && exit 1) \
5151
&& unzip "bun-linux-$build.zip" \
5252
&& mv "bun-linux-$build/bun" /usr/local/bin/bun \
5353
&& rm -f "bun-linux-$build.zip" SHASUMS256.txt.asc SHASUMS256.txt \
@@ -57,17 +57,21 @@ RUN apt-get update -qq \
5757

5858
FROM debian:bullseye-slim
5959

60+
COPY docker-entrypoint.sh /usr/local/bin
61+
COPY --from=build /usr/local/bin/bun /usr/local/bin/bun
62+
6063
RUN groupadd bun \
6164
--gid 1000 \
6265
&& useradd bun \
6366
--uid 1000 \
6467
--gid bun \
6568
--shell /bin/sh \
66-
--create-home
67-
68-
COPY docker-entrypoint.sh /usr/local/bin
69-
COPY --from=build /usr/local/bin/bun /usr/local/bin/bun
70-
RUN ln -s /usr/local/bin/bun /usr/local/bin/bunx
69+
--create-home \
70+
&& ln /usr/local/bin/bun /usr/local/bin/bunx \
71+
&& which bun \
72+
&& which bunx \
73+
&& bun --version
7174

75+
WORKDIR /home/bun/app
7276
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
7377
CMD ["/usr/local/bin/bun"]

dockerhub/debian/Dockerfile

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ RUN apt-get update -qq \
1717
&& case "${arch##*-}" in \
1818
amd64) build="x64-baseline";; \
1919
arm64) build="aarch64";; \
20-
*) echo "error: unsupported architecture: ($arch)"; exit 1 ;; \
20+
*) echo "error: unsupported architecture: $arch"; exit 1 ;; \
2121
esac \
2222
&& version="$BUN_VERSION" \
2323
&& case "$version" in \
@@ -33,7 +33,7 @@ RUN apt-get update -qq \
3333
-fsSLO \
3434
--compressed \
3535
--retry 5 \
36-
|| (echo "error: unknown release: ($tag)" && exit 1) \
36+
|| (echo "error: failed to download: $tag" && exit 1) \
3737
&& for key in \
3838
"F3DCC08A8572C0749B3E18888EAB4D40A7B22B59" \
3939
; do \
@@ -45,29 +45,31 @@ RUN apt-get update -qq \
4545
--compressed \
4646
--retry 5 \
4747
&& gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
48-
|| (echo "error: failed to verify release: ($tag)" && exit 1) \
48+
|| (echo "error: failed to verify: $tag" && exit 1) \
4949
&& grep " bun-linux-$build.zip\$" SHASUMS256.txt | sha256sum -c - \
50-
|| (echo "error: failed to verify release: ($tag)" && exit 1) \
50+
|| (echo "error: failed to verify: $tag" && exit 1) \
5151
&& unzip "bun-linux-$build.zip" \
5252
&& mv "bun-linux-$build/bun" /usr/local/bin/bun \
5353
&& rm -f "bun-linux-$build.zip" SHASUMS256.txt.asc SHASUMS256.txt \
54-
&& chmod +x /usr/local/bin/bun \
55-
&& which bun \
56-
&& bun --version
54+
&& chmod +x /usr/local/bin/bun
5755

5856
FROM debian:bullseye
5957

58+
COPY docker-entrypoint.sh /usr/local/bin
59+
COPY --from=build /usr/local/bin/bun /usr/local/bin/bun
60+
6061
RUN groupadd bun \
6162
--gid 1000 \
6263
&& useradd bun \
6364
--uid 1000 \
6465
--gid bun \
6566
--shell /bin/sh \
66-
--create-home
67-
68-
COPY docker-entrypoint.sh /usr/local/bin
69-
COPY --from=build /usr/local/bin/bun /usr/local/bin/bun
70-
RUN ln -s /usr/local/bin/bun /usr/local/bin/bunx
67+
--create-home \
68+
&& ln /usr/local/bin/bun /usr/local/bin/bunx \
69+
&& which bun \
70+
&& which bunx \
71+
&& bun --version
7172

73+
WORKDIR /home/bun/app
7274
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
7375
CMD ["/usr/local/bin/bun"]

dockerhub/distroless/Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ RUN apt-get update -qq \
1717
&& case "${arch##*-}" in \
1818
amd64) build="x64-baseline";; \
1919
arm64) build="aarch64";; \
20-
*) echo "error: unsupported architecture: ($arch)"; exit 1 ;; \
20+
*) echo "error: unsupported architecture: $arch"; exit 1 ;; \
2121
esac \
2222
&& version="$BUN_VERSION" \
2323
&& case "$version" in \
@@ -33,7 +33,7 @@ RUN apt-get update -qq \
3333
-fsSLO \
3434
--compressed \
3535
--retry 5 \
36-
|| (echo "error: unknown release: ($tag)" && exit 1) \
36+
|| (echo "error: failed to download: $tag" && exit 1) \
3737
&& for key in \
3838
"F3DCC08A8572C0749B3E18888EAB4D40A7B22B59" \
3939
; do \
@@ -45,9 +45,9 @@ RUN apt-get update -qq \
4545
--compressed \
4646
--retry 5 \
4747
&& gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
48-
|| (echo "error: failed to verify release: ($tag)" && exit 1) \
48+
|| (echo "error: failed to verify: $tag" && exit 1) \
4949
&& grep " bun-linux-$build.zip\$" SHASUMS256.txt | sha256sum -c - \
50-
|| (echo "error: failed to verify release: ($tag)" && exit 1) \
50+
|| (echo "error: failed to verify: $tag" && exit 1) \
5151
&& unzip "bun-linux-$build.zip" \
5252
&& mv "bun-linux-$build/bun" /usr/local/bin/bun \
5353
&& rm -f "bun-linux-$build.zip" SHASUMS256.txt.asc SHASUMS256.txt \
@@ -61,7 +61,7 @@ COPY --from=build /usr/local/bin/bun /usr/local/bin/
6161

6262
# Known issue: `bunx` is not available in distroless.
6363
#
64-
# If `ln -s` is used in the build image, the size of the final
64+
# If `ln` is used in the build image, the size of the final
6565
# image will be double, because of: https://github.com/oven-sh/bun/issues/5269
6666

6767
ENTRYPOINT ["/usr/local/bin/bun"]

0 commit comments

Comments
 (0)