Skip to content

Commit d330e54

Browse files
committed
create separate Dockerfile to build with --debug
1 parent bb30bdb commit d330e54

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

Dockerfile.dev

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Development Dockerfile - builds debug version for faster iteration
2+
# supported versions here: https://hub.docker.com/_/rust
3+
ARG ALPINE_VERSION=3.20
4+
5+
########################
6+
## builder image
7+
########################
8+
FROM rust:alpine${ALPINE_VERSION} AS builder
9+
10+
RUN apk add --no-cache musl-dev
11+
12+
WORKDIR /redlib
13+
14+
# download (most) dependencies in their own layer
15+
COPY Cargo.lock Cargo.toml ./
16+
RUN mkdir src && echo "fn main() { panic!(\"why am i running?\") }" > src/main.rs
17+
RUN cargo build --locked --bin redlib
18+
RUN rm ./src/main.rs && rmdir ./src
19+
20+
# copy the source and build the redlib binary
21+
COPY . ./
22+
RUN cargo build --locked --bin redlib
23+
RUN echo "finished building redlib!"
24+
25+
########################
26+
## runtime image
27+
########################
28+
FROM alpine:${ALPINE_VERSION} AS runtime
29+
30+
# Import redlib binary from builder (debug build)
31+
COPY --from=builder /redlib/target/debug/redlib /usr/local/bin/redlib
32+
33+
# Add non-root user for running redlib
34+
RUN adduser --home /nonexistent --no-create-home --disabled-password redlib
35+
USER redlib
36+
37+
# Document that we intend to expose port 8080 to whoever runs the container
38+
EXPOSE 8080
39+
40+
# Run a healthcheck every minute to make sure redlib is functional
41+
HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider -q http://localhost:8080/settings || exit 1
42+
43+
# Add container metadata
44+
LABEL org.opencontainers.image.authors="sigaloid"
45+
46+
CMD ["redlib"]
47+

compose.dev.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ services:
44
redlib:
55
build:
66
context: .
7-
dockerfile: Dockerfile.alpine
7+
dockerfile: Dockerfile.dev
88
restart: always
99
container_name: "redlib"
1010
ports:

0 commit comments

Comments
 (0)