diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5deddd1 --- /dev/null +++ b/.dockerignore @@ -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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b6983dc --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/README.md b/README.md index 0332b6e..52972f1 100644 --- a/README.md +++ b/README.md @@ -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;