This commit is contained in:
Vivek Revankar 2024-10-01 03:10:14 +00:00
parent b3e2d1f9fd
commit 29c2111ab4
2 changed files with 13 additions and 14 deletions

View file

@ -13,12 +13,12 @@ WORKDIR /redlib
# download (most) dependencies in their own layer
COPY Cargo.lock Cargo.toml ./
RUN mkdir src && echo "fn main() { panic!(\"why am i running?\") }" > src/main.rs
RUN cargo fetch
RUN cargo build --release --locked --bin redlib
RUN rm ./src/main.rs && rmdir ./src
# copy the source and build the redlib binary
COPY . ./
RUN cargo install --path .
RUN cargo build --release --locked --bin redlib
RUN echo "finished building redlib!"
########################
@ -26,12 +26,8 @@ RUN echo "finished building redlib!"
########################
FROM alpine:${ALPINE_VERSION} AS release
# Import ca-certificates from builder
COPY --from=builder /usr/share/ca-certificates /usr/share/ca-certificates
COPY --from=builder /etc/ssl/certs /etc/ssl/certs
# Import redlib binary from builder
COPY --from=builder /usr/local/cargo/bin/redlib /usr/local/bin/redlib
COPY --from=builder /redlib/target/release/redlib /usr/local/bin/redlib
# Add non-root user for running redlib
RUN adduser --home /nonexistent --no-create-home --disabled-password redlib

View file

@ -12,12 +12,12 @@ WORKDIR /redlib
# download (most) dependencies in their own layer
COPY Cargo.lock Cargo.toml ./
RUN mkdir src && echo "fn main() { panic!(\"why am i running?\") }" > src/main.rs
RUN cargo fetch
RUN cargo build --release --locked --bin redlib
RUN rm ./src/main.rs && rmdir ./src
# copy the source and build the redlib binary
COPY . ./
RUN cargo install --path .
RUN cargo build --release --locked --bin redlib
RUN echo "finished building redlib!"
########################
@ -25,15 +25,18 @@ RUN echo "finished building redlib!"
########################
FROM ubuntu:${UBUNTU_RELEASE_VERSION} AS release
# Import ca-certificates from builder
COPY --from=builder /usr/share/ca-certificates /usr/share/ca-certificates
COPY --from=builder /etc/ssl/certs /etc/ssl/certs
# Install ca-certificates
RUN apt-get update && apt-get install -y ca-certificates
# Import redlib binary from builder
COPY --from=builder /usr/local/cargo/bin/redlib /usr/local/bin/redlib
COPY --from=builder /redlib/target/release/redlib /usr/local/bin/redlib
# Add non-root user for running redlib
RUN adduser --no-create-home --disabled-password redlib
RUN useradd \
--no-create-home \
--password "!" \
--comment "user for running redlib" \
redlib
USER redlib
# Document that we intend to expose port 8080 to whoever runs the container