Skip to content

Commit

Permalink
Build docker image for arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
asan authored and afitzek committed Nov 19, 2022
1 parent 8451308 commit c6ba790
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ jobs:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_REGISTRY_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and Push Docker Image
uses: docker/build-push-action@v2
with:
push: true # Will only build if this is not here
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/${{ github.repository }}:${{ github.ref_name }}
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:latest
25 changes: 18 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
FROM rust:1.58 as build
# syntax=docker/dockerfile:1

RUN echo "export PATH=/usr/local/cargo/bin:$PATH" >> /etc/profile
FROM --platform=$BUILDPLATFORM rust:1.58 as build
ARG TARGETARCH

RUN echo "export PATH=/usr/local/cargo/bin:$PATH" >> /etc/profile
WORKDIR /app

COPY ["./build/platform.sh", "./"]
RUN ./platform.sh
COPY ["./build/.cargo/config", ".cargo/config"]
RUN rustup target add $(cat /.platform)
RUN apt-get update && apt-get install -y $(cat /.compiler)

COPY ["./metrics/Cargo.toml", "./metrics/Cargo.lock", "./"]

RUN mkdir src && echo "fn main() {}" > src/main.rs && cargo build --release
RUN mkdir src && echo "fn main() {}" > src/main.rs && cargo build --release --target=$(cat /.platform)

COPY ["./metrics/src", "./src"]

RUN touch src/main.rs && cargo build --release
RUN touch src/main.rs && cargo build --release --target=$(cat /.platform)

FROM gcr.io/distroless/cc-debian11
RUN mkdir -p /release/$TARGETARCH
RUN cp ./target/$(cat /.platform)/release/metrics /release/$TARGETARCH/metrics

COPY --from=build /app/target/release/metrics /
FROM gcr.io/distroless/cc-debian11
ARG TARGETARCH
COPY --from=build /release/$TARGETARCH/metrics /

CMD ["/metrics"]
CMD ["/metrics"]
5 changes: 5 additions & 0 deletions build/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"

[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
19 changes: 19 additions & 0 deletions build/platform.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# Used in Docker build to set platform dependent variables

case $TARGETARCH in

"amd64")
echo "x86_64-unknown-linux-gnu" > /.platform
echo "" > /.compiler
;;
"arm64")
echo "aarch64-unknown-linux-gnu" > /.platform
echo "gcc-aarch64-linux-gnu" > /.compiler
;;
"arm")
echo "armv7-unknown-linux-gnueabihf" > /.platform
echo "gcc-arm-linux-gnueabihf" > /.compiler
;;
esac
1 change: 1 addition & 0 deletions metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ clap = { version = "3", features = ["env", "cargo", "derive"] }
notify = "4.0.17"
snafu = "0.7.1"
regex = "1.6"
openssl = { version = "0.10.40", features = ["vendored"] }

0 comments on commit c6ba790

Please sign in to comment.