fej/Dockerfile

35 lines
1.2 KiB
Docker

# We use a multi-stage build to end up with a very small final image
FROM alpine:latest AS builder
ENV PATH "$PATH:/root/.cargo/bin"
WORKDIR /usr/src/app
# Install build dependencies, rustup & rust's nightly build & toolchain
RUN apk update && apk add --no-cache openssl-dev build-base curl && \
{ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly; }
# Copy source code over to builder
COPY Cargo.toml Cargo.lock ./
COPY src/ ./src/
# Run the tests, don't want no broken docker image
# And then finally, build the project
# Thank the lords that this article exists
# https://users.rust-lang.org/t/sigsegv-with-program-linked-against-openssl-in-an-alpine-container/52172
# TODO add what these flags do & why they work
RUN RUSTFLAGS="-C target-feature=-crt-static" cargo test && \
RUSTFLAGS="-C target-feature=-crt-static" cargo build --release --bin fej
# Now, we create the actual image
FROM alpine:latest
# Install some dynamic libraries needed for everything to work
RUN apk update && apk add --no-cache openssl libgcc
# Copy binary over to final image
COPY --from=builder /usr/src/app/target/release/fej /usr/local/bin/fej
CMD ["/usr/local/bin/fej"]