Skip to content

Commit

Permalink
chore: use self-hosted runner for arm builds (#118)
Browse files Browse the repository at this point in the history
This also allows the removal of all the crazy sccache logic
  • Loading branch information
bradenrayhorn authored Oct 29, 2024
1 parent 3650d39 commit 9686d63
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 116 deletions.
104 changes: 1 addition & 103 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ jobs:
with:
ref: "${{ inputs.ref }}"

- name: Set up QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3
with:
platforms: 'amd64'

- name: Login to registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
with:
Expand All @@ -33,52 +28,6 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3

- name: Make cache IDs
id: run_number
run: |
RUN_NUMBER=${{ github.run_number }}
PREV_RN=$(( RUN_NUMBER - 1 ))
NEXT_RN=$(( RUN_NUMBER ))
echo "next_rn=$NEXT_RN" >> $GITHUB_OUTPUT
echo "prev_rn=$PREV_RN" >> $GITHUB_OUTPUT
- name: Restore cache
uses: actions/cache/restore@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4
id: cache-restore
with:
path: |
sccache
key: rust-sccache-amd64-${{ steps.run_number.outputs.prev_rn }}

- name: Delete old cache
run: |
gh extension install actions/gh-actions-cache
set +e
gh actions-cache delete "rust-sccache-amd64-${{ steps.run_number.outputs.prev_rn }}" -R $REPO -B main --confirm
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}

- name: Setup cache save
uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4
id: cache-restore-save
with:
path: |
sccache
key: rust-sccache-amd64-${{ steps.run_number.outputs.next_rn }}
save-always: true

- name: Inject cache into docker
uses: reproducible-containers/buildkit-cache-dance@5b6db76d1da5c8b307d5d2e0706d266521b710de # v3.1.2
with:
cache-map: |
{
"sccache": "/sccache-cache"
}
- name: Build and push
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6
with:
Expand All @@ -92,7 +41,7 @@ jobs:

build-arm64:
name: arm64 image
runs-on: ubuntu-latest
runs-on: [self-hosted, arm64]
permissions:
packages: write
actions: write
Expand All @@ -102,11 +51,6 @@ jobs:
with:
ref: "${{ inputs.ref }}"

- name: Set up QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3
with:
platforms: 'arm64'

- name: Login to registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
with:
Expand All @@ -117,52 +61,6 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3

- name: Make cache IDs
id: run_number
run: |
RUN_NUMBER=${{ github.run_number }}
PREV_RN=$(( RUN_NUMBER - 1 ))
NEXT_RN=$(( RUN_NUMBER ))
echo "next_rn=$NEXT_RN" >> $GITHUB_OUTPUT
echo "prev_rn=$PREV_RN" >> $GITHUB_OUTPUT
- name: Restore cache
uses: actions/cache/restore@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4
id: cache-restore
with:
path: |
sccache
key: rust-sccache-arm64-${{ steps.run_number.outputs.prev_rn }}

- name: Delete old cache
run: |
gh extension install actions/gh-actions-cache
set +e
gh actions-cache delete "rust-sccache-arm64-${{ steps.run_number.outputs.prev_rn }}" -R $REPO -B main --confirm
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}

- name: Setup cache save
uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4
id: cache-restore-save
with:
path: |
sccache
key: rust-sccache-arm64-${{ steps.run_number.outputs.next_rn }}
save-always: true

- name: Inject cache into docker
uses: reproducible-containers/buildkit-cache-dance@5b6db76d1da5c8b307d5d2e0706d266521b710de # v3.1.2
with:
cache-map: |
{
"sccache": "/sccache-cache"
}
- name: Build and push
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6
with:
Expand Down
18 changes: 5 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM rust:1.81-alpine@sha256:d6e876ca5fe200f4ac60312b95606f0b042699c4cf6a19493b7d2a2ebbfb337b as rust_base
FROM rust:1.81-alpine@sha256:d6e876ca5fe200f4ac60312b95606f0b042699c4cf6a19493b7d2a2ebbfb337b AS rust_base

RUN apk add musl-dev pkgconfig wget

# find rust licenses
FROM rust_base as rust_licenses
FROM rust_base AS rust_licenses

RUN cargo install cargo-bundle-licenses

Expand All @@ -14,7 +14,7 @@ WORKDIR /app
RUN cargo bundle-licenses --format json --output /app/server-licenses.json

# build frontend
FROM node:20-alpine@sha256:c13b26e7e602ef2f1074aef304ce6e9b7dd284c419b35d89fcf3cc8e44a8def9 as ui_builder
FROM node:20-alpine@sha256:c13b26e7e602ef2f1074aef304ce6e9b7dd284c419b35d89fcf3cc8e44a8def9 AS ui_builder

RUN mkdir /app
COPY /ui app/
Expand All @@ -29,21 +29,13 @@ RUN GENERATE_LICENSES=true npm run build
RUN npm run build

# build server
FROM rust_base as server_builder

RUN wget -O sccache.tar.gz https://github.com/mozilla/sccache/releases/download/v0.8.1/sccache-v0.8.1-$(uname -m)-unknown-linux-musl.tar.gz \
&& tar xzf sccache.tar.gz \
&& mv sccache-v0.8.1-$(uname -m)-unknown-linux-musl/sccache /usr/local/bin/sccache \
&& chmod +x /usr/local/bin/sccache;

ENV SCCACHE_DIR=/sccache-cache
ENV RUSTC_WRAPPER="/usr/local/bin/sccache"
FROM rust_base AS server_builder

RUN mkdir /app
COPY /server app/
WORKDIR /app

RUN --mount=type=cache,target=/sccache-cache cargo build --release && sccache --show-stats
RUN cargo build --release

# assemble final image
FROM alpine:3.20@sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d
Expand Down

0 comments on commit 9686d63

Please sign in to comment.