Skip to content

Commit

Permalink
feat: add support for linux/arm64 image
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanccn committed Oct 19, 2023
1 parent c6432a6 commit 6ff3101
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
strategy:
matrix:
platform:
- linux/arm64
- linux/amd64

steps:
Expand Down
24 changes: 17 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
FROM --platform=amd64 rust:1.72-alpine as builder
FROM rust:1.72-slim as builder
ARG TARGETPLATFORM
WORKDIR /build

# RUN apt-get update && apt-get install -y build-essential musl-dev musl-tools gcc-x86-64-linux-gnu && apt-get clean && rm -rf /var/lib/apt/lists/*
RUN apk update && apk upgrade && apk add --no-cache musl-dev
RUN rustup target add x86_64-unknown-linux-musl
RUN set -ex; \
case "$TARGETPLATFORM" in \
"linux/amd64") target='x86_64-unknown-linux-musl' ;; \
"linux/arm64") target='aarch64-unknown-linux-musl' ;; \
*) echo >&2 "error: unsupported $TARGETPLATFORM architecture"; exit 1 ;; \
esac; \
echo "$target" > /tmp/target-spec

RUN apt-get update && apt-get install -y build-essential musl-dev musl-tools && apt-get clean && rm -rf /var/lib/apt/lists/*
# RUN apk update && apk upgrade && apk add --no-cache musl-dev
RUN rustup target add "$(cat /tmp/target-spec)"

ENV CARGO_BUILD_RUSTFLAGS="-C target-feature=+crt-static"

COPY . .
RUN cargo fetch --target x86_64-unknown-linux-musl --locked
RUN cargo build --target x86_64-unknown-linux-musl --release --locked
RUN cargo fetch --target "$(cat /tmp/target-spec)" --locked
RUN cargo build --target "$(cat /tmp/target-spec)" --release --locked
RUN cp "/build/target/$(cat /tmp/target-spec)/release/valfisk" /build/valfisk

FROM gcr.io/distroless/static:latest
COPY --from=builder /build/target/x86_64-unknown-linux-musl/release/valfisk /valfisk

COPY --from=builder /build/valfisk /valfisk
CMD ["/valfisk"]

0 comments on commit 6ff3101

Please sign in to comment.