Skip to content

Commit

Permalink
add new dockerfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
master-hax committed Sep 18, 2024
1 parent 3625fdf commit 77655e0
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# supported versions here: https://github.com/rust-lang/docker-rust/tree/9f287282d513a84cb7c7f38f197838f15d37b6a9/1.81.0
ARG ALPINE_VERSION=3.20

########################
## builder image
########################
FROM rust:alpine${ALPINE_VERSION} AS builder

RUN apk add --no-cache musl-dev

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 rm ./src/main.rs && rmdir ./src

# copy the source and build the redlib binary
COPY . ./
RUN cargo install --path .
RUN echo "finished building redlib!"

########################
## release image
########################
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

# Add non-root user for running redlib
RUN adduser --home /nonexistent --no-create-home --disabled-password redlib
USER redlib

# Document that we intend to expose port 8080 to whoever runs the container
EXPOSE 8080

# Run a healthcheck every minute to make sure redlib is functional
HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider --q http://localhost:8080/settings || exit 1

# Add container metadata
MAINTAINER sigaloid

CMD ["redlib"]
48 changes: 48 additions & 0 deletions Dockerfile.ubuntu
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# supported versions here: https://github.com/rust-lang/docker-rust/tree/9f287282d513a84cb7c7f38f197838f15d37b6a9/1.81.0
ARG RUST_BUILDER_VERSION=bookworm
ARG UBUNTU_RELEASE_VERSION=jammy

########################
## builder image
########################
FROM rust:${RUST_BUILDER_VERSION} AS builder

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 rm ./src/main.rs && rmdir ./src

# copy the source and build the redlib binary
COPY . ./
RUN cargo install --path .
RUN echo "finished building redlib!"

########################
## release image
########################
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

# Import redlib binary from builder
COPY --from=builder /usr/local/cargo/bin/redlib /usr/local/bin/redlib

# Add non-root user for running redlib
RUN adduser --no-create-home --disabled-password redlib
USER redlib

# Document that we intend to expose port 8080 to whoever runs the container
EXPOSE 8080

# Run a healthcheck every minute to make sure redlib is functional
HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider --q http://localhost:8080/settings || exit 1

# Add container metadata
MAINTAINER sigaloid

CMD ["redlib"]

0 comments on commit 77655e0

Please sign in to comment.