Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
59 lines (49 loc) · 2.51 KB
/
Copy pathDockerfile
File metadata and controls
59 lines (49 loc) · 2.51 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# cargo-pgrx must be the exact pgrx version in Cargo.lock (BUG-007). This
# stage reads that version out of the lockfile; the main stage copies only the
# one-line result, so the cargo-pgrx install layer stays cached until the pgrx
# version itself changes, not on every lockfile change.
FROM rust:1.99-bookworm AS pgrx-version
COPY Cargo.lock /
RUN awk '$0 == "name = \"pgrx\"" { getline; gsub(/version = |"/, ""); print }' /Cargo.lock > /pgrx-version \
&& test "$(wc -l < /pgrx-version)" -eq 1
# dsntk 0.3 uses let-chains (stable since Rust 1.88)
FROM rust:1.99-bookworm
# Install PostgreSQL 17 and build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
postgresql-common gnupg2 \
&& /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y \
&& apt-get update && apt-get install -y --no-install-recommends \
postgresql-17 \
postgresql-server-dev-17 \
libclang-dev \
clang \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
# pgrx tests must run as a non-root user (initdb refuses root). Create that
# user and hand it the PG install dirs and its own CARGO_HOME up front, so
# every later step (toolchain components, crate fetch, pgrx init) is owned
# by pgdmn by construction—see BUG-001 and BUG-002 in BUGHISTORY.md.
RUN useradd -ms /bin/bash pgdmn \
&& chown -R pgdmn /usr/share/postgresql/17/extension /usr/lib/postgresql/17/lib
ENV CARGO_HOME=/home/pgdmn/.cargo \
PATH=/home/pgdmn/.cargo/bin:$PATH
USER pgdmn
WORKDIR /pgdmn
# Install cargo-pgrx at exactly the lockfile's pgrx version
COPY --from=pgrx-version /pgrx-version /tmp/pgrx-version
RUN cargo install cargo-pgrx --version "=$(cat /tmp/pgrx-version)" --locked
# Lint and format tooling for `make lint` / `make fmt`
RUN rustup component add clippy rustfmt
# pgrx init reads nothing from the project manifests (its state lives in
# ~/.pgrx), so it sits above the COPY to stay cached across dependency bumps
RUN cargo pgrx init --pg17=/usr/lib/postgresql/17/bin/pg_config
# Copy manifests first for layer caching; vendor/ holds the patched dsntk
# sources referenced by [patch.crates-io], needed for dependency resolution
COPY --chown=pgdmn:pgdmn Cargo.toml Cargo.lock pgdmn.control ./
COPY --chown=pgdmn:pgdmn vendor ./vendor
# Create stub lib.rs so cargo fetch works
RUN mkdir -p src && echo '::pgrx::pg_module_magic!();' > src/lib.rs
# Fetch dependencies into pgdmn's own registry cache
RUN cargo fetch --locked
# Default: build and test (the repo is bind-mounted at /pgdmn by `make`)
CMD ["cargo", "pgrx", "test", "pg17"]