NERT-132: Database backup #440
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PR Based Deploy On OpenShift | |
# Builds and Deploys unmerged PR's to temporary pods/services/routes/etc in the OpenShift Dev environment. | |
name: PR-Based Deploy on OpenShift | |
on: | |
pull_request: | |
types: [opened, reopened, synchronize, ready_for_review] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.number }} | |
cancel-in-progress: true | |
jobs: | |
# Print variables for logging and debugging purposes | |
checkEnv: | |
name: Check Env variables | |
runs-on: ubuntu-latest | |
timeout-minutes: 20 | |
if: ${{ github.event.pull_request.merged == false }} | |
steps: | |
- name: Print Env Vars | |
run: | | |
echo OC CLI Version: $(oc version) | |
echo Git Base Ref: ${{ github.base_ref }} | |
echo Git Change ID: ${{ github.event.number }} | |
echo Git Pull Request Ref: ${{ github.event.pull_request.head.sha }} | |
echo Git Event Name: ${{ github.event_name }} | |
echo Git Event Action: ${{ github.event.action }} | |
echo Git Branch Ref: ${{ github.head_ref }} | |
echo PR in Draft: ${{ github.event.pull_request.draft }} | |
scaleDownPods: | |
name: Scale down the pods for this PR | |
runs-on: ubuntu-latest | |
timeout-minutes: 20 | |
env: | |
PR_NUMBER: ${{ github.event.number }} | |
needs: | |
- checkEnv | |
steps: | |
# Log in to OpenShift. | |
# Note: The secrets needed to log in are NOT available if the PR comes from a FORK. | |
# PR's must originate from a branch off the original repo or else all openshift `oc` commands will fail. | |
- name: Log in to OpenShift | |
run: oc login --token=${{ secrets.TOOLS_SA_TOKEN }} --server=https://api.silver.devops.gov.bc.ca:6443 | |
- name: Scale down | |
run: | | |
oc project d83219-dev | |
oc get deploymentconfig --selector env-id=$PR_NUMBER -o name | awk '{print "oc scale --replicas=0 " $1}' | bash | |
# Build the Database image | |
buildDatabase: | |
name: Build Database Image | |
runs-on: ubuntu-latest | |
timeout-minutes: 20 | |
if: ${{ github.event.pull_request.merged == false && github.event.pull_request.draft == false }} | |
env: | |
PR_NUMBER: ${{ github.event.number }} | |
needs: | |
- scaleDownPods | |
steps: | |
# Checkout the PR branch | |
- name: Checkout Target Branch | |
uses: actions/checkout@v3 | |
# Install Node - for `node` and `npm` commands | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 20 | |
# Cache Node modules | |
- name: Cache node modules | |
uses: actions/cache@v3 | |
env: | |
cache-name: cache-node-modules | |
with: | |
# npm cache files are stored in `~/.npm` on Linux/macOS | |
path: ~/.npm | |
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-build-${{ env.cache-name }}- | |
${{ runner.os }}-build- | |
${{ runner.os }}- | |
# Log in to OpenShift. | |
# Note: The secrets needed to log in are NOT available if the PR comes from a FORK. | |
# PR's must originate from a branch off the original repo or else all openshift `oc` commands will fail. | |
- name: Log in to OpenShift | |
run: oc login --token=${{ secrets.TOOLS_SA_TOKEN }} --server=https://api.silver.devops.gov.bc.ca:6443 | |
# Install database pipeline node modules | |
# Note: This already caches node modules internally | |
- name: Install pipeline node modules | |
working-directory: database/.pipeline/ | |
run: npm ci | |
# Build the database image | |
- name: Build Database Image | |
working-directory: "./database/.pipeline/" | |
run: | | |
DEBUG=* npm run db:build -- --pr=$PR_NUMBER | |
# Build the Database Setup image | |
buildDatabaseSetup: | |
name: Build Database Setup Image | |
runs-on: ubuntu-latest | |
timeout-minutes: 20 | |
if: ${{ github.event.pull_request.merged == false && github.event.pull_request.draft == false }} | |
env: | |
PR_NUMBER: ${{ github.event.number }} | |
needs: | |
- scaleDownPods | |
steps: | |
# Checkout the PR branch | |
- name: Checkout Target Branch | |
uses: actions/checkout@v3 | |
# Install Node - for `node` and `npm` commands | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 20 | |
# Cache Node modules | |
- name: Cache node modules | |
uses: actions/cache@v3 | |
env: | |
cache-name: cache-node-modules | |
with: | |
# npm cache files are stored in `~/.npm` on Linux/macOS | |
path: ~/.npm | |
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-build-${{ env.cache-name }}- | |
${{ runner.os }}-build- | |
${{ runner.os }}- | |
# Log in to OpenShift. | |
# Note: The secrets needed to log in are NOT available if the PR comes from a FORK. | |
# PR's must originate from a branch off the original repo or else all openshift `oc` commands will fail. | |
- name: Log in to OpenShift | |
run: oc login --token=${{ secrets.TOOLS_SA_TOKEN }} --server=https://api.silver.devops.gov.bc.ca:6443 | |
# Install database pipeline node modules | |
# Note: This already caches node modules internally | |
- name: Install pipeline node modules | |
working-directory: database/.pipeline/ | |
run: npm ci | |
# Build the database image | |
- name: Build Database Setup Image | |
working-directory: "./database/.pipeline/" | |
run: | | |
DEBUG=* npm run db-setup:build -- --pr=$PR_NUMBER | |
# Build the API image | |
buildAPI: | |
name: Build API Image | |
runs-on: ubuntu-latest | |
timeout-minutes: 20 | |
if: ${{ github.event.pull_request.merged == false && github.event.pull_request.draft == false }} | |
env: | |
PR_NUMBER: ${{ github.event.number }} | |
needs: | |
- scaleDownPods | |
steps: | |
# Checkout the PR branch | |
- name: Checkout Target Branch | |
uses: actions/checkout@v3 | |
# Install Node - for `node` and `npm` commands | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 20 | |
# Cache Node modules | |
- name: Cache node modules | |
uses: actions/cache@v3 | |
env: | |
cache-name: cache-node-modules | |
with: | |
# npm cache files are stored in `~/.npm` on Linux/macOS | |
path: ~/.npm | |
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-build-${{ env.cache-name }}- | |
${{ runner.os }}-build- | |
${{ runner.os }}- | |
# Log in to OpenShift. | |
# Note: The secrets needed to log in are NOT available if the PR comes from a FORK. | |
# PR's must originate from a branch off the original repo or else all openshift `oc` commands will fail. | |
- name: Log in to OpenShift | |
run: oc login --token=${{ secrets.TOOLS_SA_TOKEN }} --server=https://api.silver.devops.gov.bc.ca:6443 | |
# Install api pipeline node modules | |
# Note: This already caches node modules internally | |
- name: Install pipeline node modules | |
working-directory: api/.pipeline/ | |
run: npm ci | |
# Build the api image | |
- name: Build API Image | |
working-directory: "./api/.pipeline/" | |
run: | | |
DEBUG=* npm run build -- --pr=$PR_NUMBER | |
# Build the web frontend app image | |
buildAPP: | |
name: Build App Image | |
runs-on: ubuntu-latest | |
timeout-minutes: 20 | |
if: ${{ github.event.pull_request.merged == false && github.event.pull_request.draft == false }} | |
env: | |
PR_NUMBER: ${{ github.event.number }} | |
needs: | |
- scaleDownPods | |
steps: | |
# Checkout the PR branch | |
- name: Checkout Target Branch | |
uses: actions/checkout@v3 | |
# Install Node - for `node` and `npm` commands | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 20 | |
# Cache Node modules | |
- name: Cache node modules | |
uses: actions/cache@v3 | |
env: | |
cache-name: cache-node-modules | |
with: | |
# npm cache files are stored in `~/.npm` on Linux/macOS | |
path: ~/.npm | |
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-build-${{ env.cache-name }}- | |
${{ runner.os }}-build- | |
${{ runner.os }}- | |
# Log in to OpenShift. | |
# Note: The secrets needed to log in are NOT available if the PR comes from a FORK. | |
# PR's must originate from a branch off the original repo or else all openshift `oc` commands will fail. | |
- name: Log in to OpenShift | |
run: oc login --token=${{ secrets.TOOLS_SA_TOKEN }} --server=https://api.silver.devops.gov.bc.ca:6443 | |
# Install app pipeline node modules | |
# Note: This already caches node modules internally | |
- name: Install pipeline node modules | |
working-directory: app/.pipeline/ | |
run: npm ci | |
# Build the app image | |
- name: Build APP Image | |
working-directory: "./app/.pipeline/" | |
run: | | |
DEBUG=* npm run build -- --pr=$PR_NUMBER | |
# Deploy Database image | |
deployDatabase: | |
name: Deploy Database Image | |
runs-on: ubuntu-latest | |
timeout-minutes: 20 | |
if: ${{ github.event.pull_request.merged == false && github.event.pull_request.draft == false }} | |
env: | |
PR_NUMBER: ${{ github.event.number }} | |
BRANCH: ${{ github.base_ref }} | |
needs: | |
- buildDatabase | |
steps: | |
# Checkout the PR branch | |
- name: Checkout Target Branch | |
uses: actions/checkout@v3 | |
# Install Node - for `node` and `npm` commands | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 20 | |
# Cache Node modules | |
- name: Cache node modules | |
uses: actions/cache@v3 | |
env: | |
cache-name: cache-node-modules | |
with: | |
# npm cache files are stored in `~/.npm` on Linux/macOS | |
path: ~/.npm | |
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-build-${{ env.cache-name }}- | |
${{ runner.os }}-build- | |
${{ runner.os }}- | |
# Log in to OpenShift. | |
# Note: The secrets needed to log in are NOT available if the PR comes from a FORK. | |
# PR's must originate from a branch off the original repo or else all openshift `oc` commands will fail. | |
- name: Log in to OpenShift | |
run: oc login --token=${{ secrets.TOOLS_SA_TOKEN }} --server=https://api.silver.devops.gov.bc.ca:6443 | |
# Install database pipeline node modules | |
# Note: This already caches node modules internally | |
- name: Install pipeline node modules | |
working-directory: database/.pipeline/ | |
run: npm ci | |
# Deploy the database image | |
- name: Deploy Database Image | |
working-directory: "./database/.pipeline/" | |
run: | | |
DEBUG=* npm run db:deploy -- --pr=$PR_NUMBER --env=dev | |
# Deploy Database image | |
deployDatabaseSetup: | |
name: Deploy Database Setup Image | |
runs-on: ubuntu-latest | |
timeout-minutes: 20 | |
if: ${{ github.event.pull_request.merged == false && github.event.pull_request.draft == false }} | |
env: | |
PR_NUMBER: ${{ github.event.number }} | |
BRANCH: ${{ github.base_ref }} | |
needs: | |
- buildDatabaseSetup | |
- deployDatabase | |
steps: | |
# Checkout the PR branch | |
- name: Checkout Target Branch | |
uses: actions/checkout@v3 | |
# Install Node - for `node` and `npm` commands | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 20 | |
# Cache Node modules | |
- name: Cache node modules | |
uses: actions/cache@v3 | |
env: | |
cache-name: cache-node-modules | |
with: | |
# npm cache files are stored in `~/.npm` on Linux/macOS | |
path: ~/.npm | |
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-build-${{ env.cache-name }}- | |
${{ runner.os }}-build- | |
${{ runner.os }}- | |
# Log in to OpenShift. | |
# Note: The secrets needed to log in are NOT available if the PR comes from a FORK. | |
# PR's must originate from a branch off the original repo or else all openshift `oc` commands will fail. | |
- name: Log in to OpenShift | |
run: oc login --token=${{ secrets.TOOLS_SA_TOKEN }} --server=https://api.silver.devops.gov.bc.ca:6443 | |
# Install database pipeline node modules | |
# Note: This already caches node modules internally | |
- name: Install pipeline node modules | |
working-directory: database/.pipeline/ | |
run: npm ci | |
# Deploy the database setup image | |
- name: Deploy Database Setup Image | |
working-directory: "./database/.pipeline/" | |
run: | | |
DEBUG=* npm run db-setup:deploy -- --pr=$PR_NUMBER --env=dev | |
# Deploy API image | |
deployAPI: | |
name: Deploy API Image | |
runs-on: ubuntu-latest | |
timeout-minutes: 20 | |
if: ${{ github.event.pull_request.merged == false && github.event.pull_request.draft == false }} | |
env: | |
PR_NUMBER: ${{ github.event.number }} | |
BRANCH: ${{ github.base_ref }} | |
needs: | |
- buildAPI | |
- deployDatabase | |
steps: | |
# Checkout the PR branch | |
- name: Checkout Target Branch | |
uses: actions/checkout@v3 | |
# Install Node - for `node` and `npm` commands | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 20 | |
# Cache Node modules | |
- name: Cache node modules | |
uses: actions/cache@v3 | |
env: | |
cache-name: cache-node-modules | |
with: | |
# npm cache files are stored in `~/.npm` on Linux/macOS | |
path: ~/.npm | |
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-build-${{ env.cache-name }}- | |
${{ runner.os }}-build- | |
${{ runner.os }}- | |
# Log in to OpenShift. | |
# Note: The secrets needed to log in are NOT available if the PR comes from a FORK. | |
# PR's must originate from a branch off the original repo or else all openshift `oc` commands will fail. | |
- name: Log in to OpenShift | |
run: oc login --token=${{ secrets.TOOLS_SA_TOKEN }} --server=https://api.silver.devops.gov.bc.ca:6443 | |
# Install api pipeline node modules | |
# Note: This already caches node modules internally | |
- name: Install pipeline node modules | |
working-directory: api/.pipeline/ | |
run: npm ci | |
# Deploy the api image | |
- name: Deploy API Image | |
working-directory: "./api/.pipeline/" | |
run: | | |
DEBUG=* npm run deploy -- --pr=$PR_NUMBER --env=dev | |
# Deploy App image | |
deployAPP: | |
name: Deploy App Image | |
runs-on: ubuntu-latest | |
timeout-minutes: 20 | |
if: ${{ github.event.pull_request.merged == false && github.event.pull_request.draft == false }} | |
env: | |
PR_NUMBER: ${{ github.event.number }} | |
BRANCH: ${{ github.base_ref }} | |
needs: | |
- buildAPP | |
steps: | |
# Checkout the PR branch | |
- name: Checkout Target Branch | |
uses: actions/checkout@v3 | |
# Install Node - for `node` and `npm` commands | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 20 | |
# Cache Node modules | |
- name: Cache node modules | |
uses: actions/cache@v3 | |
env: | |
cache-name: cache-node-modules | |
with: | |
# npm cache files are stored in `~/.npm` on Linux/macOS | |
path: ~/.npm | |
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-build-${{ env.cache-name }}- | |
${{ runner.os }}-build- | |
${{ runner.os }}- | |
# Log in to OpenShift. | |
# Note: The secrets needed to log in are NOT available if the PR comes from a FORK. | |
# PR's must originate from a branch off the original repo or else all openshift `oc` commands will fail. | |
- name: Log in to OpenShift | |
run: oc login --token=${{ secrets.TOOLS_SA_TOKEN }} --server=https://api.silver.devops.gov.bc.ca:6443 | |
# Install app pipeline node modules | |
# Note: This already caches node modules internally | |
- name: Install pipeline node modules | |
working-directory: app/.pipeline/ | |
run: npm ci | |
# Deploy the app image | |
- name: Deploy App Image | |
working-directory: "./app/.pipeline" | |
run: | | |
DEBUG=* npm run deploy -- --pr=$PR_NUMBER --env=dev | |
cypress-run: | |
runs-on: ubuntu-latest | |
timeout-minutes: 20 | |
if: ${{ github.event.pull_request.merged == false && github.event.pull_request.draft == false && github.base_ref != 'prod' }} | |
env: | |
CYPRESS_RECORD_KEY: ${{ secrets.RECORDING_KEY }} | |
CYPRESS_username: ${{ secrets.CYPRESS_USER_NAME }} | |
CYPRESS_password: ${{ secrets.CYPRESS_PASSWORD }} | |
CYPRESS_BASE_URL: 'https://restoration-tracker-app-${{ github.event.number }}-d83219-dev.apps.silver.devops.gov.bc.ca' | |
CYPRESS_host: 'https://restoration-tracker-app-${{ github.event.number }}-d83219-dev.apps.silver.devops.gov.bc.ca' | |
CYPRESS_ENVIRONMENT: ${{ github.base_ref }} | |
CYPRESS_authRealm: 'standard' | |
CYPRESS_authClientId: 'nert-public-5352' | |
CYPRESS_authUrl: 'https://dev.loginproxy.gov.bc.ca' | |
needs: | |
- deployDatabase | |
- deployDatabaseSetup | |
- deployAPI | |
- deployAPP | |
steps: | |
# Checkout the PR branch | |
- name: Checkout Target Branch | |
uses: actions/checkout@v3 | |
- name: Wait for API response | |
uses: nev7n/[email protected] | |
with: | |
url: 'https://restoration-tracker-api-${{ github.event.number }}-d83219-dev.apps.silver.devops.gov.bc.ca/version' | |
responseCode: 200 | |
timeout: 240000 | |
interval: 500 | |
- name: Wait for APP response | |
uses: nev7n/[email protected] | |
with: | |
url: 'https://restoration-tracker-app-${{ github.event.number }}-d83219-dev.apps.silver.devops.gov.bc.ca' | |
responseCode: 200 | |
timeout: 120000 | |
interval: 500 | |
- name: E2E Smoke tests | |
uses: cypress-io/github-action@v2 | |
# let's give this action an ID so we can refer | |
# to its output values later | |
id: smoke | |
continue-on-error: false | |
with: | |
wait-on: 'https://restoration-tracker-app-${{ github.event.number }}-d83219-dev.apps.silver.devops.gov.bc.ca' | |
wait-on-timeout: 120 | |
record: true | |
working-directory: testing/e2e | |
spec: cypress/integration/smoke*.spec.ts | |
browser: chrome | |
ci-build-id: ${{ github.event.number }} | |
- name: Print Env Vars | |
run: | | |
echo Git Base Ref: ${{ github.base_ref }} | |
echo Git Change ID: ${{ github.event.number }} | |
echo Cypress BaseUrl: $CYPRESS_BASE_URL | |
echo Cypress Host: $CYPRESS_ENVIRONMENT | |
echo $CYPRESS_authRealm | |
echo $CYPRESS_authClientId | |
echo $CYPRESS_authUrl |