Skip to content

Commit 1e89037

Browse files
committed
Add dist-gen generated content for version 14
Signed-off-by: Petr "Stone" Hracek <[email protected]>
1 parent 5c26b72 commit 1e89037

20 files changed

+1115
-0
lines changed

14/Dockerfile.fedora

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
FROM quay.io/fedora/s2i-core:37
2+
3+
# PostgreSQL image for OpenShift.
4+
# Volumes:
5+
# * /var/lib/psql/data - Database cluster for PostgreSQL
6+
# Environment:
7+
# * $POSTGRESQL_USER - Database user name
8+
# * $POSTGRESQL_PASSWORD - User's password
9+
# * $POSTGRESQL_DATABASE - Name of the database to create
10+
# * $POSTGRESQL_ADMIN_PASSWORD (Optional) - Password for the 'postgres'
11+
# PostgreSQL administrative account
12+
13+
ENV NAME=postgresql \
14+
VERSION=0 \
15+
ARCH=x86_64 \
16+
\
17+
POSTGRESQL_VERSION=14 \
18+
POSTGRESQL_PREV_VERSION=13 \
19+
HOME=/var/lib/pgsql \
20+
PGUSER=postgres \
21+
APP_DATA=/opt/app-root
22+
23+
ENV SUMMARY="PostgreSQL is an advanced Object-Relational database management system" \
24+
DESCRIPTION="PostgreSQL is an advanced Object-Relational database management system (DBMS). \
25+
The image contains the client and server programs that you'll need to \
26+
create, run, maintain and access a PostgreSQL DBMS server."
27+
28+
LABEL summary="$SUMMARY" \
29+
description="$DESCRIPTION" \
30+
io.k8s.description="$DESCRIPTION" \
31+
io.k8s.display-name="PostgreSQL 14" \
32+
io.openshift.expose-services="5432:postgresql" \
33+
io.openshift.tags="database,postgresql,postgresql14" \
34+
com.redhat.component="$NAME" \
35+
maintainer="SoftwareCollections.org <[email protected]>" \
36+
name="fedora/$NAME-14" \
37+
version="0" \
38+
usage="docker run -d --name postgresql_database -e POSTGRESQL_USER=user -e POSTGRESQL_PASSWORD=pass -e POSTGRESQL_DATABASE=db -p 5432:5432 quay.io/fedora/$NAME-14"
39+
40+
EXPOSE 5432
41+
42+
COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions
43+
44+
# This image must forever use UID 26 for postgres user so our volumes are
45+
# safe in the future. This should *never* change, the last test is there
46+
# to make sure of that.
47+
RUN INSTALL_PKGS="rsync tar gettext bind-utils postgresql-server postgresql-contrib nss_wrapper " && \
48+
INSTALL_PKGS+="findutils xz" && \
49+
INSTALL_PKGS+=" pgaudit" && \
50+
dnf -y module enable postgresql:14 && \
51+
dnf -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \
52+
rpm -V $INSTALL_PKGS && \
53+
postgres -V | grep -qe "$POSTGRESQL_VERSION\." && echo "Found VERSION $POSTGRESQL_VERSION" && \
54+
dnf clean all && \
55+
test "$(id postgres)" = "uid=26(postgres) gid=26(postgres) groups=26(postgres)" && \
56+
mkdir -p /var/lib/pgsql/data && \
57+
/usr/libexec/fix-permissions /var/lib/pgsql /var/run/postgresql
58+
59+
# Get prefix path and path to scripts rather than hard-code them in scripts
60+
ENV CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/postgresql
61+
62+
COPY root /
63+
COPY ./s2i/bin/ $STI_SCRIPTS_PATH
64+
65+
VOLUME ["/var/lib/pgsql/data"]
66+
67+
# S2I permission fixes
68+
# --------------------
69+
# 1. unless specified otherwise (or - equivalently - we are in OpenShift), s2i
70+
# build process would be executed as 'uid=26(postgres) gid=26(postgres)'.
71+
# Such process wouldn't be able to execute the default 'assemble' script
72+
# correctly (it transitively executes 'fix-permissions' script). So let's
73+
# add the 'postgres' user into 'root' group here
74+
#
75+
# 2. we call fix-permissions on $APP_DATA here directly (UID=0 during build
76+
# anyways) to assure that s2i process is actually able to _read_ the
77+
# user-specified scripting.
78+
RUN usermod -a -G root postgres && \
79+
/usr/libexec/fix-permissions --read-only "$APP_DATA"
80+
81+
USER 26
82+
83+
ENTRYPOINT ["container-entrypoint"]
84+
CMD ["run-postgresql"]

14/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
root/usr/share/container-scripts/postgresql/README.md

14/root/usr/bin/container-entrypoint

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
exec "$@"

