|
| 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"] |
0 commit comments