Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIMSBIOHUB-449: Upgrade Postgres Version #1380

Closed
wants to merge 13 commits into from
2 changes: 1 addition & 1 deletion database/.docker/db/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This DockerFile is used for local development (via compose.yml) only.
# ########################################################################################################

ARG POSTGRES_VERSION=14.2
ARG POSTGRES_VERSION=15-bullseye

FROM postgres:$POSTGRES_VERSION

Expand Down
4 changes: 2 additions & 2 deletions database/.pipeline/lib/db.deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const dbDeploy = async (settings) => {
DATABASE_SERVICE_NAME: `${name}-postgresql${phases[phase].suffix}`,
IMAGE_STREAM_NAME: name,
IMAGE_STREAM_VERSION: phases.build.tag,
POSTGRESQL_DATABASE: 'biohubbc',
POSTGRES_DB: 'biohubbc',
TZ: phases[phase].tz,
IMAGE_STREAM_NAMESPACE: phases.build.namespace,
VOLUME_CAPACITY: phases[phase].volumeCapacity,
Expand All @@ -46,7 +46,7 @@ const dbDeploy = async (settings) => {

oc.applyRecommendedLabels(objects, name, phase, changeId, instance);
oc.importImageStreams(objects, phases[phase].tag, phases.build.namespace, phases.build.tag);

await oc.applyAndDeploy(objects, instance);
};

Expand Down
4 changes: 2 additions & 2 deletions database/.pipeline/templates/db.bc.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kind: Template
apiVersion: template.openshift.io/v1
metadata:
name: postgresql null
name: postgresql
parameters:
- name: NAME
displayName: Name
Expand Down Expand Up @@ -29,7 +29,7 @@ objects:
annotations:
from:
kind: ImageStreamTag
name: postgis-postgres:12-31
name: postgres-postgis:15-bullseye
namespace: af2668-tools
generation: 1
importPolicy: {}
Expand Down
104 changes: 38 additions & 66 deletions database/.pipeline/templates/db.dc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,43 @@ parameters:
name: NAME
required: true
value: 'postgresql'
- description: The OpenShift ImageStream name.
displayName: IMAGE_STREAM_NAME
name: IMAGE_STREAM_NAME
value: 'postgis-postgres'
- description: The OpenShift Namespace where the ImageStream resides.
displayName: Namespace
name: IMAGE_STREAM_NAMESPACE
- name: IMAGE_STREAM_NAMESPACE
description: The OpenShift Namespace where the ImageStream resides.
required: true
value: 'af2668-tools'
- name: IMAGE_STREAM_NAME
description: The OpenShift ImageStream name.
required: true
value: 'postgres-postgis'
- name: IMAGE_STREAM_VERSION
description: Version of PostgreSQL image to be used (9.2, 9.4, 9.5 or latest).
required: true
value: '15-bullseye'
- description: The name of the OpenShift Service exposed for the database.
displayName: Database Service Name
name: DATABASE_SERVICE_NAME
required: true
value: 'postgresql'
- description: Username for PostgreSQL user that will be used for accessing the database.
displayName: PostgreSQL Connection Username
name: POSTGRESQL_USER
required: true
value: 'postgres'
- description: Admin Username for PostgreSQL user that will be used for accessing the database.
displayName: PostgreSQL Admin Connection Username
name: POSTGRESQL_ADMIN_USER
name: POSTGRES_USER
required: true
value: 'postgres'
- description: Password for the PostgreSQL connection user.
displayName: PostgreSQL Connection Password
from: '[a-zA-Z0-9]{16}'
generate: expression
name: POSTGRESQL_PASSWORD
required: true
- description: Password for the PostgreSQL admin user.
displayName: PostgreSQL Admin Connection Password
from: '[a-zA-Z0-9]{16}'
generate: expression
name: POSTGRESQL_ADMIN_PASSWORD
name: POSTGRES_PASSWORD
required: true
- description: Name of the PostgreSQL database accessed.
displayName: PostgreSQL Database Name
name: POSTGRESQL_DATABASE
name: POSTGRES_DB
required: true
value: 'biohubbc'
- name: PGDATA
description: Path to PostgreSQL data directory
value: '/var/lib/pgsql/data/userdata'
required: false
- name: TZ
description: Database timezone
required: false
Expand All @@ -61,19 +58,6 @@ parameters:
name: VOLUME_CAPACITY
required: true
value: '500Mi'
- description: Version of PostgreSQL image to be used (9.2, 9.4, 9.5 or latest).
displayName: Version of PostgreSQL Image
name: IMAGE_STREAM_VERSION
required: true
value: '12-31'
- description: Indicator to enable pgcrypto extension (provided out-of-the-box with PostgreSQL).
displayName: Flag to enable pgcrypto PostgreSQL extension.
name: PGCRYPTO_EXTENSION
value: 'Y'
- description: Indicator to enable postgis extension (from official PostgeSQL YUM repo).
displayName: Flag to enable postgis PostgreSQL extension.
name: POSTGIS_EXTENSION
value: 'Y'
- name: CPU_REQUEST
value: '50m'
- name: CPU_LIMIT
Expand All @@ -90,16 +74,14 @@ objects:
metadata:
annotations:
template.openshift.io/expose-database_name: "{.data['database-name']}"
template.openshift.io/expose-password: "{.data['database-user-password']}"
template.openshift.io/expose-admin-password: "{.data['database-admin-password']}"
template.openshift.io/expose-admin-username: "{.data['database-user']}"
template.openshift.io/expose-database-user: "{.data['database-admin']}"
template.openshift.io/expose-database-user-password: "{.data['database-admin-password']}"
as-copy-of: biohubbc-creds
name: '${DATABASE_SERVICE_NAME}'
stringData:
database-name: '${POSTGRESQL_DATABASE}'
database-user-password: '${POSTGRESQL_PASSWORD}'
database-admin-password: '${POSTGRESQL_ADMIN_PASSWORD}'
database-user: '${POSTGRESQL_USER}'
database-name: '${POSTGRES_DB}'
database-user: '${POSTGRES_USER}'
database-user-password: '${POSTGRES_PASSWORD}'

- kind: Service
apiVersion: v1
Expand Down Expand Up @@ -165,30 +147,23 @@ objects:
containers:
- name: postgresql
env:
- name: POSTGRESQL_USER
- name: POSTGRES_DB
valueFrom:
secretKeyRef:
key: database-user
key: database-name
name: '${DATABASE_SERVICE_NAME}'
- name: POSTGRESQL_PASSWORD
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
key: database-user-password
key: database-admin
name: '${DATABASE_SERVICE_NAME}'
- name: POSTGRESQL_ADMIN_PASSWORD
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
key: database-admin-password
name: '${DATABASE_SERVICE_NAME}'
- name: POSTGRESQL_DATABASE
valueFrom:
secretKeyRef:
key: database-name
name: '${DATABASE_SERVICE_NAME}'
- name: PGCRYPTO_EXTENSION
value: 'N'
- name: POSTGIS_EXTENSION
value: 'N'
- name: PGDATA
value: '${PGDATA}'
- name: PGOPTIONS
value: '-c maintenance_work_mem=128MB'
- name: PGTZ
Expand All @@ -209,7 +184,7 @@ objects:
- '/bin/sh'
- '-i'
- '-c'
- psql -h 127.0.0.1 -U $POSTGRESQL_USER -q -d $POSTGRESQL_DATABASE -c 'SELECT 1'
- psql -h 127.0.0.1 -U $POSTGRES_USER -q -d $POSTGRES_DB -c 'SELECT 1'
initialDelaySeconds: 5
timeoutSeconds: 1
resources:
Expand All @@ -219,23 +194,21 @@ objects:
limits:
cpu: ${CPU_LIMIT}
memory: ${MEMORY_LIMIT}
securityContext:
capabilities: {}
privileged: false
securityContext: {}
terminationMessagePath: '/dev/termination-log'
volumeMounts:
- mountPath: '/var/lib/pgsql/data'
name: '${DATABASE_SERVICE_NAME}-data'
- mountPath: '/var/run/postgresql'
name: '${DATABASE_SERVICE_NAME}-run'
- name: '${DATABASE_SERVICE_NAME}-data'
mountPath: '/var/lib/pgsql/data'
# - name: '${DATABASE_SERVICE_NAME}-run'
# mountPath: '/var/run/postgresql'
dnsPolicy: ClusterFirst
restartPolicy: Always
volumes:
- name: '${DATABASE_SERVICE_NAME}-data'
persistentVolumeClaim:
claimName: '${DATABASE_SERVICE_NAME}'
- name: '${DATABASE_SERVICE_NAME}-run'
emptyDir: {}
# - name: '${DATABASE_SERVICE_NAME}-run'
# emptyDir: {}
triggers:
- imageChangeParams:
automatic: true
Expand All @@ -245,6 +218,5 @@ objects:
kind: ImageStreamTag
name: '${IMAGE_STREAM_NAME}:${IMAGE_STREAM_VERSION}'
namespace: '${IMAGE_STREAM_NAMESPACE}'
lastTriggeredImage: ''
type: ImageChange
- type: ConfigChange
80 changes: 80 additions & 0 deletions database/.pipeline/templates/prereqs/postgres-postgis.is.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# ########################################################################################################
# Creates a build config that builds the database dockerfile
# Creates an imagestream that references the built database image
# ########################################################################################################

kind: Template
apiVersion: template.openshift.io/v1
metadata:
name: postgresql
parameters:
# Imagestream
- name: IMAGE_STREAM_NAMESPACE
value: af2668-tools
- name: IMAGE_STREAM_NAME
value: postgres-postgis
- name: IMAGE_STREAM_VERSION
value: 15-bullseye
# Dockerfile
- name: SOURCE_CONTEXT_DIR
value: 'database'
- name: SOURCE_REPOSITORY_REF
value: dev
- name: SOURCE_REPOSITORY_URL
value: https://github.com/bcgov/biohubbc.git
- name: DOCKER_FILE_PATH
value: Dockerfile
# Resources
- name: CPU_REQUEST
value: '50m'
- name: CPU_LIMIT
value: '200m'
- name: MEMORY_REQUEST
value: '100Mi'
- name: MEMORY_LIMIT
value: '2Gi'
objects:
- kind: ImageStream
apiVersion: image.openshift.io/v1
metadata:
name: '${IMAGE_STREAM_NAME}'
labels:
shared: 'true'
spec:
lookupPolicy:
local: false

- kind: BuildConfig
apiVersion: v1
metadata:
name: '${IMAGE_STREAM_NAME}'
spec:
failedBuildsHistoryLimit: 5
nodeSelector:
output:
to:
kind: ImageStreamTag
name: '${IMAGE_STREAM_NAME}:${IMAGE_STREAM_VERSION}'
postCommit: {}
resources:
requests:
cpu: ${CPU_REQUEST}
memory: ${MEMORY_REQUEST}
limits:
cpu: ${CPU_LIMIT}
memory: ${MEMORY_LIMIT}
runPolicy: SerialLatestOnly
source:
type: Git
git:
uri: '${SOURCE_REPOSITORY_URL}'
ref: '${SOURCE_REPOSITORY_REF}'
contextDir: '${SOURCE_CONTEXT_DIR}'
strategy:
type: Docker
dockerStrategy:
dockerfilePath: ${DOCKER_FILE_PATH}
successfulBuildsHistoryLimit: 5
triggers:
- type: ConfigChange
- type: ImageChange
37 changes: 37 additions & 0 deletions database/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# ########################################################################################################
# This DockerFile is used for Openshift deployments only.
# ########################################################################################################

ARG POSTGRES_VERSION=15-bullseye

FROM postgres:$POSTGRES_VERSION

# read env variables
ARG TZ=America/Vancouver
ARG POSTGIS_VERSION=3

ENV PORT=5432

# install postgis packages
RUN mkdir -p /opt/apps
RUN apt-get -qq update
RUN apt-get -qq install -y --no-install-recommends postgresql-$PG_MAJOR-postgis-$POSTGIS_VERSION
RUN apt-get -qq install -y --no-install-recommends postgresql-$PG_MAJOR-postgis-$POSTGIS_VERSION-scripts
RUN apt-get -qq install -y --no-install-recommends postgresql-$PG_MAJOR-pgrouting
RUN apt-get -qq install -y --no-install-recommends postgresql-$PG_MAJOR-pgrouting-scripts
RUN apt-get -qq install -y --no-install-recommends postgresql-server-dev-$PG_MAJOR
RUN apt-get -qq install -y --no-install-recommends pgbadger pg-activity wget unzip nano
RUN apt-get -qq purge -y --auto-remove postgresql-server-dev-$PG_MAJOR
RUN apt-get -qq autoremove -y
RUN apt-get -qq clean

# set time zone
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# copy postgis init script to docker init directory
RUN mkdir -p /docker-entrypoint-initdb.d
COPY ./.docker/db/create_postgis.sql /docker-entrypoint-initdb.d/postgis.sql

EXPOSE $PORT

CMD ["postgres"]
2 changes: 1 addition & 1 deletion database/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| ---------- | ------- | ------------------------------------ | -------------------- |
| node | 18.x.x | https://nodejs.org/en/ | JavaScript Runtime |
| npm | 10.x.x | https://www.npmjs.com/ | Node Package Manager |
| PostgreSQL | 12.5 | https://www.postgresql.org/download/ | PSQL database |
| PostgreSQL | 14.2 | https://www.postgresql.org/download/ | PSQL database |
| PostGIS | 3 | https://postgis.net/ | GIS (spatial) tools |

<br />
Expand Down
2 changes: 1 addition & 1 deletion env_config/env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ CB_API_HOST=https://moe-critterbase-api-dev.apps.silver.devops.gov.bc.ca/api
#
# See `biohubbc-creds` secret in openshift
# ------------------------------------------------------------------------------
POSTGRES_VERSION=14.2
POSTGRES_VERSION=15-bullseye
POSTGIS_VERSION=3
DB_HOST=db
DB_ADMIN=postgres
Expand Down
Loading