fej/Dockerfile

33 lines
1.1 KiB
Docker
Raw Normal View History

2021-03-23 00:08:54 +01:00
# We use a multi-stage build to end up with a very small final image
2021-03-22 16:36:01 +01:00
FROM alpine:latest AS builder
2021-03-13 11:53:33 +01:00
2021-03-22 16:36:01 +01:00
ENV PATH "$PATH:/root/.cargo/bin"
2021-03-05 20:40:49 +01:00
WORKDIR /usr/src/app
2021-03-23 00:08:54 +01:00
# Install build dependencies, rustup & rust's nightly build & toolchain
2021-03-22 16:36:01 +01:00
RUN apk update && apk add --no-cache openssl-dev build-base curl && \
2021-03-23 00:08:54 +01:00
{ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly; }
2021-03-13 11:53:33 +01:00
2021-03-23 00:08:54 +01:00
# Copy source code over to builder
2021-03-22 16:36:01 +01:00
COPY Cargo.toml Cargo.lock ./
COPY src/ ./src/
2021-03-23 00:08:54 +01:00
# 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 build --release
2021-03-05 20:40:49 +01:00
2021-03-13 11:53:33 +01:00
# Now, we create the actual image
2021-03-23 00:08:54 +01:00
FROM alpine:latest
# Install some dynamic libraries needed for everything to work
RUN apk update && apk add --no-cache openssl libgcc
2021-03-05 20:40:49 +01:00
2021-03-23 00:08:54 +01:00
# Copy binary over to final image
COPY --from=builder /usr/src/app/target/release/fej /usr/local/bin/fej
2021-03-05 20:40:49 +01:00
2021-03-23 00:08:54 +01:00
CMD ["/usr/local/bin/fej"]