1
Fork 0
mirror of https://github.com/Steffo99/distributed-arcade.git synced 2024-12-03 13:34:23 +00:00

Fix multiplatform Docker image builds

This commit is contained in:
Steffo 2023-03-22 14:31:41 +01:00
parent 9f6381071e
commit 343ce7e240
Signed by: steffo
GPG key ID: 2A24051445686895
2 changed files with 82 additions and 12 deletions

16
.dockerignore Normal file
View file

@ -0,0 +1,16 @@
/.devcontainer/
/.github/
/.idea/
/.vscode/
/benches/
/examples/
/media/
/target/
/tests/
/.dockerignore
/.gitignore
/Dockerfile
/LICENSE
/README.md
/rustfmt.toml
**/*.rs.bk

View file

@ -1,21 +1,75 @@
FROM rust:1.65 AS files
WORKDIR /usr/src/revenants-brooch
COPY . .
FROM --platform=${BUILDPLATFORM} rust:1.68-bullseye AS builder
ARG BUILDPLATFORM
ARG TARGETPLATFORM
FROM files AS install
RUN cargo install --path . --all-features --bins
RUN apt-get update && \
apt-get upgrade --assume-yes
FROM debian:buster AS system
RUN apt-get update
RUN apt-get install -y libssl1.1 ca-certificates
RUN rm -rf /var/lib/apt/lists/*
COPY --from=install /usr/local/cargo/bin/distributed_arcade /usr/local/bin/distributed_arcade
RUN \
mkdir .cargo && \
echo '[net]' >> .cargo/config.toml && \
echo 'git-fetch-with-cli = true' >> .cargo/config.toml && \
echo >> .cargo/config.toml && \
if [ "${BUILDPLATFORM}" != "${TARGETPLATFORM}" ]; then \
if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \
apt-get install --assume-yes gcc-x86-64-linux-gnu; \
echo '[target.x86_64-unknown-linux-gnu]' >> .cargo/config.toml; \
echo 'linker = "x86-64-linux-gnu-gcc"' >> .cargo/config.toml; \
echo >> .cargo/config.toml; \
fi && \
if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
apt-get install --assume-yes gcc-aarch64-linux-gnu; \
echo '[target.aarch64-unknown-linux-gnu]' >> .cargo/config.toml; \
echo 'linker = "aarch64-linux-gnu-gcc"' >> .cargo/config.toml; \
echo >> .cargo/config.toml; \
fi && \
if [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then \
apt-get install --assume-yes gcc-arm-linux-gnueabihf; \
echo '[target.armv7-unknown-linux-gnueabihf]' >> .cargo/config.toml; \
echo 'linker = "arm-linux-gnueabihf-gcc"' >> .cargo/config.toml; \
echo >> .cargo/config.toml; \
fi \
fi
RUN \
if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \
RUSTTARGET=x86_64-unknown-linux-gnu; \
fi && \
if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
RUSTTARGET=aarch64-unknown-linux-gnu; \
fi && \
if [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then \
RUSTTARGET=armv7-unknown-linux-gnueabihf; \
fi && \
rustup target add ${RUSTTARGET}
WORKDIR /usr/src/distributed_arcade/
COPY ./ ./
RUN \
if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \
RUSTTARGET=x86_64-unknown-linux-gnu; \
fi && \
if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
RUSTTARGET=aarch64-unknown-linux-gnu; \
fi && \
if [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then \
RUSTTARGET=armv7-unknown-linux-gnueabihf; \
fi && \
cargo build --all-features --bins --release --target=${RUSTTARGET}
#############################################################################
FROM --platform=${TARGETPLATFORM} rust:1.68-slim-bullseye AS final
WORKDIR /usr/src/distributed_arcade/
COPY --from=builder \
/usr/src/distributed_arcade/target/*/release/distributed_arcade \
/usr/bin/
FROM system AS entrypoint
ENTRYPOINT ["distributed_arcade"]
CMD []
FROM entrypoint AS final
LABEL org.opencontainers.image.title="Distributed Arcade"
LABEL org.opencontainers.image.description="Fast and simple scoreboard service for games"
LABEL org.opencontainers.image.licenses="AGPL-3.0-or-later"