|
1 |
| -# Use the official Rust image as a parent image |
2 |
| -FROM rust:1.80 AS builder |
| 1 | +# Use the official Alpine-based Rust image as a parent image |
| 2 | +FROM rust:1.80-alpine AS builder |
3 | 3 |
|
4 | 4 | # Set the working directory in the container
|
5 | 5 | WORKDIR /usr/src/app
|
6 | 6 |
|
7 | 7 | # Install build dependencies
|
8 |
| -RUN apt update && apt install -y \ |
9 |
| - libssl-dev \ |
10 |
| - pkg-config \ |
11 |
| - && rm -rf /var/lib/apt/lists/* |
| 8 | +RUN apk add --no-cache \ |
| 9 | + musl-dev \ |
| 10 | + openssl-dev \ |
| 11 | + openssl-libs-static \ |
| 12 | + pkgconfig \ |
| 13 | + patch |
| 14 | + |
| 15 | +# Set environment variables for static linking |
| 16 | +ENV OPENSSL_STATIC=yes |
| 17 | +ENV OPENSSL_DIR=/usr |
12 | 18 |
|
13 | 19 | # Copy the current directory contents into the container
|
14 | 20 | COPY . .
|
15 | 21 |
|
16 |
| -# Build the application |
17 |
| -RUN cargo build --release |
| 22 | +# Determine the target architecture and build the application |
| 23 | +RUN RUST_TARGET=$(rustc -vV | sed -n 's/host: //p') && \ |
| 24 | + rustup target add $RUST_TARGET && \ |
| 25 | + RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --target $RUST_TARGET |
18 | 26 |
|
19 | 27 | # Stage for creating the non-privileged user
|
20 |
| -FROM debian:12.6-slim AS user-stage |
| 28 | +FROM alpine:3.20 AS user-stage |
21 | 29 |
|
22 |
| -RUN adduser --uid 10001 --system appuser |
| 30 | +RUN adduser -u 10001 -S appuser |
23 | 31 |
|
24 | 32 | # Stage for a smaller final image
|
25 | 33 | FROM scratch
|
26 | 34 |
|
27 |
| -# Copy necessary files from the builder stage |
28 |
| -COPY --from=builder /usr/src/app/target/release/inv_sig_helper_rust /app/inv_sig_helper_rust |
| 35 | +# Copy necessary files from the builder stage, using the correct architecture path |
| 36 | +COPY --from=builder /usr/src/app/target/*/release/inv_sig_helper_rust /app/inv_sig_helper_rust |
29 | 37 | COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
30 | 38 |
|
31 | 39 | # Copy passwd file for the non-privileged user from the user-stage
|
|
0 commit comments