This repository has been archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
62 lines (54 loc) · 2.18 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# syntax=docker/dockerfile:1.4
FROM debian:bookworm AS builder
ARG TARGETARCH
ARG LLVM_VERSION=17
RUN <<EOT
rm -f /etc/apt/apt.conf.d/docker-clean
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
EOT
# Install LLVM
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked <<EOT
apt-get update
apt-get install -y --no-install-recommends curl gnupg git patch ca-certificates python3 python3-distutils tcl
echo "
deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-${LLVM_VERSION} main
deb-src http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-${LLVM_VERSION} main
" > /etc/apt/sources.list.d/llvm.list
curl https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
apt-get update
apt-get install -y --no-install-recommends \
llvm-${LLVM_VERSION} \
lld-${LLVM_VERSION} \
clang-${LLVM_VERSION} \
libc++-${LLVM_VERSION}-dev \
libc++abi-${LLVM_VERSION}-dev \
libunwind-${LLVM_VERSION}-dev
EOT
# Install bazelisk
RUN <<EOT
curl -L https://github.com/bazelbuild/bazelisk/releases/download/v1.17.0/bazelisk-linux-${TARGETARCH} -o /usr/local/bin/bazelisk
chmod +x /usr/local/bin/bazelisk
EOT
# Download workerd source code
WORKDIR /workspace
RUN curl -L https://github.com/cloudflare/workerd/archive/refs/tags/v1.20240405.0.tar.gz | tar -zx --strip-component=1 -C ./
# Patch workerd
COPY workerd.patch ./
RUN patch -p1 < workerd.patch
# Build workerd
RUN <<EOT
echo "
build:linux --action_env=CC=/usr/lib/llvm-${LLVM_VERSION}/bin/clang --action_env=CXX=/usr/lib/llvm-${LLVM_VERSION}/bin/clang++
build:linux --host_action_env=CC=/usr/lib/llvm-${LLVM_VERSION}/bin/clang --host_action_env=CXX=/usr/lib/llvm-${LLVM_VERSION}/bin/clang++
" >> .bazelrc
EOT
RUN --mount=type=cache,target=/root/.cache/bazelisk \
--mount=type=cache,target=/root/.cache/bazel <<EOT
bazelisk build --config=thin-lto -c opt //src/workerd/server:workerd
strip -S bazel-bin/src/workerd/server/workerd
cp bazel-bin/src/workerd/server/workerd /usr/local/bin/workerd
EOT
FROM gcr.io/distroless/cc-debian12:nonroot
COPY --from=builder /usr/local/bin/workerd /usr/local/bin/workerd
ENTRYPOINT ["workerd"]