Added arm64 support to image

- Modified Dockerfile to cross-compilate to x86_64 and arm64
- Modified build-push.yml workflow and changed conditions to run workflow
- Modified build-push.yml workflow to build form x86_64 and arm64
- Modified build-push.yml workflow cache and push to GitHub's Container Registry
- Modified build-push.yml workflow and added build step to  login to GitHub's Container Registry
- Modified build-push.yml workflow and added build step to generate image metadata
- Modified build-push.yml workflow docker/build-push-action step to v5
This commit is contained in:
Tyrone Faulhaber
2023-09-24 11:43:30 +00:00
parent 2b287cc940
commit baa4e044ca
2 changed files with 76 additions and 21 deletions
+28 -9
View File
@@ -1,25 +1,44 @@
# Builder
FROM rust:1.72.1-buster as builder
FROM --platform=linux/amd64 rust:1.72.1-buster as builder
WORKDIR /app
# Add extra build dependencies here
RUN apt-get update && apt-get install -y cmake
RUN apt-get update && apt-get install -yqq \
cmake gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu
COPY . .
# Remove `--features stats` if you want to deploy without stats collection
RUN cargo install --path . --features stats
RUN rustup target add x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu
# Remove `--features=stats` if you want to deploy without stats collection
RUN cargo build --features=stats --release \
--target=x86_64-unknown-linux-gnu --target=aarch64-unknown-linux-gnu
# Runtime
FROM debian:buster-slim
WORKDIR /app
ARG TARGETPLATFORM
ENV TARGETPLATFORM=$TARGETPLATFORM
# Add extra runtime dependencies here
RUN apt-get update && apt-get install -y openssl ca-certificates && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -yqq --no-install-recommends \
openssl ca-certificates && rm -rf /var/lib/apt/lists/*
# Copy spoticord binary from builder
COPY --from=builder /usr/local/cargo/bin/spoticord ./spoticord
# Copy spoticord binaries from builder to /tmp
COPY --from=builder \
/app/target/x86_64-unknown-linux-gnu/release/spoticord /tmp/x86_64
COPY --from=builder \
/app/target/aarch64-unknown-linux-gnu/release/spoticord /tmp/aarch64
CMD ["./spoticord"]
# Copy appropiate binary for target arch from /tmp
RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
cp /tmp/x86_64 /usr/local/bin/spoticord; \
elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
cp /tmp/aarch64 /usr/local/bin/spoticord; \
fi
# Delete unused binaries
RUN rm -rvf /tmp/x86_64 /tmp/aarch64
ENTRYPOINT [ "/usr/local/bin/spoticord" ]