Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
contents: write
packages: write
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6
- name: "Configure git client"
shell: bash
run: |
Expand All @@ -26,13 +26,13 @@ jobs:

git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- uses: docker/login-action@v3
- uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/setup-qemu-action@v4
- uses: docker/setup-buildx-action@v4
- name: "Is a release or a feature version needed?"
id: define-changelog-validation
shell: bash
Expand Down Expand Up @@ -130,7 +130,7 @@ jobs:
echo "tag=${tag}" >>"${GITHUB_OUTPUT}"
fi
- id: build
uses: docker/build-push-action@v6
uses: docker/build-push-action@v7
with:
context: src/main/docker
load: true
Expand Down Expand Up @@ -158,7 +158,7 @@ jobs:
fi
- name: Build and push
if: steps.define-build.outputs.kind == 'publish'
uses: docker/build-push-action@v6
uses: docker/build-push-action@v7
with:
context: src/main/docker
platforms: linux/amd64,linux/arm64
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ Categories, defined in [changemap.json](.github/clq/changemap.json):
- `Fixed` for any bugfixes.
- `Security` in case of vulnerabilities.

## [2.4.0] - 2026-04-03

### Added

- Introduce an optional `extensions` configuration in the `values.properties` file to specify additional Postgres extensions to be created.
The `pg_trgm` and `btree_gin` extensions are always included by default.

### Fixed

- Bump `actions/checkout` from 5 to 6
- Bump `docker/build-push-action` from 6 to 7
- Bump `docker/login-action` from 3 to 4
- Bump `docker/setup-buildx-action` from 3 to 4
- Bump `alpine` from 3.20 to 3.23

## [2.3.0] - 2026-01-22

### Added
Expand Down
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ A property file, it contains un-escaped values to define the database to be crea

Keys and values are separated with a `=`. Comment lines, starting with a `#`, are ignored.

| Property | Required | Description |
| ---------------------- | -------- | ---------------------------------------------- |
| database_name | yes | Name of the database |
| database_owner | yes | Name of the database owner |
| database_owner_passwor | yes | Password for the database owner |
| connection_limit | no | Initial connection cout limit, defaults to 100 |
| Property | Required | Description |
|-------------------------|----------|-------------------------------------------------------------------------------------------------------|
| database_name | yes | Name of the database |
| database_owner | yes | Name of the database owner |
| database_owner_password | yes | Password for the database owner |
| connection_limit | no | Initial connection count limit, defaults to 100 |
| extensions | no | Comma-separated names of Postgres extensions to create; `pg_trgm` and `btree_gin` are always included |

Mount the file at `/home/values.properties`.

Expand All @@ -40,9 +41,8 @@ A property file, it contains un-escaped values for the master user name and pass

Keys and values are separated with a `=`. Comment lines, starting with a `#`, are ignored.


| Property | Required | Description |
| ---------- | -------- | ---------------------------- |
|------------|----------|------------------------------|
| PGUSER | yes | Name of the master user |
| PGPASSWORD | yes | Password for the master user |

Expand All @@ -61,19 +61,21 @@ Mount the file at `/home/.pgpass`.
```shell
docker buildx build src/main/docker --tag arda-cards/postgres-database-initializer
```

Alternative:

```shell
make build
```


# How to test

```shell
docker compose -f src/test/docker/compose.yaml up --renew-anon-volumes
```

Alternative:

```shell
make test
```
Expand All @@ -85,9 +87,11 @@ Then inspect the log.
The script `tests.sh` runs all the integration tests.

The *clean build* command is

```shell
docker system prune --volumes --force; ./tests.sh
```

The command purges the local docker installation from any temporary images, volumes, ...

# How to use
Expand Down
2 changes: 1 addition & 1 deletion src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.20
FROM alpine:3.23

RUN apk add --update --no-cache postgresql16-client

Expand Down
8 changes: 4 additions & 4 deletions src/main/docker/create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public TO :"database_role";

