Skip to content

Commit

Permalink
Add arm64 support
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrsantos committed Oct 19, 2023
1 parent aefaf5e commit 2943882
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
19 changes: 9 additions & 10 deletions hole-punching-tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# syntax=docker/dockerfile:1.5-labs
FROM rust:1.72.0 as builder

RUN rustup target add x86_64-unknown-linux-musl
RUN --mount=type=cache,target=/var/cache/apt apt-get update && apt-get install -y musl-dev musl-tools
FROM --platform=$BUILDPLATFORM rust:1.72.0 as builder

# Run with access to the target cache to speed up builds
ARG BUILDPLATFORM

# Set the working directory
WORKDIR /workspace
ADD . .
RUN --mount=type=cache,target=./target \
--mount=type=cache,target=/usr/local/cargo/registry \
cargo build --release --package hole-punching-tests --target x86_64-unknown-linux-musl

RUN --mount=type=cache,target=./target \
mv ./target/x86_64-unknown-linux-musl/release/hole-punching-tests /usr/local/bin/hole-punching-tests
# Copy the Rust project source code, including build.sh, into the image
COPY . /workspace

# Make the build.sh script executable and run it
RUN chmod +x /workspace/build.sh && /workspace/build.sh ${BUILDPLATFORM}

FROM alpine:3
COPY --from=builder /usr/local/bin/hole-punching-tests /usr/bin/hole-punch-client
Expand Down
19 changes: 19 additions & 0 deletions hole-punching-tests/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# Translate Docker platform format to Rust target format
case "$(echo $1 | cut -d/ -f2)" in
"amd64") RUST_TARGET="x86_64-unknown-linux-musl";;
"arm64") RUST_TARGET="aarch64-unknown-linux-musl";;
*) echo "Unsupported architecture: $1" >&2; exit 1;;
esac

# Add the Rust target
rustup target add ${RUST_TARGET}

apt-get update && apt-get install -y musl-dev musl-tools

# Build the project
cargo build --release --package hole-punching-tests --target ${RUST_TARGET}

# Move the built binary to a common location
mv ./target/${RUST_TARGET}/release/hole-punching-tests /usr/local/bin/hole-punching-tests

0 comments on commit 2943882

Please sign in to comment.