Fixed broken Docker image
parent
35fc9be5da
commit
82b2927b33
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "rust-api"
|
||||
version = "0.1.0"
|
||||
name = "fej"
|
||||
version = "0.0.1"
|
||||
authors = ["Jef Roosens <roosensjef@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
|
|
30
Dockerfile
30
Dockerfile
|
@ -1,28 +1,32 @@
|
|||
# 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"
|
||||
|
||||
# Switch to the nightly build
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Install build dependencies, install rustup & create dummy project
|
||||
# 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; } && \
|
||||
rustup target add x86_64-unknown-linux-musl
|
||||
{ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly; }
|
||||
|
||||
# Build the dependencies
|
||||
# This is done separately to reduce average compile time
|
||||
# Afterwards, we remove the dummy src directory
|
||||
# Now, we build our own source code
|
||||
# Copy source code over to builder
|
||||
COPY Cargo.toml Cargo.lock ./
|
||||
COPY src/ ./src/
|
||||
RUN cargo build --release --target x86_64-unknown-linux-musl
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
# Now, we create the actual image
|
||||
FROM scratch
|
||||
FROM alpine:latest
|
||||
|
||||
# Install dependencies
|
||||
COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/rust-api /rust-api
|
||||
# Install some dynamic libraries needed for everything to work
|
||||
RUN apk update && apk add --no-cache openssl libgcc
|
||||
|
||||
CMD ["/rust-api"]
|
||||
# Copy binary over to final image
|
||||
COPY --from=builder /usr/src/app/target/release/fej /usr/local/bin/fej
|
||||
|
||||
CMD ["/usr/local/bin/fej"]
|
||||
|
|
Loading…
Reference in New Issue