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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
28 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,9 @@ name: Build | |
|
||
on: [push, pull_request] | ||
|
||
env: | ||
IMAGE_NAME: dcard/workerd | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
platform: | ||
- linux/amd64 | ||
- linux/arm64 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
@@ -29,73 +21,18 @@ jobs: | |
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.IMAGE_NAME }} | ||
- name: Set up Bazel cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: bazel-cache | ||
key: bazel-${{ matrix.platform }}-${{ hashFiles('Dockerfile') }} | ||
restore-keys: bazel-${{ matrix.platform }} | ||
- name: Inject Bazel cache into Docker | ||
uses: reproducible-containers/[email protected] | ||
with: | ||
cache-source: bazel-cache | ||
cache-target: /root/.cache/bazel | ||
images: dcard/workerd | ||
tags: | | ||
type=sha | ||
type=raw,value=latest,enable={{is_default_branch}} | ||
- name: Build and push | ||
id: build | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
platforms: ${{ matrix.platform }} | ||
push: true | ||
platforms: linux/amd64,linux/arm64 | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true | ||
- name: Set PLATFORM_PAIR environment variable | ||
run: | | ||
platform=${{ matrix.platform }} | ||
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV | ||
- name: Export digest | ||
run: | | ||
mkdir -p /tmp/digests | ||
digest="${{ steps.build.outputs.digest }}" | ||
touch "/tmp/digests/${digest#sha256:}" | ||
- name: Upload digest | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: digests-${{ env.PLATFORM_PAIR }} | ||
path: /tmp/digests/* | ||
if-no-files-found: error | ||
retention-days: 1 | ||
merge: | ||
runs-on: ubuntu-latest | ||
needs: | ||
- build | ||
steps: | ||
- name: Download digests | ||
uses: actions/download-artifact@v4 | ||
with: | ||
path: /tmp/digests | ||
pattern: digests-* | ||
merge-multiple: true | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.IMAGE_NAME }} | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
- name: Create manifest list and push | ||
working-directory: /tmp/digests | ||
run: | | ||
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | ||
$(printf '${{ env.IMAGE_NAME }}@sha256:%s ' *) | ||
- name: Inspect image | ||
run: | | ||
docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,11 @@ | ||
# 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 | ||
RUN apt-get update && apt-get install -y curl | ||
WORKDIR /workspace | ||
RUN curl -L https://github.com/cloudflare/workerd/archive/refs/tags/v1.20240605.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 | ||
COPY download-workerd.sh ./ | ||
RUN ARCH=${TARGETARCH} ./download-workerd.sh | ||
|
||
FROM gcr.io/distroless/cc-debian12:nonroot | ||
COPY --from=builder /usr/local/bin/workerd /usr/local/bin/workerd | ||
COPY --from=builder /workspace/bin/workerd /usr/local/bin/workerd | ||
ENTRYPOINT ["workerd"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -Eeuo pipefail | ||
|
||
pkg_version=1.20240605.0 | ||
target_path=./bin/workerd | ||
|
||
if [[ $ARCH == arm* ]]; then | ||
pkg_arch=arm64 | ||
else | ||
pkg_arch=64 | ||
fi | ||
|
||
set -x | ||
mkdir -p "$(dirname $target_path)" | ||
curl -L "https://github.com/cloudflare/workerd/releases/download/v${pkg_version}/workerd-linux-${pkg_arch}.gz" | gzip -d > "$target_path" | ||
chmod +x "$target_path" |
This file was deleted.
Oops, something went wrong.