Skip to content

Commit 9b2a4fb

Browse files
authored
chore: add gha caching to CI (#756)
Also removed a redundant development cargo build call that didn't result in any build optimizations.
1 parent 42a8bf0 commit 9b2a4fb

4 files changed

Lines changed: 61 additions & 48 deletions

File tree

‎.github/workflows/docker-build.yml‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Docker Build
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
permissions:
10+
contents: read
11+
12+
concurrency:
13+
group: docker-build-${{ github.event.pull_request.number || github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
build:
18+
timeout-minutes: 30
19+
strategy:
20+
matrix:
21+
include:
22+
- arch: amd64
23+
runner: ubuntu-latest
24+
- arch: arm64
25+
runner: ubuntu-24.04-arm
26+
runs-on: ${{ matrix.runner }}
27+
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- uses: docker/setup-buildx-action@v3
32+
33+
- uses: docker/build-push-action@v6
34+
with:
35+
context: .
36+
file: ./Dockerfile
37+
platforms: linux/${{ matrix.arch }}
38+
push: false
39+
cache-from: type=gha,scope=build-${{ matrix.arch }}
40+
cache-to: type=gha,mode=max,scope=build-${{ matrix.arch }}

‎.github/workflows/publish.yml‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,50 @@ permissions:
1111
id-token: write # OIDC
1212

1313
jobs:
14-
publish-docker-image:
15-
timeout-minutes: 20
14+
build-and-push:
15+
timeout-minutes: 30
1616
strategy:
1717
matrix:
1818
include:
1919
- arch: amd64
2020
runner: ubuntu-latest
2121
- arch: arm64
22-
runner: ubuntu-24.04-arm64
22+
runner: ubuntu-24.04-arm
2323
runs-on: ${{ matrix.runner }}
2424

2525
steps:
2626
- uses: actions/checkout@v4
2727

28-
# Log in so we can push the image layers + tags to Docker Hub
29-
- uses: docker/login-action@v2
28+
- name: Extract version from Cargo.toml
29+
id: version
30+
run: echo "version=$(awk -F '"' '/^version =/ {print $2}' Cargo.toml)" >> "$GITHUB_OUTPUT"
31+
32+
- uses: docker/setup-buildx-action@v3
33+
34+
- uses: docker/login-action@v3
3035
with:
3136
username: ${{ vars.DOCKERHUB_USER }}
3237
password: ${{ secrets.DOCKERHUB_WRITE_PASSWORD }}
3338

34-
- run: ./scripts/publish-image.sh
35-
shell: bash
36-
env:
37-
ARCH: ${{ matrix.arch }}
39+
- uses: docker/build-push-action@v6
40+
with:
41+
context: .
42+
file: ./Dockerfile
43+
platforms: linux/${{ matrix.arch }}
44+
push: true
45+
tags: farcasterxyz/snapchain:${{ steps.version.outputs.version }}-${{ matrix.arch }}
46+
cache-from: type=gha,scope=build-${{ matrix.arch }}
47+
cache-to: type=gha,mode=max,scope=build-${{ matrix.arch }}
3848

3949
create-manifest:
4050
timeout-minutes: 10
4151
runs-on: ubuntu-latest
42-
needs: publish-docker-image
52+
needs: build-and-push
4353

4454
steps:
4555
- uses: actions/checkout@v4
4656

47-
- uses: docker/login-action@v2
57+
- uses: docker/login-action@v3
4858
with:
4959
username: ${{ vars.DOCKERHUB_USER }}
5060
password: ${{ secrets.DOCKERHUB_WRITE_PASSWORD }}

‎Dockerfile‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ ARG ETH_SIGNATURE_VERIFIER_GIT_REPO_URL=https://github.com/CassOnMars/eth-signat
99
ENV ETH_SIGNATURE_VERIFIER_GIT_REPO_URL=$ETH_SIGNATURE_VERIFIER_GIT_REPO_URL
1010
ARG ETH_SIGNATURE_VERIFIER_GIT_REF=8deb4a091982c345949dc66bf8684489d9f11889
1111
ENV RUST_BACKTRACE=1
12-
RUN echo "clear cache" # Invalidate cache to pick up latest eth-signature-verifier
1312
RUN <<EOF
1413
set -eu
1514
apt-get update && apt-get install -y libclang-dev git libjemalloc-dev llvm-dev make protobuf-compiler libssl-dev openssh-client cmake
@@ -22,8 +21,6 @@ cd ..
2221
git clone $MALACHITE_GIT_REPO_URL
2322
cd malachite
2423
git checkout $MALACHITE_GIT_REF
25-
cd code
26-
cargo build
2724
EOF
2825

2926
# Unfortunately, we can't prefetch creates without including the source code,

‎scripts/publish-image.sh‎

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

0 commit comments

Comments
 (0)