mirror of
https://github.com/Steffo99/distributed-arcade.git
synced 2024-11-21 15:44:26 +00:00
Stefano Pigozzi
d34e7bf9b1
Uses the `USER` instruction. See https://stackoverflow.com/questions/68155641/should-i-run-things-inside-a-docker-container-as-non-root-for-safety .
79 lines
3 KiB
Docker
79 lines
3 KiB
Docker
FROM --platform=${BUILDPLATFORM} rust:1.68-bullseye AS builder
|
|
ARG BUILDPLATFORM
|
|
ARG TARGETPLATFORM
|
|
|
|
RUN apt-get update && \
|
|
apt-get upgrade --assume-yes
|
|
|
|
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/
|
|
|
|
USER ${UID:-1000}:${GID:-1000}
|
|
ENTRYPOINT ["distributed_arcade"]
|
|
CMD []
|
|
|
|
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"
|
|
LABEL org.opencontainers.image.url="https://github.com/Steffo99/distributed-arcade"
|
|
LABEL org.opencontainers.image.authors="Stefano Pigozzi <me@steffo.eu>"
|
|
ENV RUST_LOG "warn,distributed_arcade=info"
|