-- Create extensions as the current psql user (typically a superuser) after connecting to the database.
-- This is done here because creating these extensions requires superuser privileges that the application roles do not have.
-- Enable pg_trgm extension for fuzzy string matching
CREATE EXTENSION IF NOT EXISTS pg_trgm;
-- Enable btree_gin extension for types other than Strings.
CREATE EXTENSION IF NOT EXISTS btree_gin;
SELECT format('CREATE EXTENSION IF NOT EXISTS %I', btrim(extension_name))
FROM regexp_split_to_table(:'extensions', ',') AS extension_name
WHERE btrim(extension_name) <> ''
\gexec

-- Revoke the ability to drop the database or create new users
REVOKE CREATE ON DATABASE :"database_name" FROM :"database_owner";
Expand Down
23 changes: 20 additions & 3 deletions src/main/docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,37 @@ else
# Handle escaped colons (\:) and backslashes (\\) in .pgpass
bs_ph="<BS_ESCAPE>"
cl_ph="<CL_ESCAPE>"
pg_user="$(grep -v -e '^#' ${PGPASSFILE} | \
sed -e "s/\\\\\\\\/${bs_ph}/g" -e "s/\\\\:/${cl_ph}/g" | \
cut -d : -f 4 | \
pg_user="$(grep -v -e '^#' ${PGPASSFILE} |
sed -e "s/\\\\\\\\/${bs_ph}/g" -e "s/\\\\:/${cl_ph}/g" |
cut -d : -f 4 |
sed -e "s/${cl_ph}/:/g" -e "s/${bs_ph}/\\\\/g")"
fi
chmod -f 0600 ${PGPASSFILE}

readonly values=/home/values.properties
normalized_extensions=
for extension in $(
echo "pg_trgm,btree_gin,$(sed -n -e 's/^extensions=//p' "${values}")" |
awk -F',' '{ for (i = 1; i <= NF; i++) { gsub(/^[[:space:]]+|[[:space:]]+$/, "", $i); if ($i != "") print $i } }' |
sort -u \
Comment thread
denisa marked this conversation as resolved.
Comment thread
denisa marked this conversation as resolved.
); do
if ! printf '%s' "${extension}" | grep -Eq '^[A-Za-z_][A-Za-z0-9_]*$'; then
echo "Invalid extension name: ${extension}"
exit 1
fi
if [ -n "${normalized_extensions}" ]; then
normalized_extensions="${normalized_extensions},${extension}"
else
normalized_extensions="${extension}"
fi
done
{
echo "\set database_name '$(sed -n -e 's/^database_name=//p' "${values}")'"
echo "\set database_owner '$(sed -n -e 's/^database_owner=//p' "${values}")'"
echo "\set database_owner_password '$(sed -n -e 's/^database_owner_password=//p' "${values}")'"
connection_limit=$(sed -n -e 's/^connection_limit=//p' "${values}" | cut -d = -f 2)
echo "\set connection_limit ${connection_limit:-100}"
echo "\set extensions '${normalized_extensions}'"
} >/home/values.sql

command=/home/create.sql
Expand Down
14 changes: 14 additions & 0 deletions src/test/docker/test_all.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,17 @@ BEGIN
END IF;
END;
$$;

DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'pg_trgm') THEN
RAISE EXCEPTION 'Extension pg_trgm was not created';
END IF;
IF NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'btree_gin') THEN
RAISE EXCEPTION 'Extension btree_gin was not created';
END IF;
IF NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'btree_gist') THEN
RAISE EXCEPTION 'Extension btree_gist was not created';
END IF;
END;
$$;
1 change: 1 addition & 0 deletions src/test/docker/values_all.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ database_name=test_db_all
database_owner=test_db_all_owner
database_owner_password=test_db_all_owner_pwd
connection_limit=25
extensions=pg_trgm, btree_gist