Frontend/static files building & serving

This commit is contained in:
Quentin Gliech
2021-12-09 22:09:39 +01:00
parent adbdcfdb6c
commit a5c0a88c85
16 changed files with 4284 additions and 7 deletions

View File

@@ -7,12 +7,27 @@
# there is a small script that translates those platforms to LLVM triples,
# respectively x86-64-unknown-linux-gnu and aarch64-unknown-linux-gnu
ARG RUSTC_VERSION=1.56.1
# The Debian version and version name must be in sync
ARG DEBIAN_VERSION=11
ARG DEBIAN_VERSION_NAME=bullseye
ARG RUSTC_VERSION=1.57.0
ARG NODEJS_VERSION=16
## Build stage that builds the static files/frontend ##
FROM --platform=${BUILDPLATFORM} docker.io/library/node:${NODEJS_VERSION}-${DEBIAN_VERSION_NAME}-slim AS static-files
WORKDIR /app/crates/static-files
COPY ./crates/static-files/package.json ./crates/static-files/package-lock.json /app/crates/static-files/
RUN npm ci
COPY . /app/
RUN npm run build
# Change the timestamp of built files for better caching
RUN find public -type f -exec touch -t 197001010000.00 {} +
## Base image with cargo-chef and the right cross-compilation toolchain ##
# cargo-chef helps with caching dependencies between builds
# The image Debian base name (bullseye) must be in sync with the runtime variant (debian11)
FROM --platform=${BUILDPLATFORM} docker.io/library/rust:${RUSTC_VERSION}-slim-bullseye AS chef
FROM --platform=${BUILDPLATFORM} docker.io/library/rust:${RUSTC_VERSION}-slim-${DEBIAN_VERSION_NAME} AS chef
# Install x86_64 and aarch64 cross-compiling stack
RUN apt update && apt install -y --no-install-recommends \
@@ -60,6 +75,7 @@ RUN cargo chef cook \
# Build the rest
COPY . .
COPY --from=static-files /app/crates/static-files/public /app/crates/static-files/public
RUN cargo build \
--release \
--bin mas-cli \
@@ -68,8 +84,12 @@ RUN cargo build \
# Move the binary to avoid having to guess its name in the next stage
RUN mv target/$(/docker-arch-to-rust-target.sh "${TARGETPLATFORM}")/release/mas-cli /mas-cli
## Runtime stage ##
# The image Debian base name (bullseye) must be in sync with the runtime variant (debian11)
FROM --platform=${TARGETPLATFORM} gcr.io/distroless/cc-debian11:nonroot
## Runtime stage, debug variant ##
FROM --platform=${TARGETPLATFORM} gcr.io/distroless/cc-debian${DEBIAN_VERSION}:debug-nonroot AS debug
COPY --from=builder /mas-cli /mas-cli
ENTRYPOINT ["/mas-cli"]
## Runtime stage ##
FROM --platform=${TARGETPLATFORM} gcr.io/distroless/cc-debian${DEBIAN_VERSION}:nonroot
COPY --from=builder /mas-cli /mas-cli
ENTRYPOINT ["/mas-cli"]