diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index 065c4bb..bfdf521 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -16,20 +16,17 @@ jobs: build: strategy: matrix: - postgres_version: [13, 14, 15, 16, 17] + postgres_version: [14, 15, 16, 17] major: [4,5] include: - partman_version: v4.7.4 partman_checksum: 28e4fdb83ecc16525959ae9593bfbfd077db429285f5f7d8e2468bfff6cbdbf2c81ace79a9ddeb4f00f51eb709163dbd713fe6b221a432ac2ff766f98d4cf8e4 - default: "true" + default: "false" major: 4 - partman_version: v5.2.4 partman_checksum: 8328a00ce1a55a5c9173d4adbf251e784fed62413fb76bba89dd893749a720a5ecb25ee668eb0b826b8e1f2b89d9dd7da219fd797bfd9ab1a43d05f5b3ac494f - default: "false" + default: "true" major: 5 - exclude: - - major: 5 - postgres_version: 13 # partman 5.x does not support postgres 13 runs-on: ubuntu-latest permissions: contents: read @@ -63,7 +60,7 @@ jobs: with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | - type=raw,value=latest,enable=${{ matrix.postgres_version == '15' && matrix.default == 'true' }} + type=raw,value=latest,enable=${{ matrix.postgres_version == '17' && matrix.default == 'true' }} type=raw,value=${{ matrix.postgres_version }},enable=${{ matrix.default == 'true'}} ${{ matrix.postgres_version }}-${{ matrix.major }} diff --git a/Dockerfile b/Dockerfile index 3d97f60..4c94673 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ -ARG POSTGRESQL_VERSION="16" +ARG POSTGRESQL_VERSION="17" ARG JOBMON_VERSION="v1.4.1" ARG PARTMAN_VERSION="v5.2.4" -FROM bitnami/postgresql:$POSTGRESQL_VERSION AS builder +FROM postgres:$POSTGRESQL_VERSION-alpine AS builder LABEL org.opencontainers.image.source="https://github.com/dbsystel/postgresql-partman-container" ARG JOBMON_VERSION LABEL de.dbsystel.jobmon-version=$JOBMON_VERSION @@ -14,24 +14,21 @@ ARG JOBMON_CHECKSUM="db67c068ecdc136305eafb25bd8fc737f6b9944d4ef3d59ecf700693368 ARG PARTMAN_CHECKSUM="8328a00ce1a55a5c9173d4adbf251e784fed62413fb76bba89dd893749a720a5ecb25ee668eb0b826b8e1f2b89d9dd7da219fd797bfd9ab1a43d05f5b3ac494f" USER root -RUN install_packages wget gcc make build-essential \ - && export C_INCLUDE_PATH=/opt/bitnami/postgresql/include/:/opt/bitnami/common/include/ \ - && export LIBRARY_PATH=/opt/bitnami/postgresql/lib/:/opt/bitnami/common/lib/ \ - && export LD_LIBRARY_PATH=/opt/bitnami/postgresql/lib/:/opt/bitnami/common/lib/ +RUN apk add --no-cache wget gcc make musl-dev postgresql-dev $DOCKER_PG_LLVM_DEPS RUN wget "https://github.com/omniti-labs/pg_jobmon/archive/refs/tags/${JOBMON_VERSION}.tar.gz" \ - && echo "${JOBMON_CHECKSUM} ${JOBMON_VERSION}.tar.gz" | sha512sum --check \ + && echo "${JOBMON_CHECKSUM} ${JOBMON_VERSION}.tar.gz" | sha512sum -c \ && tar zxf ${JOBMON_VERSION}.tar.gz && cd pg_jobmon-${JOBMON_VERSION#v}\ && make \ && make install RUN wget "https://github.com/pgpartman/pg_partman/archive/refs/tags/${PARTMAN_VERSION}.tar.gz" \ - && echo "${PARTMAN_CHECKSUM} ${PARTMAN_VERSION}.tar.gz" | sha512sum --check \ + && echo "${PARTMAN_CHECKSUM} ${PARTMAN_VERSION}.tar.gz" | sha512sum -c \ && tar zxf ${PARTMAN_VERSION}.tar.gz && cd pg_partman-${PARTMAN_VERSION#v}\ && make \ && make install -FROM bitnami/postgresql:$POSTGRESQL_VERSION +FROM postgres:$POSTGRESQL_VERSION-alpine LABEL org.opencontainers.image.source="https://github.com/dbsystel/postgresql-partman-container" ARG JOBMON_VERSION LABEL de.dbsystel.jobmon-version=$JOBMON_VERSION @@ -40,8 +37,9 @@ LABEL de.dbsystel.partman-version=$PARTMAN_VERSION ARG POSTGRESQL_VERSION LABEL de.dbsystel.postgres-version=$POSTGRESQL_VERSION -COPY --from=builder pg_jobmon-${JOBMON_VERSION#v}/sql/pg_jobmon--${JOBMON_VERSION#v}.sql pg_jobmon-${JOBMON_VERSION#v}/pg_jobmon.control pg_partman-${PARTMAN_VERSION#v}/sql/pg_partman--${PARTMAN_VERSION#v}.sql pg_partman-${PARTMAN_VERSION#v}/pg_partman.control /opt/bitnami/postgresql/share/extension/ -COPY --from=builder /opt/bitnami/postgresql/lib/pg_partman_bgw.so /opt/bitnami/postgresql/lib/pg_partman_bgw.so -COPY --from=builder pg_partman-${PARTMAN_VERSION#v}/bin/common/* /opt/bitnami/lib/postgresql/bin/ +COPY --from=builder /usr/local/share/postgresql/extension/pg_jobmon* /usr/local/share/postgresql/extension/ +COPY --from=builder /usr/local/share/postgresql/extension/pg_partman* /usr/local/share/postgresql/extension/ +COPY --from=builder /usr/local/lib/postgresql/pg_partman_bgw.so /usr/local/lib/postgresql/ +COPY --from=builder pg_partman-*/bin/common/* /usr/local/bin/ -USER 1001 +USER postgres diff --git a/README.md b/README.md index 920101f..3b68a8e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # PostgreSQL container image with pg_partman -This repo is meant to provide an OCI (Docker) container image that is based on the popular [bitnami/postgresql](https://hub.docker.com/r/bitnami/postgresql) image, that comes preinstalled with the [pg_partman](https://github.com/pgpartman/pg_partman) and [pg_jobmon](https://github.com/omniti-labs/pg_jobmon) PostgreSQL extensions. +This repo is meant to provide an OCI (Docker) container image that is based on the official [postgres](https://hub.docker.com/_/postgres) image in the alpine variant, that comes preinstalled with the [pg_partman](https://github.com/pgpartman/pg_partman) and [pg_jobmon](https://github.com/omniti-labs/pg_jobmon) PostgreSQL extensions. It pushes a nightly latest image of all tag versions to [ghcr.io](https://github.com/orgs/dbsystel/packages/container/package/postgresql-partman) @@ -8,8 +8,8 @@ It pushes a nightly latest image of all tag versions to [ghcr.io](https://github ```shell docker run ghcr.io/dbsystel/postgresql-partman -docker run ghcr.io/dbsystel/postgresql-partman:{13,14,15,16,17} -docker run ghcr.io/dbsystel/postgresql-partman:{13-4,14-4,15-4,16-4,17-4} +docker run ghcr.io/dbsystel/postgresql-partman:{14,15,16,17} +docker run ghcr.io/dbsystel/postgresql-partman:{14-4,15-4,16-4,17-4} docker run ghcr.io/dbsystel/postgresql-partman:{14-5,15-5,16-5,17-5} ``` @@ -17,13 +17,25 @@ The first part of the tag represents the PostgreSQL major version, the second pa You can find out the actual versions used by looking at the labels of an image. -`docker inspect ghcr.io/dbsystel/postgresql-partman:13` +`docker inspect ghcr.io/dbsystel/postgresql-partman:17` ```` - "de.dbsystel.partman-version" : "v4.7.4", - "de.dbsystel.postgres-version" : "13", + "de.dbsystel.partman-version" : "v5.2.4", + "de.dbsystel.postgres-version" : "17", ```` +## Development + +### test-build.sh + +The `test-build.sh` script builds all PostgreSQL and partman version combinations locally for testing purposes. It extracts version information from the GitHub workflow to ensure consistency. + +```shell +./test-build.sh +``` + +This builds Docker images for all supported PostgreSQL versions with both partman v4 and v5, tagged as `test-partman:{pg_version}-{partman_major}`. + ## License This project is licensed under the Apache-2.0 license, see [LICENSE](LICENSE). diff --git a/test-build.sh b/test-build.sh new file mode 100755 index 0000000..74df922 --- /dev/null +++ b/test-build.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Test build script for all PostgreSQL versions and partman combinations +# Extracts versions and checksums from GitHub workflow to stay DRY + +set -e + +# Extract data from workflow file +WORKFLOW_FILE=".github/workflows/build-and-publish.yml" + +# Parse PostgreSQL versions +POSTGRES_VERSIONS=($(yq '.jobs.build.strategy.matrix.postgres_version[]' $WORKFLOW_FILE)) + +# Parse partman versions and checksums +PARTMAN_V4_VERSION=$(yq '.jobs.build.strategy.matrix.include[] | select(.major == 4) | .partman_version' $WORKFLOW_FILE) +PARTMAN_V4_CHECKSUM=$(yq '.jobs.build.strategy.matrix.include[] | select(.major == 4) | .partman_checksum' $WORKFLOW_FILE) +PARTMAN_V5_VERSION=$(yq '.jobs.build.strategy.matrix.include[] | select(.major == 5) | .partman_version' $WORKFLOW_FILE) +PARTMAN_V5_CHECKSUM=$(yq '.jobs.build.strategy.matrix.include[] | select(.major == 5) | .partman_checksum' $WORKFLOW_FILE) + +for pg_version in "${POSTGRES_VERSIONS[@]}"; do + echo "Building PostgreSQL $pg_version with partman v5..." + docker build \ + --build-arg POSTGRESQL_VERSION=$pg_version \ + --build-arg PARTMAN_VERSION=$PARTMAN_V5_VERSION \ + --build-arg PARTMAN_CHECKSUM=$PARTMAN_V5_CHECKSUM \ + -t test-partman:$pg_version-5 . + + echo "Building PostgreSQL $pg_version with partman v4..." + docker build \ + --build-arg POSTGRESQL_VERSION=$pg_version \ + --build-arg PARTMAN_VERSION=$PARTMAN_V4_VERSION \ + --build-arg PARTMAN_CHECKSUM=$PARTMAN_V4_CHECKSUM \ + -t test-partman:$pg_version-4 . +done + +echo "All builds completed successfully!"