2021-04-17 13:46:38 +02:00
|
|
|
# vim: filetype=dockerfile
|
2021-04-13 21:43:30 +02:00
|
|
|
# Our entire toolchain runs in alpine
|
2021-04-12 17:39:52 +02:00
|
|
|
FROM alpine:latest AS builder
|
|
|
|
|
2021-04-17 13:46:38 +02:00
|
|
|
ENV PATH "$PATH:/app/.cargo/bin"
|
2021-04-13 21:43:30 +02:00
|
|
|
# Needed for proper compiling of openssl-dev
|
|
|
|
ENV RUSTFLAGS "-C target-feature=-crt-static"
|
2021-04-12 17:39:52 +02:00
|
|
|
|
2021-04-17 13:46:38 +02:00
|
|
|
# Add the build user
|
|
|
|
# Install dependencies
|
|
|
|
RUN addgroup -S builder && \
|
|
|
|
adduser -S builder -G builder -h /app && \
|
|
|
|
apk update && \
|
|
|
|
apk add --no-cache \
|
|
|
|
curl \
|
|
|
|
gcc \
|
|
|
|
libgcc \
|
|
|
|
musl-dev \
|
|
|
|
openssl-dev \
|
|
|
|
postgresql-dev
|
2021-04-12 17:39:52 +02:00
|
|
|
|
2021-04-17 13:46:38 +02:00
|
|
|
# Switch to the non-root user
|
|
|
|
USER builder
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
# Install rustup in the new user's home
|
|
|
|
# Create mountpoints for volumes with correct permissions
|
|
|
|
RUN { curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly; } && \
|
|
|
|
rustup target add x86_64-unknown-linux-musl --toolchain nightly && \
|
|
|
|
mkdir -p .cargo/registry target
|
2021-04-12 17:39:52 +02:00
|
|
|
|
|
|
|
# Copy source code over to builder
|
2021-04-17 13:46:38 +02:00
|
|
|
COPY --chown=builder:builder Cargo.toml Cargo.lock ./
|
|
|
|
COPY --chown=builder:builder src/ ./src/
|
2021-04-17 14:43:24 +02:00
|
|
|
COPY --chown=builder:builder migrations/ ./migrations/
|