Skip to content

Commit

Permalink
Merge pull request #1272 from bcgov/release
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
DerekRoberts authored Apr 4, 2019
2 parents cfbb678 + 5f1b26a commit 88e801b
Show file tree
Hide file tree
Showing 64 changed files with 13,255 additions and 786 deletions.
104 changes: 59 additions & 45 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -384,33 +384,51 @@ def dbBackup (String envProject, String envSuffix) {
def dumpDir = "/var/lib/pgsql/data/deployment-backups"
def dumpName = "${envSuffix}-\$( date +%Y-%m-%d-%H%M ).dump"
def dumpOpts = "--no-privileges --no-tablespaces --schema=public --exclude-table=spatial_ref_sys"
return sh (
script: """
oc rsh -n ${envProject} dc/${dcName} bash -c ' \
set -e; \
mkdir -p ${dumpDir}; \
cd ${dumpDir}; \
pg_dump -U \${POSTGRESQL_USER} -d \${POSTGRESQL_DATABASE} -Fc -f ./${dumpName} ${dumpOpts}; \
ls -lh \
'
"""
)
}


// Database purge
def dbKeepOnly (String envProject, String envSuffix, int maxBackups = 10) {
def dcName = envSuffix == "dev" ? "${appName}-pgsql-${envSuffix}-${prNumber}" : "${appName}-pgsql-${envSuffix}"
def dumpDir = "/var/lib/pgsql/data/deployment-backups"
return sh (
script: """
oc rsh -n ${envProject} dc/${dcName} bash -c " \
find ${dumpDir} -name *.dump -printf '%Ts\t%p\n' \
| sort -nr | cut -f2 | tail -n +${maxBackups} | xargs rm 2>/dev/null\
|| echo 'No extra backups to remove'
"
"""
def dumpTemp = "/tmp/unverified.dump"
int maxBackups = 10

// Dump to temporary file
sh "oc rsh -n ${envProject} dc/${dcName} bash -c ' \
pg_dump -U \${POSTGRESQL_USER} -d \${POSTGRESQL_DATABASE} -Fc -f ${dumpTemp} ${dumpOpts} \
'"

// Verify dump size is at least 1M
int sizeAtLeast1M = sh (
script: "oc rsh -n ${envProject} dc/${dcName} bash -c ' \
du --threshold=1M ${dumpTemp} | wc -l \
'",
returnStdout: true
)
assert sizeAtLeast1M == 1

// Restore (schema only, w/ extensions) to temporary db
sh """
oc rsh -n ${envProject} dc/${dcName} bash -c ' \
set -e; \
psql -c "DROP DATABASE IF EXISTS db_verify"; \
createdb db_verify; \
psql -d db_verify -c "CREATE EXTENSION IF NOT EXISTS oracle_fdw;"; \
psql -d db_verify -c "CREATE EXTENSION IF NOT EXISTS postgis;"; \
psql -d db_verify -c "CREATE EXTENSION IF NOT EXISTS pgcrypto;"; \
psql -d db_verify -c "COMMIT;"; \
pg_restore -d db_verify --schema-only --create ${dumpTemp}; \
psql -c "DROP DATABASE IF EXISTS db_verify"
'
"""

// Store verified dump
sh "oc rsh -n ${envProject} dc/${dcName} bash -c ' \
mkdir -p ${dumpDir}; \
mv ${dumpTemp} ${dumpDir}/${dumpName}; \
ls -lh ${dumpDir} \
'"

// Database purge
sh "oc rsh -n ${envProject} dc/${dcName} bash -c \" \
find ${dumpDir} -name *.dump -printf '%Ts\t%p\n' \
| sort -nr | cut -f2 | tail -n +${maxBackups} | xargs rm 2>/dev/null \
|| echo 'No extra backups to remove' \
\""
}


Expand Down Expand Up @@ -798,7 +816,7 @@ pipeline {
"TAG=${stagingSuffix}",
"NAME=export",
"COMMAND=export",
"SCHEDULE='0 12 * * *'"
"SCHEDULE='30 11 * * *'"
)
openshift.apply(exportWellCronTemplate).label(
[
Expand Down Expand Up @@ -1017,7 +1035,7 @@ pipeline {
"TAG=${demoSuffix}",
"NAME=export",
"COMMAND=export",
"SCHEDULE='0 12 * * *'"
"SCHEDULE='30 11 * * *'"
)
openshift.apply(exportWellCronTemplate).label(
[
Expand Down Expand Up @@ -1093,6 +1111,18 @@ pipeline {
}


stage('PROD - Backup') {
when {
expression { env.CHANGE_TARGET == 'master' }
}
steps {
script {
dbBackup (prodProject, prodSuffix)
}
}
}


stage('PROD - Deploy') {
when {
expression { env.CHANGE_TARGET == 'master' }
Expand Down Expand Up @@ -1213,7 +1243,7 @@ pipeline {
"TAG=${prodSuffix}",
"NAME=export",
"COMMAND=export",
"SCHEDULE='0 12 * * *'"
"SCHEDULE='30 11 * * *'"
)
openshift.apply(exportWellCronTemplate).label(
[
Expand Down Expand Up @@ -1275,21 +1305,5 @@ pipeline {
}
}
}


stage('PROD - Post-Deploy Cleanup') {
when {
expression { env.CHANGE_TARGET == 'master' }
}
steps {
script {
// Backup
dbBackup (prodProject, prodSuffix)

// Clean backupsq
dbKeepOnly (prodProject, prodSuffix, 10)
}
}
}
}
}
3 changes: 2 additions & 1 deletion app/.s2i/bin/assemble
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ npm install
# npm run build
# Run unit tests in build stage with the code below
echo "--> testing and building frontend files"
npm run unit -- --runInBand && npm run build
npm run unit -- --runInBand
npm run build
cd ..

if should_collectstatic; then
Expand Down
Loading

0 comments on commit 88e801b

Please sign in to comment.