@@ -4,21 +4,43 @@ FROM rust:1.55 AS builder
4
4
# Set the working directory
5
5
WORKDIR /usr/src/app
6
6
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
9
10
10
- # Build the Rust Frontend Service
11
+ # Copy the rest of the code and build the application
12
+ COPY . .
11
13
RUN cargo build --release
12
14
13
15
14
16
# 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
16
32
17
33
# 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 .
19
35
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
21
40
EXPOSE 8000
22
41
42
+ # Switch to the non-root user
43
+ USER refactoruser
44
+
23
45
# Set the command to run the application
24
- CMD ["app" ]
46
+ CMD ["./ app" ]
0 commit comments