Skip to content

Commit

Permalink
Add NO_CLUSTER variable
Browse files Browse the repository at this point in the history
Prevents `pg-start` from initializing and starting a cluster. Add docs
to describe it and a use case.

Also fix some shell issues reported by shellcheck.
  • Loading branch information
theory committed Feb 5, 2024
1 parent 91086d9 commit 5cc691a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ jobs:
run: "docker run -w /repo --rm --volume \"$(pwd)/test:/repo\" -e AS_USER=worker pgxn-tools-test ./runtest.sh ${{ matrix.pg }} zip"
- name: Test Zip with zip excluded file
run: "docker run -w /repo --rm --volume \"$(pwd)/test:/repo\" pgxn-tools-test ./runtest.sh ${{ matrix.pg }} zip yes"
# Test NO_CLUSTER
- name: Test NO_CLUSTER
env: { NO_CLUSTER: true }
run: |-
docker run -w /repo --rm pgxn-tools-test pg-start ${{ matrix.pg }}
if [ -d /var/lib/postgresql/16/test ]; then
echo "ERROR: /var/lib/postgresql/16/test should not exist!"
exit 1;
fi
publish:
# Publish for a tag starting with v.
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,31 @@ modified the `postgresql.conf` file), use `pg_ctlcluster` like so:
pg_ctlcluster 12 test restart
```

For finer control over running the PostgreSQL cluster, set the `NO_CLUSTER`
environment variable to prevent `pg-start` from creating and starting a cluster:

```sh
env NO_CLUSTER=1 pg-start 14
```

This will simply install Postgres 14; to start it, use the [`pg_createcluster`]
command, like so:

```sh
pg_createcluster --start 14 my14 -p 5414 -- -A trust
```

This starts a cluster named "my14" on port 5414. This technique is useful to run
multiple clusters, even different versions at once; just given them unique names and
ports to run on:

```sh
env NO_CLUSTER=1 pg-start 15
pg_createcluster --start 15 my15 -p 5415 -- -A trust
env NO_CLUSTER=1 pg-start 16
pg_createcluster --start 16 my16 -p 5416 -- -A trust
```

### [`pg-build-test`]

``` sh
Expand Down Expand Up @@ -411,6 +436,7 @@ Copyright (c) 2020-2024 The PGXN Maintainers. Distributed under the
[upload-release-asset]: https://github.com/actions/upload-release-asset
[git-archive-all]: https://github.com/Kentzo/git-archive-all
[PGXN]: https://pgxn.org/ "The PostgreSQL Extension Network"
[`pg_createcluster`]: https://manpages.debian.org/buster/postgresql-common/pg_createcluster.1.en.html
[David E. Wheeler]: https://justatheory.com/
[PostgreSQL License]: https://opensource.org/licenses/PostgreSQL
[LICENSE]: LICENSE
Expand Down
1 change: 0 additions & 1 deletion bin/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ set -e
[ -z "$AS_USER" ] && exec "$@"

USER_ID=${LOCAL_UID:-1001}
USERNAME=worker

echo "Starting with UID $USER_ID"
useradd --system --create-home --shell /bin/bash -g root -G sudo -u $USER_ID "$AS_USER"
Expand Down
2 changes: 1 addition & 1 deletion bin/pg-start
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ if [ $# -gt 1 ]; then
sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install -y "${@:2}"
fi

sudo pg_createcluster --start $PGVERSION test -p "${PGPORT:-5432}" -- -A trust
[ -z ${NO_CLUSTER+x} ] && sudo pg_createcluster --start "$PGVERSION" test -p "${PGPORT:-5432}" -- -A trust
4 changes: 3 additions & 1 deletion test/runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ prefix=widget-1.0.0
zipfile="${prefix}.zip"
extrafile=extra.txt

cd $(dirname "$0")
cd "$(dirname "$0")"

if [ -n "$testopts" ]; then
# Use GIT_BUNDLE_OPTS to add an untracked file to the Git archive or
Expand Down Expand Up @@ -39,6 +39,7 @@ if [ "$expectutil" = "git" ]; then
# Make sure runtest.sh was omitted thanks to .gitattributes.
if [ -f "$prefix/runtests.sh" ]; then
echo 'ERROR: Zip file contains runtests.sh and should not'
# shellcheck disable=SC2016
echo ' Did pgxn-bundle use `zip` instead of `git archive`?'
exit 2
fi
Expand All @@ -51,6 +52,7 @@ else
# Make sure runtest.sh is included in the zip file.
if [ ! -f "$prefix/runtest.sh" ]; then
echo 'ERROR: Zip file contains runtests.sh and should not'
# shellcheck disable=SC2016
echo ' Did pgxn-bundle use `git archive` instead of `zip`?'
exit 2
fi
Expand Down

0 comments on commit 5cc691a

Please sign in to comment.