Skip to content

Commit

Permalink
trying to get around SCL Postgres container limitations
Browse files Browse the repository at this point in the history
  • Loading branch information
alecmerdler committed Oct 19, 2020
1 parent 5e21bfc commit f9669ab
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 11 deletions.
1 change: 0 additions & 1 deletion kustomize/components/clair/postgres.deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ spec:
claimName: clair-postgres
securityContext:
fsGroup: 0
defaultMode: 0740
containers:
- name: postgres
image: postgres:latest
Expand Down
13 changes: 10 additions & 3 deletions kustomize/components/postgres/create-extensions.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/bin/sh

echo "attempting to install required pg_trgm extension"

psql -d $POSTGRESQL_DATABASE -c 'CREATE EXTENSION pg_trgm;'
# FIXME(alecmerdler): Wait until `PG_INITIALIZED` is not false, then run the below command
while true; do
sleep 10
echo $PG_INITIALIZED
if [[ "$PG_INITIALIZED" != "false" ]]; then
echo "database initialized, creating pg_trgm extension"
psql -d $POSTGRESQL_DATABASE -h $POSTGRESQL_DATABASE -U postgres -c 'CREATE EXTENSION pg_trgm;'
break
fi
done
2 changes: 2 additions & 0 deletions kustomize/components/postgres/migrate.job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ spec:
image: postgres:latest
env:
- name: DB_URI
# FIXME(alecmerdler): Change value...
value: postgresql://old-quay-database:old-quay-database@old-quay-postgresql/old-quay-database
command:
- "pg_dump"
- "$(DB_URI)"
- "--format"
- "c"
- "--file"
# FIXME(alecmerdler): Fix this for SCL Postgres container.
- "/var/lib/postgresql/data/dump.sql"
volumeMounts:
- name: postgres-data
Expand Down
21 changes: 18 additions & 3 deletions kustomize/components/postgres/postgres.deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ spec:
- name: postgres-bootstrap
secret:
secretName: postgres-bootstrap
defaultMode: 0777
items:
- key: create-extensions.sh
path: create-extensions.sh
- key: restore.sh
path: restore.sh
securityContext:
fsGroup: 0
# FIXME(alecmerdler): This is not being marshaled from octal correctly (probably due to our YAML library) and is turing into `420`
defaultMode: 0740
containers:
- name: postgres
image: postgres:latest
Expand All @@ -42,6 +41,8 @@ spec:
value: $(POSTGRES_DEPLOYMENT_NAME)
- name: POSTGRESQL_DATABASE
value: $(POSTGRES_DEPLOYMENT_NAME)
- name: POSTGRESQL_ADMIN_PASSWORD
value: postgres
- name: POSTGRESQL_PASSWORD
value: postgres
- name: POSTGRESQL_SHARED_BUFFERS
Expand All @@ -51,5 +52,19 @@ spec:
volumeMounts:
- name: postgres-data
mountPath: /var/lib/pgsql/data
# FIXME(alecmerdler): `postgresql-init` does not work because the Quay database hasn't been created yet...
# - name: postgres-bootstrap
# mountPath: /opt/app-root/src/postgresql-init
# TODO(alecmerdler): Run another container which runs installs the `pg_trgm` extension to the Quay database (since the SCL container does not support post-init hooks...)
- name: postgres-extensions
image: postgres:latest
command:
- /opt/app-root/src/docker-entrypoint-initdb.d/create-extensions.sh
env:
- name: POSTGRESQL_DATABASE
value: $(POSTGRES_DEPLOYMENT_NAME)
- name: PGPASSWORD
value: postgres
volumeMounts:
- name: postgres-bootstrap
mountPath: /opt/app-root/src/postgresql-init
mountPath: /opt/app-root/src/docker-entrypoint-initdb.d
4 changes: 3 additions & 1 deletion kustomize/components/postgres/restore.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/sh

# NOTE: The Postgres container will not run this init script if `$PGDATA` is populated, so no need to have extra checks here to prevent re-restoring.
# FIXME(alecmerdler): Ensure this only runs once...

# FIXME(alecmerdler): This file path is wrong for SCL Postgres...
RESTORE_FILE=/var/lib/postgresql/data/dump.sql

if [ -f "$RESTORE_FILE" ]; then
Expand Down
2 changes: 1 addition & 1 deletion kustomize/overlays/downstream/v3.4.0/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ images:
newName: registry.access.redhat.com/rhscl/redis-32-rhel7
- name: postgres
newName: registry.access.redhat.com/rhscl/postgresql-10-rhel7
newTag: 1-35
newTag: latest
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ images:
newName: registry.access.redhat.com/rhscl/redis-32-rhel7
- name: postgres
newName: registry.access.redhat.com/rhscl/postgresql-10-rhel7
newTag: 1-35
# FIXME(alecmerdler): Need to handle `redhat-pull-secret` (potentially with a `secretGenerator`?)...
newTag: latest

0 comments on commit f9669ab

Please sign in to comment.