2024-09-16 12:39:06 +02:00
|
|
|
####################################################################################################
|
|
|
|
## Builder
|
|
|
|
####################################################################################################
|
|
|
|
FROM rust:1-alpine3.19
|
|
|
|
# This is important, see https://github.com/rust-lang/docker-rust/issues/85
|
|
|
|
ENV RUSTFLAGS="-C target-feature=-crt-static"
|
|
|
|
|
|
|
|
RUN apk add --no-cache musl-dev
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
COPY ./ /app
|
|
|
|
|
|
|
|
RUN cargo build --release
|
|
|
|
RUN strip target/release/small-rust
|
|
|
|
|
|
|
|
####################################################################################################
|
|
|
|
## Final image
|
|
|
|
####################################################################################################
|
|
|
|
FROM alpine:3.19
|
|
|
|
|
|
|
|
RUN apk add --no-cache libgcc
|
|
|
|
|
|
|
|
COPY --from=0 /app/target/release/small-rust .
|
|
|
|
|
|
|
|
ENTRYPOINT ["/small-rust"]
|
|
|
|
|
|
|
|
|
|
|
|
####################################################################################################
|
|
|
|
## Alternatively use this builder
|
|
|
|
####################################################################################################
|
|
|
|
#FROM rust:latest AS builder
|
|
|
|
#
|
|
|
|
#RUN rustup target add x86_64-unknown-linux-musl
|
|
|
|
#RUN apt update && apt install -y musl-tools musl-dev
|
|
|
|
#RUN update-ca-certificates
|
|
|
|
#
|
|
|
|
## Create appuser
|
2024-09-16 12:39:06 +02:00
|
|
|
#ENV USER=small-rust
|
2024-09-16 12:39:06 +02:00
|
|
|
#ENV UID=10001
|
|
|
|
#
|
|
|
|
#RUN adduser \
|
|
|
|
# --disabled-password \
|
|
|
|
# --gecos "" \
|
|
|
|
# --home "/nonexistent" \
|
|
|
|
# --shell "/sbin/nologin" \
|
|
|
|
# --no-create-home \
|
|
|
|
# --uid "${UID}" \
|
|
|
|
# "${USER}"
|
|
|
|
#
|
|
|
|
#
|
2024-09-16 12:39:06 +02:00
|
|
|
#WORKDIR /app
|
2024-09-16 12:39:06 +02:00
|
|
|
#
|
|
|
|
#COPY ./ .
|
|
|
|
#
|
|
|
|
#RUN cargo build --target x86_64-unknown-linux-musl --release
|