-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathDockerfile
More file actions
42 lines (31 loc) · 1.19 KB
/
Dockerfile
File metadata and controls
42 lines (31 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
FROM rust:1.88.0-slim-trixie AS builder
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Cache Rust dependencies separately,
# avoiding rebuilding the layer on every source code change
# This layer is only rebuilt when Cargo.toml or Cargo.lock changes.
COPY Cargo.toml Cargo.lock ./
RUN cargo fetch
COPY . .
RUN cargo build --release
################################################################################
FROM debian:trixie-slim
RUN apt-get update && \
apt-get install -y --no-install-recommends postgresql-client && \
# Create a non-root user for security
groupadd --system --gid 1001 appgroup && \
useradd --system --uid 1001 --gid appgroup appuser && \
# Clean up layer to reduce size
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
truncate -s 0 /var/log/*log
WORKDIR /etc/pgcat
RUN chown appuser:appgroup /etc/pgcat
USER appuser
COPY --from=builder --chown=appuser:appgroup /app/target/release/pgcat /usr/bin/pgcat
COPY --from=builder --chown=appuser:appgroup /app/pgcat.toml /etc/pgcat/pgcat.toml
ENV RUST_LOG=info
CMD ["pgcat"]
STOPSIGNAL SIGINT