rustlog/Dockerfile

42 lines
1.5 KiB
Docker
Raw Permalink Normal View History

2023-12-13 17:50:16 -03:00
FROM --platform=$BUILDPLATFORM node:18-alpine as frontend
WORKDIR /src/web
COPY web .
2023-03-11 14:31:56 -03:00
RUN yarn install --ignore-optional
2022-10-21 03:18:30 -03:00
RUN yarn build
2023-12-13 17:50:16 -03:00
FROM --platform=$BUILDPLATFORM rust:1.74-bookworm AS chef
2022-09-03 17:00:49 -04:00
USER root
2023-06-09 01:29:51 -04:00
ENV CARGO_PROFILE_RELEASE_LTO=true
2022-09-03 17:00:49 -04:00
RUN cargo install cargo-chef
WORKDIR /app
2023-12-13 17:50:16 -03:00
FROM --platform=$BUILDPLATFORM chef AS planner
COPY . .
2022-09-03 17:00:49 -04:00
RUN cargo chef prepare --recipe-path recipe.json
2023-12-13 17:50:16 -03:00
FROM --platform=$BUILDPLATFORM chef AS builder
ARG TARGETPLATFORM
RUN case "${TARGETPLATFORM}" in \
"linux/arm64") echo "aarch64-unknown-linux-gnu" > /target.txt && echo "-C linker=aarch64-linux-gnu-gcc" > /flags.txt ;; \
"linux/amd64") echo "x86_64-unknown-linux-gnu" > /target.txt && echo "-C linker=x86_64-linux-gnu-gcc" > /flags.txt ;; \
*) exit 1 ;; \
esac
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get install -yq build-essential g++-aarch64-linux-gnu binutils-aarch64-linux-gnu
RUN rustup target add "$(cat /target.txt)"
2022-09-03 17:00:49 -04:00
COPY --from=planner /app/recipe.json recipe.json
2023-12-13 17:50:16 -03:00
RUN RUSTFLAGS="$(cat /flags.txt)" cargo chef cook --target "$(cat /target.txt)" --release --recipe-path recipe.json
2022-09-03 17:00:49 -04:00
COPY . .
2022-10-21 03:18:30 -03:00
COPY --from=frontend /src/web web/
2023-12-13 17:50:16 -03:00
RUN RUSTFLAGS="$(cat /flags.txt)" cargo build --target "$(cat /target.txt)" --release
RUN mv "./target/$(cat /target.txt)/release" "/output"
2022-09-03 17:00:49 -04:00
2023-12-13 17:50:16 -03:00
FROM debian:bookworm AS runtime
RUN useradd rustlog && mkdir /logs && chown rustlog: /logs
2023-12-13 17:50:16 -03:00
COPY --from=builder /output/rustlog /usr/local/bin/
2022-09-03 17:00:49 -04:00
USER rustlog
2023-03-11 14:31:56 -03:00
CMD ["/usr/local/bin/rustlog"]