Skip to content

Commit 95b22df

Browse files
committed
enhancement: Update Dockerfile for web service to use Alpine Linux as base image and improve metadata
1 parent 3e15e49 commit 95b22df

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

web/Dockerfile

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,43 @@ FROM rust:1.55 AS builder
44
# Set the working directory
55
WORKDIR /usr/src/app
66

7-
# Copy the Cargo.toml and Cargo.lock files to the working directory
8-
COPY . .
7+
# Copy Cargo.toml and Cargo.lock and install dependencies
8+
COPY Cargo.toml Cargo.lock ./
9+
RUN cargo fetch
910

10-
# Build the Rust Frontend Service
11+
# Copy the rest of the code and build the application
12+
COPY . .
1113
RUN cargo build --release
1214

1315

1416
# Stage 2: Create a smaller image with only the build binary
15-
FROM debian:buster-slim
17+
FROM alpine:3.14
18+
19+
# Add metadata
20+
LABEL maintainer="Levi McDonough <levimcdonough@gmail.com>"
21+
LABEL version="1.0"
22+
LABEL description="The web service for the refactor platoform project."
23+
24+
# Install necessary runtime dependencies
25+
RUN apk add --no-cache ca-certificates
26+
27+
# Create a non-root user and group
28+
RUN addgroup -S appgroup && adduser -S refactoruser -G refactorgroup
29+
30+
# Set the working directory
31+
WORKDIR /app
1632

1733
# Copy the binary from the build stage to the working directory
18-
COPY --from=builder /usr/src/app/target/release/app /usr/local/bin/app
34+
COPY --from=builer /usr/src/app/target/release/app .
1935

20-
# Expose the port that the application listens on
36+
# Change ownership of the binary to the non-root user
37+
RUN chown refactoruser:refactorgroup /app/app
38+
39+
# Expose the port that the app listens on
2140
EXPOSE 8000
2241

42+
# Switch to the non-root user
43+
USER refactoruser
44+
2345
# Set the command to run the application
24-
CMD ["app"]
46+
CMD ["./app"]

0 commit comments

Comments
 (0)