Files
stl/Dockerfile

79 lines
1.8 KiB
Docker

##################
### BASE STAGE ###
##################
FROM rust:1.53 as base
# Install build dependencies
RUN cargo install strip_cargo_version
RUN rustup target add x86_64-unknown-linux-musl
WORKDIR /app
RUN mkdir cli lib server
###########################
### STRIP-VERSION STAGE ###
###########################
FROM base as strip-version
# Strip version from Cargo.*
# This avoids cache invalidations (ergo rebuilding all deps) when bumping the version number
COPY Cargo.lock Cargo.toml ./
COPY server/Cargo.toml ./server/
COPY cli/Cargo.toml ./cli/
COPY lib/Cargo.toml ./lib/
RUN strip_cargo_version
###################
### BUILD STAGE ###
###################
FROM base as build_stage
RUN cargo init --bin server
RUN cargo init --lib lib
# Create a dummy binary for pre-compiling dependencies (for caching)
COPY --from=strip-version /app/server/Cargo.toml /app/server/
COPY --from=strip-version /app/lib/Cargo.toml /app/lib/
COPY --from=strip-version /app/cli/Cargo.toml /app/cli/
COPY --from=strip-version /app/Cargo.lock /app/Cargo.toml /app/
WORKDIR /app/server
RUN cargo build --release --target x86_64-unknown-linux-musl
# Copy actual source files
WORKDIR /app
COPY . .
# Compile final binary
WORKDIR /app/server
RUN cargo build --release --target x86_64-unknown-linux-musl
RUN strip /app/target/x86_64-unknown-linux-musl/release/stl
########################
### PRODUCTION STAGE ###
########################
FROM scratch
# Default to staging environment
# Override with "production" when deploying for real
ENV ROCKET_ENV="staging"
ENV ROCKET_TEMPLATE_DIR="/templates"
ENV DB_PATH="/database"
VOLUME "/database"
WORKDIR /
# Copy static files
COPY server/templates templates
COPY server/static static
# Copy application binary
COPY --from=build_stage /app/target/x86_64-unknown-linux-musl/release/stl stl
CMD ["/stl"]