Fixed broken Docker image

master
Jef Roosens 2021-03-23 00:08:54 +01:00
parent 35fc9be5da
commit 82b2927b33
Signed by: Jef Roosens
GPG Key ID: B580B976584B5F30
3 changed files with 20 additions and 16 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "rust-api" name = "fej"
version = "0.1.0" version = "0.0.1"
authors = ["Jef Roosens <roosensjef@gmail.com>"] authors = ["Jef Roosens <roosensjef@gmail.com>"]
edition = "2018" edition = "2018"

View File

@ -1,28 +1,32 @@
# We use a multi-stage build to end up with a very small final image
FROM alpine:latest AS builder FROM alpine:latest AS builder
ENV PATH "$PATH:/root/.cargo/bin" ENV PATH "$PATH:/root/.cargo/bin"
# Switch to the nightly build
WORKDIR /usr/src/app 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 && \ 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; } && \ { curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly; }
rustup target add x86_64-unknown-linux-musl
# Build the dependencies # Copy source code over to builder
# This is done separately to reduce average compile time
# Afterwards, we remove the dummy src directory
# Now, we build our own source code
COPY Cargo.toml Cargo.lock ./ COPY Cargo.toml Cargo.lock ./
COPY src/ ./src/ 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 # Now, we create the actual image
FROM scratch FROM alpine:latest
# Install dependencies # Install some dynamic libraries needed for everything to work
COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/rust-api /rust-api 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"]

View File

@ -1,5 +1,5 @@
IMAGE := chewingbever/fej IMAGE := chewingbever/fej
TAG := 0.1-dev TAG := 0.0.1-dev
shell := /bin/bash shell := /bin/bash