2021-04-08 23:56:08 +02:00
|
|
|
# syntax = docker/dockerfile:1.2
|
|
|
|
|
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
|
|
|
|
2021-04-08 22:39:04 +02:00
|
|
|
# Run the tests, don't want no broken docker image
|
|
|
|
# And then finally, build the project
|
2021-03-23 00:08:54 +01:00
|
|
|
# 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
|
2021-04-08 23:56:08 +02:00
|
|
|
RUN --mount=type=cache,target=/usr/src/app/target RUSTFLAGS="-C target-feature=-crt-static" cargo test && \
|
|
|
|
RUSTFLAGS="-C target-feature=-crt-static" cargo install --path . --bin fej --root /usr/local/bin
|
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
|
2021-04-08 23:56:08 +02:00
|
|
|
COPY --from=builder /usr/local/bin/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"]
|