Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
FROM rust:1.81.0-slim-bookworm AS builder
FROM rust:1.88.0-slim-trixie AS builder

RUN apt-get update && \
apt-get install -y build-essential
apt-get install -y --no-install-recommends build-essential && \
rm -rf /var/lib/apt/lists/*

COPY . /app
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:bookworm-slim
RUN apt-get update && apt-get install -o Dpkg::Options::=--force-confdef -yq --no-install-recommends \
postgresql-client \
# Clean up layer
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& truncate -s 0 /var/log/*log
COPY --from=builder /app/target/release/pgcat /usr/bin/pgcat
COPY --from=builder /app/pgcat.toml /etc/pgcat/pgcat.toml
################################################################################

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
4 changes: 2 additions & 2 deletions Dockerfile.ci
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM cimg/rust:1.81.0
FROM cimg/rust:1.88.0
COPY --from=sclevine/yj /bin/yj /bin/yj
RUN /bin/yj -h
RUN sudo apt-get update && \
sudo apt-get install -y \
psmisc postgresql-contrib-14 postgresql-client-14 libpq-dev \
ruby ruby-dev python3 python3-pip \
lcov llvm-11 iproute2 && \
lcov llvm-19 iproute2 && \
sudo apt-get upgrade curl && \
cargo install cargo-binutils rustfilt && \
rustup component add llvm-tools-preview && \
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json
# Build application
COPY . .
RUN cargo build

FROM debian:bookworm-slim
FROM debian:trixie-slim
COPY --from=builder /app/target/release/pgcat /usr/bin/pgcat
COPY --from=builder /app/pgcat.toml /etc/pgcat/pgcat.toml
WORKDIR /etc/pgcat
Expand Down
4 changes: 2 additions & 2 deletions dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM rust:bullseye
FROM rust:trixie

# Dependencies
COPY --from=sclevine/yj /bin/yj /bin/yj
RUN /bin/yj -h
RUN apt-get update -y \
&& apt-get install -y \
llvm-11 psmisc postgresql-contrib postgresql-client \
wget llvm-19 psmisc postgresql-contrib postgresql-client \
ruby ruby-dev libpq-dev python3 python3-pip lcov curl sudo iproute2 \
strace ngrep iproute2 dnsutils lsof net-tools telnet

Expand Down
4 changes: 2 additions & 2 deletions tests/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM rust:1.81.0-slim-bookworm
FROM rust:1.88.0-slim-trixie

COPY --from=sclevine/yj /bin/yj /bin/yj
RUN /bin/yj -h
RUN apt-get update && apt-get install llvm-11 psmisc postgresql-contrib postgresql-client ruby ruby-dev libpq-dev python3 python3-pip lcov curl sudo iproute2 -y
RUN apt-get update && apt-get install wget llvm-19 psmisc postgresql-contrib postgresql-client ruby ruby-dev libpq-dev python3 python3-pip lcov curl sudo iproute2 -y
RUN cargo install cargo-binutils rustfilt
RUN rustup component add llvm-tools-preview
RUN sudo gem install bundler
Expand Down