Skip to content

Commit

Permalink
add Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
carderne committed Jul 10, 2024
1 parent b15f57e commit 78582bd
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Exclude python code
py

# General ignore stuff
.git
.github
.gitignore
.pdm-build
.pytest_cache
.python-version
.ruff_cache
.venv

# Project files
LICENSE
Makefile
pyproject.toml
requirements.lock
requirements-dev.lock

*.md
*.yml

# Python and Rust build outputs
dist
target
48 changes: 48 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
ARG PG_MAJOR=16

# ##################################
# builder image
# ##################################
FROM postgres:${PG_MAJOR} AS builder

RUN apt-get -y update && \
apt-get install -y --no-install-recommends \
pkg-config \
cmake \
ca-certificates \
git \
build-essential \
libpq-dev \
postgresql-server-dev-${PG_MAJOR} \
curl \
libreadline6-dev \
zlib1g-dev

ENV HOME=/home/builder
ENV PATH=/home/builder/.cargo/bin:$PATH
WORKDIR /home/builder

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --profile minimal --default-toolchain 1.79.0
RUN cargo install cargo-pgrx --version 0.11.4 --locked
RUN cargo pgrx init --pg${PG_MAJOR} $(which pg_config)

COPY .cargo .cargo
COPY Cargo.lock Cargo.lock
COPY Cargo.toml Cargo.toml
COPY upid_pg upid_pg
COPY upid_rs upid_rs
RUN cargo pgrx install --package upid_pg

# ##################################
# runner image
# ##################################
FROM postgres:${PG_MAJOR} AS runner

COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/extension /usr/share/postgresql/${PG_MAJOR}/extension
COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib /usr/lib/postgresql/${PG_MAJOR}/lib

RUN chown -R postgres:postgres /usr/share/postgresql/${PG_MAJOR}/extension
RUN chown -R postgres:postgres /usr/lib/postgresql/${PG_MAJOR}/lib

USER postgres
ENV USER=postgres
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ pgrx install
pgrx run
```

Alternatively, you can try out the Docker image `[carderne/postgres-upid:16](https://hub.docker.com/r/carderne/postgres-upid):
```bash
docker run -e POSTGRES_HOST_AUTH_METHOD=trust -p 5432:5432 carderne/postgres-upid:16
```

#### Usage
```sql
CREATE EXTENSION ulid;
Expand Down

0 comments on commit 78582bd

Please sign in to comment.