Skip to content

Commit e0867ec

Browse files
feat: Implement cross-compilation and Docker layer caching for ARM builds
1 parent b749478 commit e0867ec

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

.github/workflows/CI.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,27 @@ jobs:
3636
- uses: actions/checkout@v4
3737
- name: Set up Docker Buildx
3838
uses: docker/setup-buildx-action@v3
39+
with:
40+
driver-opts: |
41+
image=moby/buildkit:master
42+
- name: Cache Docker layers
43+
uses: actions/cache@v4
44+
with:
45+
path: /tmp/.buildx-cache
46+
key: ${{ runner.os }}-buildx-${{ github.sha }}
47+
restore-keys: |
48+
${{ runner.os }}-buildx-
3949
- name: Build and push Docker image
4050
uses: docker/build-push-action@v5
51+
with:
52+
cache-from: type=local,src=/tmp/.buildx-cache
53+
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
4154
with:
4255
platforms: linux/amd64,linux/arm64
4356
push: false
4457
tags: |
4558
cybuerg/cfspeedtest:${{ github.sha }}
59+
- name: Move cache
60+
run: |
61+
rm -rf /tmp/.buildx-cache
62+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

Dockerfile

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
FROM rust:slim-bullseye as builder
22
WORKDIR /usr/src/cfspeedtest
3+
4+
# Add cross-compilation support
5+
ARG TARGETPLATFORM
6+
RUN echo "Building for $TARGETPLATFORM" && \
7+
if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
8+
apt-get update && \
9+
apt-get install -y --no-install-recommends \
10+
gcc-aarch64-linux-gnu \
11+
binutils-aarch64-linux-gnu && \
12+
rustup target add aarch64-unknown-linux-gnu && \
13+
rm -rf /var/lib/apt/lists/*; \
14+
fi
15+
316
COPY Cargo.toml Cargo.lock ./
417
COPY src ./src
5-
RUN cargo install --path .
18+
19+
# Set up cross-compilation environment
20+
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
21+
ARG CARGO_BUILD_FLAGS=""
22+
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then export CARGO_BUILD_FLAGS="--target aarch64-unknown-linux-gnu"; fi && \
23+
cargo install --path . $CARGO_BUILD_FLAGS
624

725
FROM debian:bullseye-slim
826
RUN apt-get update && apt-get install -y --no-install-recommends tini && rm -rf /var/lib/apt/lists/*

0 commit comments

Comments
 (0)