2023-06-17 04:15:02 +00:00
|
|
|
FROM rust:alpine3.17 as builder
|
2023-06-16 05:15:12 +00:00
|
|
|
|
2023-07-22 05:48:33 +00:00
|
|
|
ARG RELEASE_BUILD=true
|
|
|
|
|
2023-06-16 05:15:12 +00:00
|
|
|
# update packages
|
|
|
|
RUN apk update
|
|
|
|
RUN apk add build-base openssl-dev ca-certificates
|
|
|
|
|
|
|
|
# create root application folder
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
COPY ./ /app/src
|
|
|
|
|
|
|
|
# Install rust toolchains
|
|
|
|
RUN rustup toolchain install stable
|
|
|
|
RUN rustup default stable
|
|
|
|
|
|
|
|
WORKDIR /app/src
|
|
|
|
|
|
|
|
# Build dependencies only. Separate these for caches
|
|
|
|
RUN cargo install cargo-build-deps
|
2023-07-23 21:32:55 +00:00
|
|
|
RUN sh -c "cargo build-deps --release"
|
2023-06-16 05:15:12 +00:00
|
|
|
|
|
|
|
# Build the release executable.
|
2023-07-23 21:32:55 +00:00
|
|
|
RUN sh -c "cargo build --release"
|
2023-06-16 05:15:12 +00:00
|
|
|
|
|
|
|
# Runner stage. I tried using distroless (gcr.io/distroless/static-debian11), but the image was only ~3MBs smaller than
|
2023-07-22 05:48:33 +00:00
|
|
|
# alpine. I chose to use alpine since it makes it easier to exec into the container to debug things.
|
2023-06-16 05:15:12 +00:00
|
|
|
FROM alpine:3.17
|
|
|
|
|
|
|
|
ARG UNAME=orca-registry
|
|
|
|
ARG UID=1000
|
|
|
|
ARG GID=1000
|
|
|
|
|
|
|
|
# Add user and copy the executable from the build stage.
|
|
|
|
RUN adduser --disabled-password --gecos "" $UNAME -s -G $GID -u $UID
|
|
|
|
COPY --from=builder --chown=$UID:$GID /app/src/target/release/orca-registry /app/orca-registry
|
|
|
|
|
2023-07-22 05:48:33 +00:00
|
|
|
# Chown everything
|
2023-06-17 04:55:12 +00:00
|
|
|
RUN mkdir /data && \
|
|
|
|
chown -R $UID:$GID /data && \
|
|
|
|
chown -R $UID:$GID /app
|
2023-06-16 05:15:12 +00:00
|
|
|
|
|
|
|
USER $UNAME
|
|
|
|
|
|
|
|
WORKDIR /app/
|
|
|
|
|
|
|
|
EXPOSE 3000
|
|
|
|
|
|
|
|
ENTRYPOINT [ "/app/orca-registry" ]
|