14/root/usr/bin/run-postgresql

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
3+
export ENABLE_REPLICATION=${ENABLE_REPLICATION:-false}
4+
5+
set -eu
6+
export_vars=$(cgroup-limits) ; export $export_vars
7+
8+
source "${CONTAINER_SCRIPTS_PATH}/common.sh"
9+
10+
set_pgdata
11+
12+
process_extending_files \
13+
"${APP_DATA}/src/postgresql-pre-start" \
14+
"${CONTAINER_SCRIPTS_PATH}/pre-start"
15+
16+
check_env_vars
17+
generate_passwd_file
18+
generate_postgresql_config
19+
20+
# Is this brand new data volume?
21+
PG_INITIALIZED=false
22+
23+
if [ ! -f "$PGDATA/postgresql.conf" ]; then
24+
initialize_database
25+
PG_INITIALIZED=:
26+
else
27+
try_pgupgrade
28+
fi
29+
30+
# Use insanely large timeout (24h) to ensure that the potential recovery has
31+
# enough time here to happen (unless liveness probe kills us). Note that in
32+
# case of server failure this command still exists immediately.
33+
pg_ctl start -w --timeout 86400 -o "-h ''"
34+
35+
# This is just a pedantic safety measure (the timeout above is unlikely to
36+
# happen), but `pt_ctl -w` is not reliable prior to PostgreSQL v10 where it
37+
# returns exit_status=0 even if the server is still starting. For more info
38+
# see the issue#297 and
39+
# https://www.postgresql.org/message-id/CAB7nPqSJs85wK9aknm%3D_jmS6GnH3SQBhpzKcqs8Qo2LhEg2etw%40mail.gmail.com
40+
pg_isready
41+
42+
if $PG_INITIALIZED ; then
43+
process_extending_files \
44+
"${APP_DATA}/src/postgresql-init" \
45+
"${CONTAINER_SCRIPTS_PATH}/init"
46+
migrate_db
47+
create_users
48+
fi
49+
50+
process_extending_files \
51+
"${APP_DATA}/src/postgresql-start" \
52+
"${CONTAINER_SCRIPTS_PATH}/start"
53+
54+
pg_ctl stop
55+
56+
unset_env_vars
57+
echo "Starting server..."
58+
exec postgres "$@"

14/root/usr/bin/run-postgresql-master

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
export ENABLE_REPLICATION=true
4+
5+
exec run-postgresql "$@"

14/root/usr/bin/run-postgresql-slave

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
export ENABLE_REPLICATION=true
4+
5+
set -eu
6+
export_vars=$(cgroup-limits) ; export $export_vars
7+
8+
source "$CONTAINER_SCRIPTS_PATH"/common.sh
9+
10+
set_pgdata
11+
12+
function initialize_replica() {
13+
echo "Initializing PostgreSQL slave ..."
14+
# TODO: Validate and reuse existing data?
15+
rm -rf $PGDATA
16+
PGPASSWORD="${POSTGRESQL_MASTER_PASSWORD}" pg_basebackup -X fetch --no-password --pgdata ${PGDATA} --host=${MASTER_FQDN} --port=5432 -U "${POSTGRESQL_MASTER_USER}"
17+
18+
# PostgreSQL recovery configuration.
19+
generate_postgresql_recovery_config
20+
cat >> "$PGDATA/postgresql.auto.conf" <<EOF
21+
22+
# Custom OpenShift recovery configuration:
23+
include '${POSTGRESQL_RECOVERY_FILE}'
24+
EOF
25+
# activate standby mode
26+
touch "$PGDATA/standby.signal"
27+
}
28+
29+
check_env_vars
30+
generate_passwd_file
31+
generate_postgresql_config
32+
33+
wait_for_postgresql_master
34+
export MASTER_FQDN=$(postgresql_master_addr)
35+
initialize_replica
36+
37+
unset_env_vars
38+
echo "Starting server..."
39+
exec postgres "$@"

14/root/usr/bin/usage

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
cat /usr/share/container-scripts/postgresql/README.md
4+

14/root/usr/libexec/check-container

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#! /bin/sh
2+
3+
# Try whether the PostgreSQL in container accepts connections.
4+
#
5+
# With --live, be tolerant to starting PG server. If the /bin/postgres binary
6+
# has not been executed yet (the shell script is initializing the container),
7+
# wait for it (this script might run forever, we expect that the timeout is
8+
# maintained externally).
9+
10+
test -z "$ENABLED_COLLECTIONS" || . scl_source enable $ENABLED_COLLECTIONS
11+
12+
if test x"$1" = "x--live"; then
13+
# Since livenessProbe is about to detect container deadlocks, and we
14+
# so far don't know about real deadlocks to be detected -- we keep
15+
# liveness probe to report that container is always ready (as long as
16+
# we are able to execute shell, enable collections, etc., which is
17+
# good for container sanity testing anyways).
18+
exit 0
19+
fi
20+
21+
# Readiness check follows, the --timeout is set to "infinite" because it
22+
# is handled externally (readinessProbe.timeoutSeconds).
23+
pg_isready -q \
24+
-h 127.0.0.1 \
25+
${POSTGRESQL_USER+-U "$POSTGRESQL_USER"} \
26+
${POSTGRESQL_DATABASE+-d "$POSTGRESQL_DATABASE"} \
27+
--timeout 0

14/root/usr/libexec/fix-permissions

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
3+
documentation="\
4+
Recursively fix permissions on the given directories to allow GID=0
5+
read/write regular files and read/write/execute directories.
6+
7+
To run this command, you have to be in the group root=0!"
8+
9+
uid=26
10+
write=w
11+
12+
usage ()
13+
{
14+
cat >&2 <<EOF
15+
$0: Error: ${1-usage error}
16+
17+
Usage: $0 [--read-only] DIR [DIR ..]
18+
19+
$documentation
20+
EOF
21+
exit 1
22+
}
23+
24+
while test $# -gt 0; do
25+
case $1 in
26+
--read-only) write= ; shift ;;
27+
*) break ;;
28+
esac
29+
done
30+
31+
test $# -eq 0 && usage "no DIR specified"
32+
33+
for dir; do
34+
test -d "$dir" || usage "no such directory '$dir'"
35+
echo >&2 "fixing permissions on '$dir' directory"
36+
find "$dir" -exec chown "$uid:0" {} \;
37+
find "$dir" -exec chmod "g+r$write" {} \;
38+
find "$dir" -type d -exec chmod g+x {} +
39+
done

0 commit comments

Comments
 (0)