Skip to content

Commit fab570d

Browse files
authored
Merge pull request #49 from butaneprotocol/cross-compilation
feat: cross-compile the oracle outside of docker
2 parents ad8819e + 270a4ae commit fab570d

File tree

3 files changed

+61
-41
lines changed

3 files changed

+61
-41
lines changed

Diff for: .github/workflows/docker.yml

+26-20
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@ on:
88
jobs:
99
push_to_registry:
1010
name: Push Docker image to Docker Hub
11-
runs-on: "ubuntu-20.04"
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
include:
15+
- os: "ubuntu-22.04"
16+
platform: linux/amd64
17+
rust_target: x86_64-unknown-linux-gnu
18+
- os: "ubuntu-22.04"
19+
platform: linux/arm64
20+
rust_target: aarch64-unknown-linux-gnu
21+
1222
permissions:
1323
packages: write
1424
contents: read
@@ -34,26 +44,20 @@ jobs:
3444
with:
3545
images: sundaeswap/butane-oracle
3646

37-
- name: Cargo Cache
47+
- name: Install ARM toolchain
48+
if: matrix.rust_target == 'aarch64-unknown-linux-gnu'
49+
run: |
50+
rustup target install aarch64-unknown-linux-gnu
51+
sudo apt install gcc-aarch64-linux-gnu
52+
53+
- name: Rust Cache
3854
id: cache
39-
uses: actions/cache@v4
55+
uses: Swatinem/rust-cache@v2
4056
with:
41-
path: |
42-
cargo-registry-cache
43-
sccache-cache
44-
key: ${{ runner.os }}-cargo-cache-${{ github.sha }}
45-
restore-keys: |
46-
${{ runner.os }}-cargo-cache
57+
prefix-key: ${{ matrix.rust_target }}
4758

48-
- name: inject cargo caches into docker
49-
uses: reproducible-containers/buildkit-cache-dance@5b6db76d1da5c8b307d5d2e0706d266521b710de # v3.1.2
50-
with:
51-
cache-map: |
52-
{
53-
"cargo-registry-cache": "/usr/local/cargo/registry",
54-
"sccache-cache": "/sccache"
55-
}
56-
skip-extraction: ${{ steps.cache.outputs.cache-hit }}
59+
- name: Compile
60+
run: cargo build --release --target ${{ matrix.rust_target }}
5761

5862
- name: Build and push Docker image
5963
id: push
@@ -62,8 +66,10 @@ jobs:
6266
cache-from: type=gha
6367
cache-to: type=gha,mode=max
6468
context: .
65-
file: ./Dockerfile
69+
file: ./prebuilt.Dockerfile
6670
push: true
67-
platforms: "linux/amd64,linux/arm64"
71+
platforms: ${{ matrix.platform }}
72+
build-args: |
73+
RUST_TARGET=${{ matrix.rust_target }}
6874
tags: ${{ steps.meta.outputs.tags }}
6975
labels: ${{ steps.meta.outputs.labels }}

Diff for: .github/workflows/refresh-docker-cache.yml

+27-21
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@ on:
1010
jobs:
1111
build_image:
1212
name: Build Docker image
13-
runs-on: "ubuntu-20.04"
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
matrix:
16+
include:
17+
- os: "ubuntu-22.04"
18+
platform: linux/amd64
19+
rust_target: x86_64-unknown-linux-gnu
20+
- os: "ubuntu-22.04"
21+
platform: linux/arm64
22+
rust_target: aarch64-unknown-linux-gnu
23+
1424
permissions:
1525
contents: read
1626
steps:
@@ -27,26 +37,20 @@ jobs:
2737
with:
2838
images: sundaeswap/butane-oracle
2939

30-
- name: Cargo Cache
40+
- name: Install ARM toolchain
41+
if: matrix.rust_target == 'aarch64-unknown-linux-gnu'
42+
run: |
43+
rustup target install aarch64-unknown-linux-gnu
44+
sudo apt install gcc-aarch64-linux-gnu
45+
46+
- name: Rust Cache
3147
id: cache
32-
uses: actions/cache@v4
48+
uses: Swatinem/rust-cache@v2
3349
with:
34-
path: |
35-
cargo-registry-cache
36-
sccache-cache
37-
key: ${{ runner.os }}-cargo-cache-${{ github.sha }}
38-
restore-keys: |
39-
${{ runner.os }}-cargo-cache
40-
41-
- name: inject cargo caches into docker
42-
uses: reproducible-containers/buildkit-cache-dance@5b6db76d1da5c8b307d5d2e0706d266521b710de # v3.1.2
43-
with:
44-
cache-map: |
45-
{
46-
"cargo-registry-cache": "/usr/local/cargo/registry",
47-
"sccache-cache": "/sccache"
48-
}
49-
skip-extraction: ${{ steps.cache.outputs.cache-hit }}
50+
prefix-key: ${{ matrix.rust_target }}
51+
52+
- name: Compile
53+
run: cargo build --release --target ${{ matrix.rust_target }}
5054

5155
- name: Build Docker image
5256
id: build
@@ -55,8 +59,10 @@ jobs:
5559
cache-from: type=gha
5660
cache-to: type=gha,mode=max
5761
context: .
58-
file: ./Dockerfile
62+
file: ./prebuilt.Dockerfile
5963
outputs: type=image
60-
platforms: "linux/amd64,linux/arm64"
64+
platforms: ${{ matrix.platform }}
65+
build-args: |
66+
RUST_TARGET=${{ matrix.rust_target }}
6167
tags: ${{ steps.meta.outputs.tags }}
6268
labels: ${{ steps.meta.outputs.labels }}

Diff for: prebuilt.Dockerfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# GitHub Actions doesn't have free ARM runners for private repos.
2+
# Until we can use that, build the oracle from outside of docker via cross-compilation,
3+
# so that we don't do any expensive work inside of an emulated OS.
4+
FROM alpine
5+
ARG RUST_TARGET
6+
WORKDIR /app
7+
COPY target/${RUST_TARGET}/release/oracles /app/
8+
CMD ["./oracles"]

0 commit comments

Comments
 (0)