diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5f7893a..3d0b276 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,8 +4,8 @@ on: push: branches: - 'main' - # schedule: - # - cron: '15 5 * * 1' + schedule: + - cron: '15 5 * * 1' defaults: run: diff --git a/.github/workflows/pljava-dev.yml b/.github/workflows/pljava-dev.yml new file mode 100644 index 0000000..ab1b8a0 --- /dev/null +++ b/.github/workflows/pljava-dev.yml @@ -0,0 +1,45 @@ +name: Docker PostgreSQL pl/java CI + +on: + push: + branches: + - 'main' + schedule: + - cron: '30 5 * * 1' + +defaults: + run: + shell: bash + +jobs: + + build-and-push-docker-images: + name: Build and push docker images for PostgreSQL + extensions (PL/Java Dev only) + + runs-on: ubuntu-22.04 + + env: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }} + + steps: + - name: Checkout source + uses: actions/checkout@v3 + + - name: Install ansible and docker sources + run: /usr/bin/sudo /usr/bin/cp build-resources/apt/sources.list.d/* /etc/apt/sources.list.d + + - name: Install ansible and docker keyrings + run: /usr/bin/sudo /usr/bin/cp build-resources/keyrings/* /usr/share/keyrings + + - name: Run apt-update + run: /usr/bin/sudo /usr/bin/apt-get update + + - name: Install ansible and docker-ce + run: /usr/bin/sudo /usr/bin/apt-get install -y ansible ansible-core docker-ce docker-compose-plugin + + - name: Install ansible collections (does not require root) + run: /usr/bin/ansible-galaxy install -r src/main/ansible/roles/requirements.yml + + - name: Build and push docker images + run: /usr/bin/ansible-playbook src/main/ansible/build-pljava-dev.yml diff --git a/README-extensions.md b/README-extensions.md new file mode 100644 index 0000000..13188bc --- /dev/null +++ b/README-extensions.md @@ -0,0 +1,120 @@ +# Extensions available at the official PostgreSQL repository + +PostgreSQL maintains an official package repository with the latest releases. For instance for Ubuntu +you should add this to your `/etc/apt/sources.list` file: + +``` +# keyring: from 'apt.postgresql.org.gpg' +deb [arch=amd64 signed-by=/usr/share/keyrings/papt.postgresql.org.gpg] http://apt.postgresql.org/pub/repos/apt jammy-pgdg main +``` + +with the specified keyring downloaded and added to your system. + +A large number of extensions have already been packaged for your system - you usually do not need +to take any additional steps beyond installing the respective package. + +- pg-activity - Realtime PostgreSQL database server monitoring tool +- pg-cloudconfig - Set optimized defaults for PostgreSQL in virtual environments +- pg-cron +- pg-rage-terminator-14 - PostgreSQL background worker that kill random sessions. +- pg-rational +- pg-snakeoil +- pgagent - job scheduling engine for PostgreSQL +- pgaudit +- pgcluu - PostgreSQL performance monitoring and auditing tool +- pgmemcache +- pgsphere +- pgstat - Collects PostgreSQL statistics the same way as a vmstat tool +- pgtop - PostgreSQL performance monitoring tool akin to top +- postgis-java +- postgresql-pgmp - PostgreSQL extension for multiple-precision math +- postgresql-pllua - PostgreSQL extension for LUA +- postgresql-plsh - PostgreSQL extension for shell scripts + +The debian packages (bookworm and PostgreSQL repo) are + +- postgresql-15-asn1oid - ASN.1 OID data type for PostgreSQL +- postgresql-15-auto-failover - Postgres high availability support +- postgresql-15-bgw-replstatus - report whether PostgreSQL node is master or standby +- postgresql-15-credcheck - PostgreSQL username/password checks +- postgresql-15-cron - Run periodic jobs in PostgreSQL +- postgresql-15-debversion - Debian version number type for PostgreSQL +- postgresql-15-decoderbufs - logical decoder output plugin to deliver data as Protocol Buffers +- postgresql-15-dirtyread - Read dead but unvacuumed tuples from a PostgreSQL relation +- postgresql-15-extra-window-functions - Extra Window Functions for PostgreSQL +- postgresql-15-first-last-agg - PostgreSQL extension providing first and last aggregate functions +- postgresql-15-hll - HyperLogLog extension for PostgreSQL +- postgresql-15-hypopg - PostgreSQL extension adding support for hypothetical indexes. +- postgresql-15-icu-ext - PostgreSQL extension exposing functionality from the ICU library +- postgresql-15-ip4r - IPv4 and IPv6 types for PostgreSQL 15 +- postgresql-15-jsquery - PostgreSQL JSON query language with GIN indexing support +- postgresql-15-londiste-sql - SQL infrastructure for Londiste +- postgresql-15-mimeo - specialized, per-table replication between PostgreSQL instances +- postgresql-15-mysql-fdw - Postgres 15 Foreign Data Wrapper for MySQL +- postgresql-15-numeral - numeral datatypes for PostgreSQL +- postgresql-15-ogr-fdw - PostgreSQL foreign data wrapper for OGR +- postgresql-15-omnidb - PostgreSQL PL/pgSQL debugger extension for OmniDB +- postgresql-15-oracle-fdw - PostgreSQL Foreign Data Wrapper for Oracle +- postgresql-15-orafce - Oracle support functions for PostgreSQL 15 +- postgresql-15-partman - PostgreSQL Partition Manager +- postgresql-15-periods - PERIODs and SYSTEM VERSIONING for PostgreSQL +- postgresql-15-pgauditlogtofile - PostgreSQL pgAudit Add-On to redirect audit logs +- postgresql-15-pgaudit - PostgreSQL Audit Extension +- postgresql-15-pg-catcheck - Postgres system catalog checker +- postgresql-15-pg-checksums - Activate/deactivate/verify PostgreSQL data checksums +- postgresql-15-pgextwlist - PostgreSQL Extension Whitelisting +- postgresql-15-pg-fact-loader - Build fact tables asynchronously with Postgres +- postgresql-15-pg-failover-slots - High-availability support for PostgreSQL logical replication +- postgresql-15-pgfincore - set of PostgreSQL functions to manage blocks in memory +- postgresql-15-pgl-ddl-deploy - Transparent DDL replication for PostgreSQL +- postgresql-15-pglogical - Logical Replication Extension for PostgreSQL +- postgresql-15-pglogical-ticker - Have time-based replication delay for pglogical +- postgresql-15-pgmemcache - PostgreSQL interface to memcached +- postgresql-15-pgmp - arbitrary precision integers and rationals for PostgreSQL 15 +- postgresql-15-pgpcre - Perl Compatible Regular Expressions (PCRE) extension for PostgreSQL +- postgresql-15-pgpool2 - connection pool server and replication proxy for PostgreSQL - modules +- postgresql-15-pgq3 - Generic queue for PostgreSQL +- postgresql-15-pgq-node - Cascaded queueing on top of PgQ +- postgresql-15-pg-qualstats - PostgreSQL extension to gather statistics about predicates. +- postgresql-15-pgrouting - Routing functionality support for PostgreSQL/PostGIS +- postgresql-15-pgrouting-scripts - Routing functionality support for PostgreSQL/PostGIS - SQL scripts +- postgresql-15-pgsphere - Spherical data types for PostgreSQL +- postgresql-15-pg-stat-kcache - PostgreSQL extension to gather per-query kernel statistics. +- postgresql-15-pgtap - Unit testing framework extension for PostgreSQL 15 +- postgresql-15-pg-track-settings - PostgreSQL extension tracking of configuration settings +- postgresql-15-pgvector - Open-source vector similarity search for Postgres +- postgresql-15-pg-wait-sampling - Extension providing statistics about PostgreSQL wait events +- postgresql-15-pldebugger - PostgreSQL pl/pgsql Debugger API +- postgresql-15-pljava - Java procedural language for PostgreSQL 15 +- postgresql-15-pllua - Lua procedural language for PostgreSQL 15 +- postgresql-15-plpgsql-check - plpgsql_check extension for PostgreSQL +- postgresql-15-plprofiler - PostgreSQL PL/pgSQL functions performance profiler +- postgresql-15-plproxy - database partitioning system for PostgreSQL 15 +- postgresql-15-plr - Procedural language interface between PostgreSQL and R +- postgresql-15-plsh - PL/sh procedural language for PostgreSQL 15 +- postgresql-15-pointcloud - PostgreSQL extension for storing point cloud (LIDAR) data +- postgresql-15-postgis-3 - Geographic objects support for PostgreSQL 15 +- postgresql-15-postgis-3-scripts - Geographic objects support for PostgreSQL 15 -- SQL scripts +- postgresql-15-powa - PostgreSQL Workload Analyzer -- PostgreSQL 15 extension +- postgresql-15-prefix - Prefix Range module for PostgreSQL +- postgresql-15-preprepare - pre prepare your PostgreSQL statements server side +- postgresql-15-prioritize - Get and set the nice priorities of PostgreSQL backends +- postgresql-15-q3c - PostgreSQL 15 extension used for indexing the sky +- postgresql-15-rational - Precise fractional arithmetic for PostgreSQL +- postgresql-15-rdkit - Cheminformatics and machine-learning software (PostgreSQL Cartridge) +- postgresql-15-repack - reorganize tables in PostgreSQL databases with minimal locks +- postgresql-15-repmgr - replication manager for PostgreSQL 15 +- postgresql-15-rum - PostgreSQL RUM access method +- postgresql-15-semver - Semantic version number type for PostgreSQL +- postgresql-15-set-user - PostgreSQL privilege escalation with enhanced logging and control +- postgresql-15-show-plans - Show query plans of currently running PostgreSQL statements +- postgresql-15-similarity - PostgreSQL similarity functions extension +- postgresql-15-slony1-2 - replication system for PostgreSQL: PostgreSQL 15 server plug-in +- postgresql-15-snakeoil - PostgreSQL anti-virus scanner based on ClamAV +- postgresql-15-squeeze - PostgreSQL extension for automatic bloat cleanup +- postgresql-15-tablelog - log changes on tables and restore tables to point in time +- postgresql-15-tdigest - t-digest algorithm for on-line accumulation of rank-based statistics +- postgresql-15-tds-fdw - PostgreSQL foreign data wrapper for TDS databases +- postgresql-15-toastinfo - Show storage structure of varlena datatypes in PostgreSQL +- postgresql-15-unit - SI Units for PostgreSQL +- postgresql-15-wal2json - PostgreSQL logical decoding JSON output plugin diff --git a/README.md b/README.md index 4c0202e..662a142 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## Introduction -PostgreSQL has rich support for **server** extensions. See +PostgreSQL has rich support for server extensions. See [Chapter 38: Extending SQL](https://www.postgresql.org/docs/15/extend.html). These extensions are typically used to support: @@ -19,17 +19,26 @@ Two widely used extensions that demonstrate this additional functionality are: - [PostGIS](https://postgis.net/) - [PGAudit](https://www.pgaudit.org/) -This repository provides three new sets of docker images: +This repository produces three new sets of docker images: -- postgres-pgxnclient -- postgres-pljava -- postgres-pljava-dev +- [postgres-pgxnclient](https://hub.docker.com/repository/docker/beargiles/postgres-pgxnclient/general) +- [postgres-pljava](https://hub.docker.com/repository/docker/beargiles/postgres-pljava/general) +- [postgres-pljava-dev](https://hub.docker.com/repository/docker/beargiles/postgres-pljava-dev/general) ### CI/CD (GitHub Actions) -I plan to use GitHub actions to periodically poll the official PostgreSQL images and build new images -as they became available but I've had some problems getting the logic working right. So for now I've -temporarily taken a step back and will only perform a build after pushing an update to this repo. +GitHub actions are run once a week that check the upstream [PostgreSQL repo](https://hub.docker.com/_/postgres) +then builds and deploys these new docker images as required. + +Known limitation: for the pljava-dev image the Dockerfile downloads and rebuilds the Debian +source package. This normally creates a predictable source directory. Unfortunately the +authors of the `postgresql-15-pljava` package have decided to include the version of the +[pljava](https://github.com/tada/pljava) library in the source directory name. + +For now I'm using a separate CI/CD pipeline and the hardcoded `1.6.4` version but +the pipeline will break when the source package is updated. + +This does not affect the `postgres-pljava` image. ## Managing new extensions @@ -47,132 +56,14 @@ PGXS infrastructure. Many of the extensions available at PGXN are procedural languages, e.g., PL/Java. -# Extensions available at the official PostgreSQL repository - -PostgreSQL maintains an official package repository with the latest releases. For instance for Ubuntu -you should add this to your `/etc/apt/sources.list` file: - -``` -# keyring: from 'apt.postgresql.org.gpg' -deb [arch=amd64 signed-by=/usr/share/keyrings/papt.postgresql.org.gpg] http://apt.postgresql.org/pub/repos/apt jammy-pgdg main -``` - -with the specified keyring downloaded and added to your system. - -A large number of extensions have already been packaged for your system - you usually do not need -to take any additional steps beyond installing the respective package. - -- pg-activity - Realtime PostgreSQL database server monitoring tool -- pg-cloudconfig - Set optimized defaults for PostgreSQL in virtual environments -- pg-cron -- pg-rage-terminator-14 - PostgreSQL background worker that kill random sessions. -- pg-rational -- pg-snakeoil -- pgagent - job scheduling engine for PostgreSQL -- pgaudit -- pgcluu - PostgreSQL performance monitoring and auditing tool -- pgmemcache -- pgsphere -- pgstat - Collects PostgreSQL statistics the same way as a vmstat tool -- pgtop - PostgreSQL performance monitoring tool akin to top -- postgis-java -- postgresql-pgmp - PostgreSQL extension for multiple-precision math -- postgresql-pllua - PostgreSQL extension for LUA -- postgresql-plsh - PostgreSQL extension for shell scripts - -The debian packages (bookworm and PostgreSQL repo) are - -- postgresql-15-asn1oid - ASN.1 OID data type for PostgreSQL -- postgresql-15-auto-failover - Postgres high availability support -- postgresql-15-bgw-replstatus - report whether PostgreSQL node is master or standby -- postgresql-15-credcheck - PostgreSQL username/password checks -- postgresql-15-cron - Run periodic jobs in PostgreSQL -- postgresql-15-debversion - Debian version number type for PostgreSQL -- postgresql-15-decoderbufs - logical decoder output plugin to deliver data as Protocol Buffers -- postgresql-15-dirtyread - Read dead but unvacuumed tuples from a PostgreSQL relation -- postgresql-15-extra-window-functions - Extra Window Functions for PostgreSQL -- postgresql-15-first-last-agg - PostgreSQL extension providing first and last aggregate functions -- postgresql-15-hll - HyperLogLog extension for PostgreSQL -- postgresql-15-hypopg - PostgreSQL extension adding support for hypothetical indexes. -- postgresql-15-icu-ext - PostgreSQL extension exposing functionality from the ICU library -- postgresql-15-ip4r - IPv4 and IPv6 types for PostgreSQL 15 -- postgresql-15-jsquery - PostgreSQL JSON query language with GIN indexing support -- postgresql-15-londiste-sql - SQL infrastructure for Londiste -- postgresql-15-mimeo - specialized, per-table replication between PostgreSQL instances -- postgresql-15-mysql-fdw - Postgres 15 Foreign Data Wrapper for MySQL -- postgresql-15-numeral - numeral datatypes for PostgreSQL -- postgresql-15-ogr-fdw - PostgreSQL foreign data wrapper for OGR -- postgresql-15-omnidb - PostgreSQL PL/pgSQL debugger extension for OmniDB -- postgresql-15-oracle-fdw - PostgreSQL Foreign Data Wrapper for Oracle -- postgresql-15-orafce - Oracle support functions for PostgreSQL 15 -- postgresql-15-partman - PostgreSQL Partition Manager -- postgresql-15-periods - PERIODs and SYSTEM VERSIONING for PostgreSQL -- postgresql-15-pgauditlogtofile - PostgreSQL pgAudit Add-On to redirect audit logs -- postgresql-15-pgaudit - PostgreSQL Audit Extension -- postgresql-15-pg-catcheck - Postgres system catalog checker -- postgresql-15-pg-checksums - Activate/deactivate/verify PostgreSQL data checksums -- postgresql-15-pgextwlist - PostgreSQL Extension Whitelisting -- postgresql-15-pg-fact-loader - Build fact tables asynchronously with Postgres -- postgresql-15-pg-failover-slots - High-availability support for PostgreSQL logical replication -- postgresql-15-pgfincore - set of PostgreSQL functions to manage blocks in memory -- postgresql-15-pgl-ddl-deploy - Transparent DDL replication for PostgreSQL -- postgresql-15-pglogical - Logical Replication Extension for PostgreSQL -- postgresql-15-pglogical-ticker - Have time-based replication delay for pglogical -- postgresql-15-pgmemcache - PostgreSQL interface to memcached -- postgresql-15-pgmp - arbitrary precision integers and rationals for PostgreSQL 15 -- postgresql-15-pgpcre - Perl Compatible Regular Expressions (PCRE) extension for PostgreSQL -- postgresql-15-pgpool2 - connection pool server and replication proxy for PostgreSQL - modules -- postgresql-15-pgq3 - Generic queue for PostgreSQL -- postgresql-15-pgq-node - Cascaded queueing on top of PgQ -- postgresql-15-pg-qualstats - PostgreSQL extension to gather statistics about predicates. -- postgresql-15-pgrouting - Routing functionality support for PostgreSQL/PostGIS -- postgresql-15-pgrouting-scripts - Routing functionality support for PostgreSQL/PostGIS - SQL scripts -- postgresql-15-pgsphere - Spherical data types for PostgreSQL -- postgresql-15-pg-stat-kcache - PostgreSQL extension to gather per-query kernel statistics. -- postgresql-15-pgtap - Unit testing framework extension for PostgreSQL 15 -- postgresql-15-pg-track-settings - PostgreSQL extension tracking of configuration settings -- postgresql-15-pgvector - Open-source vector similarity search for Postgres -- postgresql-15-pg-wait-sampling - Extension providing statistics about PostgreSQL wait events -- postgresql-15-pldebugger - PostgreSQL pl/pgsql Debugger API -- postgresql-15-pljava - Java procedural language for PostgreSQL 15 -- postgresql-15-pllua - Lua procedural language for PostgreSQL 15 -- postgresql-15-plpgsql-check - plpgsql_check extension for PostgreSQL -- postgresql-15-plprofiler - PostgreSQL PL/pgSQL functions performance profiler -- postgresql-15-plproxy - database partitioning system for PostgreSQL 15 -- postgresql-15-plr - Procedural language interface between PostgreSQL and R -- postgresql-15-plsh - PL/sh procedural language for PostgreSQL 15 -- postgresql-15-pointcloud - PostgreSQL extension for storing point cloud (LIDAR) data -- postgresql-15-postgis-3 - Geographic objects support for PostgreSQL 15 -- postgresql-15-postgis-3-scripts - Geographic objects support for PostgreSQL 15 -- SQL scripts -- postgresql-15-powa - PostgreSQL Workload Analyzer -- PostgreSQL 15 extension -- postgresql-15-prefix - Prefix Range module for PostgreSQL -- postgresql-15-preprepare - pre prepare your PostgreSQL statements server side -- postgresql-15-prioritize - Get and set the nice priorities of PostgreSQL backends -- postgresql-15-q3c - PostgreSQL 15 extension used for indexing the sky -- postgresql-15-rational - Precise fractional arithmetic for PostgreSQL -- postgresql-15-rdkit - Cheminformatics and machine-learning software (PostgreSQL Cartridge) -- postgresql-15-repack - reorganize tables in PostgreSQL databases with minimal locks -- postgresql-15-repmgr - replication manager for PostgreSQL 15 -- postgresql-15-rum - PostgreSQL RUM access method -- postgresql-15-semver - Semantic version number type for PostgreSQL -- postgresql-15-set-user - PostgreSQL privilege escalation with enhanced logging and control -- postgresql-15-show-plans - Show query plans of currently running PostgreSQL statements -- postgresql-15-similarity - PostgreSQL similarity functions extension -- postgresql-15-slony1-2 - replication system for PostgreSQL: PostgreSQL 15 server plug-in -- postgresql-15-snakeoil - PostgreSQL anti-virus scanner based on ClamAV -- postgresql-15-squeeze - PostgreSQL extension for automatic bloat cleanup -- postgresql-15-tablelog - log changes on tables and restore tables to point in time -- postgresql-15-tdigest - t-digest algorithm for on-line accumulation of rank-based statistics -- postgresql-15-tds-fdw - PostgreSQL foreign data wrapper for TDS databases -- postgresql-15-toastinfo - Show storage structure of varlena datatypes in PostgreSQL -- postgresql-15-unit - SI Units for PostgreSQL -- postgresql-15-wal2json - PostgreSQL logical decoding JSON output plugin - # Dockerization -The PostgreSQL's official docker images are available at [https://hub.docker.com/_/postgres](https://hub.docker.com/_/postgres). -I highly recommend them, especially if you're using [TestContainers](https://testcontainers.com/) since the -Postgres module knows about this repo. (Warning: the module defaults to a very old version of the database.) +The official PostgreSQL official docker images are available at [https://hub.docker.com/_/postgres](https://hub.docker.com/_/postgres). +There are two Debian releases (bookworm and bullseye) and one Alpine release. I highly recommend them. + +Note: this is especially important if you're using [TestContainers](https://testcontainers.com/) +since the Postgres module knows about this repo. (Warning: the module defaults to a very old version of the database.) +You need to add a bit of code for that module to accept other docker images. This approach breaks down somewhat if your application needs one or more extensions. You want your CI/CD pipeline to start with the official PostgreSQL image, install known extensions, and then proceed to the next diff --git a/src/main/ansible/build-pljava-dev.yml b/src/main/ansible/build-pljava-dev.yml new file mode 100644 index 0000000..de9d6bb --- /dev/null +++ b/src/main/ansible/build-pljava-dev.yml @@ -0,0 +1,15 @@ +# +# Build postgres-pljava-dev image. This is done in a separate +# CI/CD task since it will fail when the pl/java version is +# bumped. +# +--- +- hosts: localhost + tasks: + - name: Build and deploy docker images. + vars: + targets: + - name: 'beargiles/postgres-pljava-dev' + target: pljavadev + ansible.builtin.include_role: + name: pljava_docker diff --git a/src/main/ansible/build.yml b/src/main/ansible/build.yml index b95ab98..342811a 100644 --- a/src/main/ansible/build.yml +++ b/src/main/ansible/build.yml @@ -1,6 +1,17 @@ +# +# Build most images. This script does not build pljava-dev since it +# currently makes an unsafe assumption. (The name of the source directory +# includes the pl/java version.) +# --- - hosts: localhost tasks: - - name: Build and deploy docker images. + - name: Build and deploy pgxnclient and pljava docker images. + vars: + targets: + - name: 'beargiles/postgres-pljava' + target: pljava + - name: 'beargiles/postgres-pgxnclient' + target: pgxnclient ansible.builtin.include_role: name: pljava_docker diff --git a/src/main/ansible/roles/pljava_docker/meta/main.yml b/src/main/ansible/roles/pljava_docker/meta/main.yml index aa3f362..4cbe0be 100644 --- a/src/main/ansible/roles/pljava_docker/meta/main.yml +++ b/src/main/ansible/roles/pljava_docker/meta/main.yml @@ -1,8 +1,8 @@ galaxy_info: - author: your name + author: Bear Giles namespace: beargiles - description: your role description - company: your company (optional) + description: Builds PostgreSQL docker images with pl/java pre-installed + company: # If the issue tracker for your role is not on github, uncomment the # next line and provide a value @@ -15,7 +15,7 @@ galaxy_info: # - GPL-3.0-only # - Apache-2.0 # - CC-BY-4.0 - license: Apache-2.0 + license: MIT min_ansible_version: 2.1 diff --git a/src/main/ansible/roles/pljava_docker/molecule/README.md b/src/main/ansible/roles/pljava_docker/molecule/README.md new file mode 100644 index 0000000..85ad432 --- /dev/null +++ b/src/main/ansible/roles/pljava_docker/molecule/README.md @@ -0,0 +1 @@ +Not implemented yet \ No newline at end of file diff --git a/src/main/ansible/roles/pljava_docker/tasks/actual-build-images.yml b/src/main/ansible/roles/pljava_docker/tasks/actual-build-images.yml new file mode 100644 index 0000000..03d432a --- /dev/null +++ b/src/main/ansible/roles/pljava_docker/tasks/actual-build-images.yml @@ -0,0 +1,34 @@ +# ------------------------------------------------------ +# +# Build and tag local images. +# +# ------------------------------------------------------ +# +# Requires: +# - debian_release - Debian release (bookworm, bullseye) +# - pg_version - full version of Postgres version +# +# Provides: +# - local docker image(s). +# +--- +- name: 'Set facts ({{ pg_version }}-{{ debian_release }})' + ansible.builtin.set_fact: + pg_major: "{{ pg_version | regex_replace('^([0-9]+).*$', '\\1') }}" + tag: '{{ pg_version }}-{{ debian_release }}' + +- name: 'Build docker image {{ tag }}' + community.docker.docker_image: + name: '{{ build.name }}' + build: + path: ../docker + target: '{{ build.target }}' + args: + DEBIAN_RELEASE: '{{ debian_release }}' + POSTGRES_MAJOR: '{{ pg_major }}' + POSTGRES_VERSION: '{{ pg_version }}' + tag: '{{ tag }}' + source: build + loop: '{{ targets }}' + loop_control: + loop_var: build diff --git a/src/main/ansible/roles/pljava_docker/tasks/actual-push-images.yml b/src/main/ansible/roles/pljava_docker/tasks/actual-push-images.yml new file mode 100644 index 0000000..5cde7b4 --- /dev/null +++ b/src/main/ansible/roles/pljava_docker/tasks/actual-push-images.yml @@ -0,0 +1,39 @@ +# ------------------------------------------------------ +# +# Push local images to dockerhub +# +# ------------------------------------------------------ +# +# Requires: +# - debian_release +# - pg_version - version to push +# +# ------------------------------------------------------ +# +# Push local images to docker hub +# +--- + +- name: 'Push docker images for ({{ pg_version }}-{{ debian_release }})' + community.docker.docker_image: + name: '{{ push1.name }}:{{ pg_version }}-{{ debian_release }}' + repository: '{{ push1.name }}:{{ pg_version }}-{{ debian_release }}' + force_tag: true + push: true + source: local + loop: '{{ targets }}' + loop_control: + loop_var: push1 + +- name: 'Push docker images for major version' + vars: + pg_major: "{{ pg_version | regex_replace('^([0-9]+).*$', '\\1') }}" + community.docker.docker_image: + name: '{{ push2.name }}:{{ pg_version }}-{{ debian_release }}' + repository: '{{ push2.name }}:{{ pg_major }}-{{ debian_release }}' + force_tag: true + push: true + source: local + loop: '{{ targets }}' + loop_control: + loop_var: push2 \ No newline at end of file diff --git a/src/main/ansible/roles/pljava_docker/tasks/build-images-by-pg-version.yml b/src/main/ansible/roles/pljava_docker/tasks/build-images-by-pg-version.yml new file mode 100644 index 0000000..420816d --- /dev/null +++ b/src/main/ansible/roles/pljava_docker/tasks/build-images-by-pg-version.yml @@ -0,0 +1,23 @@ +# ------------------------------------------------------ +# +# Build and tag local images by pg version +# +# ------------------------------------------------------ +# +# Requires: +# - pg_version - full version of Postgres version +# +# Produces: +# - local docker image(s). +# +--- +- name: 'Build docker images for ({{ pg_version }})' + vars: + debian_release: '{{ debian_release_build }}' + ansible.builtin.include_tasks: actual-build-images.yml + loop: '{{ debian_releases }}' + loop_control: + loop_var: debian_release_build + when: + - debian_releases is defined + - debian_releases[0] is defined \ No newline at end of file diff --git a/src/main/ansible/roles/pljava_docker/tasks/build-images.yml b/src/main/ansible/roles/pljava_docker/tasks/build-images.yml deleted file mode 100644 index 5401b7c..0000000 --- a/src/main/ansible/roles/pljava_docker/tasks/build-images.yml +++ /dev/null @@ -1,85 +0,0 @@ -# ------------------------------------------------------ -# -# Build and tag local images. -# -# ------------------------------------------------------ -# -# Requires: -# - pg_version - full version of Postgres version -# -# Provides: -# - local docker image(s). -# -#-- -- name: Set facts (pg_major) - ansible.builtin.set_fact: - pg_major: "{{ pg_version | regex_replace('^([0-9]+).*$', '\\1') }}" - -- name: 'Build docker image {{ pg_version }} (for pgxnclient development)' - community.docker.docker_image: - name: '{{ pgxnclient_name }}' - build: - path: ../docker - target: 'pgxnclient' - args: - POSTGRES_MAJOR: '{{ pg_major }}' - POSTGRES_VERSION: '{{ pg_version }}' - tag: '{{ pg_version }}' - source: build - -- name: 'Build docker image {{ pg_version }} (for pl/java)' - community.docker.docker_image: - name: '{{ pljava_name }}' - build: - path: ../docker - args: - POSTGRES_MAJOR: '{{ pg_major }}' - POSTGRES_VERSION: '{{ pg_version }}' - tag: '{{ pg_version }}' - source: build - -- name: 'Build docker image {{ pg_version }} (for pl/java development)' - community.docker.docker_image: - name: '{{ pljava_dev_name }}' - build: - path: ../docker - args: - POSTGRES_MAJOR: '{{ pg_major }}' - POSTGRES_VERSION: '{{ pg_version }}' - tag: '{{ pg_version }}' - source: build - - -# ------------------------------------------------------ -# Tag local images -# ------------------------------------------------------ -- name: 'Tag docker images {{ pg_major }}' - community.docker.docker_image: - name: '{{ name }}:{{ pg_version }}' - repository: '{{ name }}:{{ pg_major }}' - force_tag: true - source: local - loop: - - '{{ pgxnclient_name }}' - - '{{ pljava_name }}' - - '{{ pljava_dev_name }}' - loop_control: - loop_var: name - - -# ------------------------------------------------------ -# Tag latest image -# ------------------------------------------------------ -- name: 'Tag latest docker images' - community.docker.docker_image: - name: '{{ name }}:{{ pg_version }}' - repository: '{{ name }}:latest' - force_tag: true - source: local - loop: - - '{{ pgxnclient_name }}' - - '{{ pljava_name }}' - - '{{ pljavadev_name }}' - loop_control: - loop_var: name - when: pg_major == postgres_latest_major_tag diff --git a/src/main/ansible/roles/pljava_docker/tasks/list-tags.yml b/src/main/ansible/roles/pljava_docker/tasks/list-tags.yml index 1171c33..3ad6c82 100644 --- a/src/main/ansible/roles/pljava_docker/tasks/list-tags.yml +++ b/src/main/ansible/roles/pljava_docker/tasks/list-tags.yml @@ -14,14 +14,14 @@ # - full_tags - 'root' versions in that repo. (Postgres specific) # - latest_major_tag - latest major vesions in that repo. (Postgres specific) --- -- name: Request docker hub auth token +- name: Request docker hub auth token for {{ repo }} ansible.builtin.uri: url: 'https://auth.docker.io/token?service=registry.docker.io&scope=repository:{{ repo }}:pull' return_content: true status_code: 200 register: docker_hub_auth_token_resp -- name: Request tags +- name: Request {{ repo }} tags ansible.builtin.uri: url: 'https://registry-1.docker.io/v2/{{ repo }}/tags/list' headers: @@ -30,11 +30,10 @@ status_code: 200 register: tags_resp -- name: Capture any matching tags +- name: Capture any matching {{ repo }} tags vars: list_of_null: - null - all_tags: "{{ tags_resp.json.tags | map('regex_search', '^((1[2-9])|([2-9][0-9]))\\.[^-]+?$') | list | unique | difference(list_of_null) }}" + full_tags: "{{ tags_resp.json.tags | map('regex_search', '^((1[4-9])|([2-9][0-9]))\\.[^-]+?$') | list | unique | difference(list_of_null) | difference(seed_tags) }}" ansible.builtin.set_fact: - full_tags: '{{ all_tags }}' - latest_major_tag: "{{ all_tags | map('regex_replace', '^([0-9]+).*$', '\\1') | list | unique | sort(reverse = true) | first() }}" + all_tags: '{{ full_tags | sort(reverse = true) }}' diff --git a/src/main/ansible/roles/pljava_docker/tasks/main.yml b/src/main/ansible/roles/pljava_docker/tasks/main.yml index daaea10..a2f0a5f 100644 --- a/src/main/ansible/roles/pljava_docker/tasks/main.yml +++ b/src/main/ansible/roles/pljava_docker/tasks/main.yml @@ -1,93 +1,54 @@ --- -# tasks file for pljava_docker - -- name: Create set of tags to build - ansible.builtin.set_fact: - tags: [] # -# Disable this block for now... +# Determine what's already available. # -# name: Get list of postgresql tags -# vars: -# repo: '{{ postgres_name }}' -# ansible.builtin.include_tasks: list-tags.yml - -# name: Set facts (postgres_tags) -# ansible.builtin.set_fact: -# postgres_tags: '{{ full_tags }}' -# postgres_latest_major_tag: '{{ latest_major_tag }}' +- +# --- get list of postgresql tags --- +- name: Get list of postgresql tags + vars: + repo: '{{ postgres_name }}' + ansible.builtin.include_tasks: list-tags.yml -# name: Build docker images -# ansible.builtin.include_tasks: build-images.yml -# loop: '{{ tags }}' -# loop_control: -# loop_var: pg_version -# when: -# - tags is defined -# - tags[0] is defined +- name: Capture PostgreSQL tags + ansible.builtin.set_fact: + all_pg_tags: '{{ all_tags }}' -# -# Do this instead -# -- name: Build all packages - ansible.builtin.shell: 'src/main/docker/buildall.sh' +- name: Get list of our tags + vars: + repo: '{{ targets[0].name }}' + ansible.builtin.include_tasks: list-tags.yml -# -# another cheat - for some reason 'tags' is still what I had months ago... -# +- name: Capture our own tags + ansible.builtin.set_fact: + existing_tags: '{{ all_tags }}' -# -# Log into docker hub -# -- name: Log into docker hub - community.docker.docker_login: - username: "{{ lookup('ansible.builtin.env', 'DOCKERHUB_USERNAME') }}" - password: "{{ lookup('ansible.builtin.env', 'DOCKERHUB_PASSWORD') }}" - register: login_resp - when: - - actual_versions is defined - - actual_versions[0] is defined +- name: Set facts (postgres_tags) + ansible.builtin.set_fact: + pg_versions: '{{ all_pg_tags | difference(existing_tags) }}' + latest_full_pg_version: '{{ all_pg_tags | sort(reverse = true) | first() }}' -- name: Verify we succeeded - ansible.builtin.assert: - that: - - not login_resp.failed - msg: Unable to log into Docker Hub +- name: show information... + ansible.builtin.debug: var=pg_versions -- name: Push pgxnclient docker images to docker hub - vars: - version: '{{ item }}' - community.docker.docker_image: - name: '{{ pgxnclient_name }}:{{ version }}' - repository: '{{ pgxnclient_name }}:{{ version }}' - force_version: true - push: true - source: local - loop: '{{ actual_versions }}' +- name: show information... + ansible.builtin.debug: var=latest_full_pg_version -- name: Push pljava docker images to docker hub - vars: - version: '{{ item }}' - community.docker.docker_image: - name: '{{ pljava_name }}:{{ version }}' - repository: '{{ pljava_name }}:{{ version }}' - force_version: true - push: true - source: local - loop: '{{ actual_versions }}' +# --- build and push docker images --- -- name: Push pljava-dev docker images to docker hub +- name: Build docker images by PostgreSQL version vars: - version: '{{ item }}' - community.docker.docker_image: - name: '{{ pljava_dev_name }}:{{ version }}' - repository: '{{ pljava_dev_name }}:{{ version }}' - force_version: true - push: true - source: local - loop: '{{ actual_versions }}' + pg_version: '{{ pg_version_build }}' + ansible.builtin.include_tasks: build-images-by-pg-version.yml + loop: '{{ pg_versions }}' + loop_control: + loop_var: pg_version_build + when: + - pg_versions is defined + - pg_versions[0] is defined -- name: Log out of docker hub - community.docker.docker_login: - state: absent +- name: Push docker images to docker hub (with debian release tags) + ansible.builtin.include_tasks: push-all-images.yml + when: + - pg_versions is defined + - pg_versions[0] is defined diff --git a/src/main/ansible/roles/pljava_docker/tasks/push-all-images.yml b/src/main/ansible/roles/pljava_docker/tasks/push-all-images.yml new file mode 100644 index 0000000..8090841 --- /dev/null +++ b/src/main/ansible/roles/pljava_docker/tasks/push-all-images.yml @@ -0,0 +1,55 @@ +# +# Push all images +# +--- + +# +# Log into docker hub +# +- name: Log into docker hub + community.docker.docker_login: + username: "{{ lookup('ansible.builtin.env', 'DOCKERHUB_USERNAME') }}" + password: "{{ lookup('ansible.builtin.env', 'DOCKERHUB_PASSWORD') }}" + register: login_resp + +- name: Verify we succeeded + ansible.builtin.assert: + that: + - not login_resp.failed + msg: Unable to log into Docker Hub + +- name: Push docker images to docker hub (with debian release) + vars: + pg_version: '{{ pg_version_push }}' + ansible.builtin.include_tasks: push-images-by-pg-version.yml + loop: '{{ pg_versions }}' + loop_control: + loop_var: pg_version_push + +- name: Push docker images to docker hub (without debian release) + vars: + pg_version: '{{ pg_version_push }}' + ansible.builtin.include_tasks: push-images-by-main-debian-release.yml + loop: '{{ pg_versions }}' + loop_control: + loop_var: pg_version_push + +# note - we *might* have seen an update in a prior db version without +# a corresponding update in the latest version. That's why this check +# the full list of pg versions, not just the update list. +- name: Finally push 'latest' docker images to docker hub + vars: + pg_major: "{{ latest_full_pg_version | regex_replace('^([0-9]+).*$', '\\1') }}" + community.docker.docker_image: + name: '{{ latest.name }}:{{ pg_major }}-{{ debian_latest_release }}' + repository: '{{ latest.name }}:latest' + force_tag: true + push: true + source: local + loop: '{{ targets }}' + loop_control: + loop_var: latest + +- name: Log out of docker hub + community.docker.docker_login: + state: absent diff --git a/src/main/ansible/roles/pljava_docker/tasks/push-images-by-main-debian-release.yml b/src/main/ansible/roles/pljava_docker/tasks/push-images-by-main-debian-release.yml new file mode 100644 index 0000000..6588635 --- /dev/null +++ b/src/main/ansible/roles/pljava_docker/tasks/push-images-by-main-debian-release.yml @@ -0,0 +1,37 @@ +# ------------------------------------------------------ +# +# Push local images to dockerhub +# +# ------------------------------------------------------ +# +# Requires: +# - pg_version - version to push (multiple debian releases) +# +# ------------------------------------------------------ +# +# Push local images to docker hub +# +--- +- name: 'Push docker images for latest debian release ({{ pg_version }})' + community.docker.docker_image: + name: '{{ push5.name }}:{{ pg_version }}-{{ debian_latest_release }}' + repository: '{{ push5.name }}:{{ pg_version }}' + force_tag: true + push: true + source: local + loop: '{{ targets }}' + loop_control: + loop_var: push5 + +- name: 'Push docker images for latest debian release' + vars: + pg_major: "{{ pg_version | regex_replace('^([0-9]+).*$', '\\1') }}" + community.docker.docker_image: + name: '{{ push6.name }}:{{ pg_version }}' + repository: '{{ push6.name }}:{{ pg_major }}' + force_tag: true + push: true + source: local + loop: '{{ targets }}' + loop_control: + loop_var: push6 diff --git a/src/main/ansible/roles/pljava_docker/tasks/push-images-by-pg-version.yml b/src/main/ansible/roles/pljava_docker/tasks/push-images-by-pg-version.yml new file mode 100644 index 0000000..724a861 --- /dev/null +++ b/src/main/ansible/roles/pljava_docker/tasks/push-images-by-pg-version.yml @@ -0,0 +1,24 @@ +# ------------------------------------------------------ +# +# Push local images to dockerhub +# +# ------------------------------------------------------ +# +# Requires: +# - pg_version - version to push (multiple debian releases) +# +# ------------------------------------------------------ +# +# Push local images to docker hub +# +--- +- name: 'Push docker images for ({{ pg_version }})' + vars: + debian_release: '{{ debian_release_push }}' + ansible.builtin.include_tasks: actual-push-images.yml + loop: '{{ debian_releases }}' + loop_control: + loop_var: debian_release_push + when: + - debian_releases is defined + - debian_releases[0] is defined diff --git a/src/main/ansible/roles/pljava_docker/tasks/push-images.yml b/src/main/ansible/roles/pljava_docker/tasks/push-images.yml deleted file mode 100644 index 83956f3..0000000 --- a/src/main/ansible/roles/pljava_docker/tasks/push-images.yml +++ /dev/null @@ -1,26 +0,0 @@ -# ------------------------------------------------------ -# -# Push local images to dockerhub -# -# ------------------------------------------------------ -# -# Requires: -# - version - version to push -# -# ------------------------------------------------------ -# -# Push local images to docker hub -# ---- - -- name: 'Push docker images for ({{ version }})' - community.docker.docker_image: - name: '{{ item }}:{{ version }}' - repository: '{{ item }}:{{ version }}' - force_version: true - push: true - source: local - loop: - - '{{ pgxnclient_name }}' - - '{{ pljava_name }}' - - '{{ pljava_dev_name }}' \ No newline at end of file diff --git a/src/main/ansible/roles/pljava_docker/vars/main.yml b/src/main/ansible/roles/pljava_docker/vars/main.yml index 7b00369..ba9053c 100644 --- a/src/main/ansible/roles/pljava_docker/vars/main.yml +++ b/src/main/ansible/roles/pljava_docker/vars/main.yml @@ -1,43 +1,16 @@ --- +debian_releases: + - bullseye + - bookworm + +debian_latest_release: bookworm + # Docker names (to ensure consistency) postgres_name: library/postgres -pgxnclient_name: beargiles/postgres-pgxnclient -pljava_name: beargiles/postgres-pljava -pljava_dev_name: beargiles/postgres-pljava-dev # we can ignore tese tags since the release is so old. seed_tags: - - '12' - - '12.0' - - '12.1' - - '12.2' - - '12.3' - - '12.4' - - '12.5' - - '12.6' - - '12.7' - - '12.8' - - '12.9' - - '12.10' - - '12.11' - - '12.12' - - '12.13' - # '12.14' - # '12.15' - - '13' - - '13.0' - - '13.1' - - '13.2' - - '13.3' - - '13.4' - - '13.5' - - '13.6' - - '13.7' - - '13.8' - - '13.9' - # '13.10' - # '13.11' - '14' - '14.0' - '14.1' @@ -46,28 +19,10 @@ seed_tags: - '14.4' - '14.5' - '14.6' - # '14.7' - # '14.8' + - '14.7' + - '14.8' - '15' - '15.0' - '15.1' - # '15.2' - # '15.3' - -# since they aren't being pulled in by main/push-images... -actual_versions: - - '14.9-bookworm' - - '14-bookworm' - - '14.9-bullseye' - - '14-bullseye' - - '14' - - '15.4-bookworm' - - '15-bookworm' - - '15.4-bullseye' - - '15-bullseye' - - '15.4' - - '15' - - 'latest' - # '16rc1-bookworm' - # '16rc1-bullseye' - # '16rc1' \ No newline at end of file + - '15.2' + - '15.3' \ No newline at end of file diff --git a/src/main/docker/Dockerfile b/src/main/docker/Dockerfile index 162fd16..9e7cb1c 100644 --- a/src/main/docker/Dockerfile +++ b/src/main/docker/Dockerfile @@ -3,8 +3,8 @@ # (pgxnclient and pgtap) # ARG PG_VERSION=15.3 -ARG RELEASE=bookworm -FROM postgres:${PG_VERSION}-${RELEASE} AS pgxnclient +ARG DEBIAN_RELEASE=bookworm +FROM postgres:${PG_VERSION}-${DEBIAN_RELEASE} AS pgxnclient LABEL maintainer="Bear Giles " LABEL org.opencontainers.image.authors="bgiles@coyotesong.com"