Skip to content

Commit c06e7eb

Browse files
authored
Merge pull request #143 from WadeBarnes/hard-reset
Tooling Updates
2 parents 44ec67e + c18b02a commit c06e7eb

14 files changed

+366
-56
lines changed

.devcontainer/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM mcr.microsoft.com/devcontainers/base:noble
2+
3+
# Install oc cli
4+
RUN curl -s -L https://downloads-openshift-console.apps.silver.devops.gov.bc.ca/arm64/linux/oc.tar | \
5+
tar -xv -C /usr/local/bin
6+
7+
# Install openshift-developer-tools scripts
8+
RUN curl -L -O https://github.com/BCDevOps/openshift-developer-tools/archive/refs/heads/master.zip && \
9+
unzip master.zip && \
10+
mv ./openshift-developer-tools-master/bin /usr/local/bin/openshift-developer-tools && \
11+
rm -rf ./openshift-developer-tools-master master.zip
12+
13+
# Install dev-tools (for docker scripts)
14+
RUN curl -L -O https://github.com/WadeBarnes/dev-tools/archive/refs/heads/main.zip && \
15+
unzip main.zip && \
16+
mv ./dev-tools-main /usr/local/bin/dev-tools && \
17+
find /usr/local/bin/dev-tools/ -name *.sh -exec chmod +x {} \; && \
18+
rm -rf ./dev-tools-main main.zip
19+
20+
# Update Path
21+
ENV PATH="$PATH:/usr/local/bin/openshift-developer-tools:/usr/local/bin/dev-tools/docker/scripts"

.devcontainer/devcontainer.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
3+
{
4+
"name": "DITP-DevOps",
5+
// Reference https://containers.dev/guide/dockerfile
6+
"build": {
7+
"dockerfile": "Dockerfile",
8+
"context": "."
9+
},
10+
// Features to add to the dev container. More info: https://containers.dev/features.
11+
"features": {
12+
"ghcr.io/devcontainers/features/docker-from-docker:1.6.0": {}
13+
},
14+
// Allows the local folder to be redirected to the workspace folder
15+
// in situations where you're mounting volumes into containers
16+
// such as when using docker-compose
17+
// example; "${LOCAL_WORKSPACE_FOLDER-..}/web/package.json:/opt/app-root/src/package.json"
18+
"containerEnv": {
19+
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}"
20+
}
21+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
22+
// "forwardPorts": [],
23+
// Use 'postCreateCommand' to run commands after the container is created.
24+
// "postCreateCommand": "uname -a",
25+
// Configure tool-specific properties.
26+
// "customizations": {},
27+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
28+
// "remoteUser": "root"
29+
}

.github/dependabot.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# For details on how this file works refer to:
2+
# - https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
3+
version: 2
4+
updates:
5+
- package-ecosystem: "devcontainers"
6+
directory: "/"
7+
schedule:
8+
interval: weekly
9+
10+
- package-ecosystem: "docker"
11+
directory: "/.devcontainer"
12+
schedule:
13+
interval: weekly

openshift/manage

Lines changed: 105 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ usage () {
2828
- Reset the environment.
2929
- All data will be lost.
3030
The following operations will be performed:
31-
- The process pauses at the beginning to ensure the related ICIA reset process has started.
32-
- The wallet is reset, by restoring initial copy of ICOB Wallet.
31+
- The process pauses at the beginning to ensure the related BC Registries Agent reset process has started.
32+
- The wallet is reset, by restoring initial copy of OrgBook Wallet.
3333
- The 'db' is reset and reinitialized.
3434
- The search indexes are reset.
35-
- The process pauses to ensure the related ICIA registration process has had time to complete.
36-
- The ICIA registration is verified.\n
35+
- The process pauses to ensure the related BC Registries Agent registration process has had time to complete.
36+
- The BC Registries Agent registration is verified.\n
3737
3838
resetDatabase
3939
- Drop and recreate the database.
@@ -357,6 +357,20 @@ offlineIndexerResourceSuffix=${offlineIndexerResourceSuffix:--oli}
357357
# Process the local command line arguments and pass everything else along.
358358
# - The 'getopts' options string must start with ':' for this to work.
359359
# -----------------------------------------------------------------------------------------------------------------
360+
for arg in "$@"; do
361+
# Remove recognized arguments from the list after processing.
362+
shift
363+
case "$arg" in
364+
--hard-reset)
365+
HARD_RESET=1
366+
;;
367+
*)
368+
# If not recognized, save it for later processing ...
369+
set -- "$@" "$arg"
370+
;;
371+
esac
372+
done
373+
360374
while [ ${OPTIND} -le $# ]; do
361375
if getopts :s: FLAG; then
362376
case ${FLAG} in
@@ -457,6 +471,14 @@ function deleteDatabase() {
457471
echoWarning "\nThe databases on ${_dbPodName}${resourceSuffix} have been deleted."
458472
}
459473

474+
function hardReset() {
475+
if [ ! -z ${HARD_RESET} ]; then
476+
return 0
477+
else
478+
return 1
479+
fi
480+
}
481+
460482
function reset() {
461483
(
462484
agentPod=${1}
@@ -479,7 +501,7 @@ function reset() {
479501

480502
# Explain what is about to happen and wait for confirmation ...
481503
txtMsg=$(cat <<-EOF
482-
The [${targetNamespace}] ICOB environment will be reset using the following settings:
504+
The [${targetNamespace}] OrgBook environment will be reset using the following settings:
483505
- agentPod: ${agentPod}${resourceSuffix}
484506
- apiPod: ${apiPod}${resourceSuffix}
485507
- msgQueuePod: ${msgQueuePod}${resourceSuffix}
@@ -491,93 +513,123 @@ The [${targetNamespace}] ICOB environment will be reset using the following sett
491513
- walletDbBackupFileFilter: ${walletDbBackupFileFilter}
492514
- walletDbAdminPasswordKey: ${walletDbAdminPasswordKey}
493515
- dbPod: ${dbPod}${resourceSuffix}
516+
EOF
517+
)
494518

519+
if hardReset; then
520+
txtMsg+=$(cat <<-EOF
521+
\n
522+
\033[0;31mYou have requested a Hard Reset. The following operations will be performed (ALL DATA WILL BE LOST):
523+
\033[1;33m- The process will pause at the beginning to ensure the related BC Registries Agent reset process has started.
524+
- The wallet will be deleted and recreated.
525+
- The 'db' will be reset and reinitialized.
526+
- The search indexes will be reset.
527+
- The process will pause to ensure the related BC Registries Agent registration process has had time to complete.
528+
- The BC Registries Agent registration will be verified.\n
529+
EOF
530+
)
531+
else
532+
txtMsg+=$(cat <<-EOF
533+
\n
495534
The following operations will be performed (ALL DATA WILL BE LOST):
496-
- The process will pause at the beginning to ensure the related ICIA reset process has started.
497-
- The wallet will be reset, by restoring initial copy of ICOB Wallet.
535+
- The process will pause at the beginning to ensure the related BC Registries Agent reset process has started.
536+
- The wallet will be reset, by restoring initial copy of OrgBook Wallet.
498537
- The 'db' will be reset and reinitialized.
499538
- The search indexes will be reset.
500-
- The process will pause to ensure the related ICIA registration process has had time to complete.
501-
- The ICIA registration will be verified.\n
539+
- The process will pause to ensure the related BC Registries Agent registration process has had time to complete.
540+
- The BC Registries Agent registration will be verified.\n
502541
EOF
503542
)
543+
fi
504544

505-
printAndAskToContinue "${txtMsg}"
545+
if ! printAndWaitForYes "${txtMsg}"; then
546+
echoWarning "Exiting ..."
547+
exit 1
548+
fi
506549

507-
# - scaledown ICIA controller and agent
508-
printAndWait "Please ensure the reset process in the corresponding ICIA environment has been started and it has indicated it is safe to process before continuing ..."
550+
# - scaledown BC Registries Agent controller and agent
551+
printAndWait "Please ensure the reset process in the corresponding BC Registries Agent environment has been started and it has indicated it is safe to process before continuing ..."
509552

510-
# - scaledown ICOB agent, api, msg-queue, and msg-queue-worker
553+
# - scaledown OrgBook agent, api, msg-queue, and msg-queue-worker
511554
echo "Scaling down ${agentPod}${resourceSuffix}, ${apiPod}${resourceSuffix}, ${msgQueuePod}${resourceSuffix} and ${msgQueueWorkerPod}${resourceSuffix} ..."
512555
scaleDown -w "${apiPod}${resourceSuffix}" "${msgQueueWorkerPod}${resourceSuffix}" "${agentPod}${resourceSuffix}" "${msgQueuePod}${resourceSuffix}"
513556
exitOnError
514557

515-
# - reset ICOB Wallet Database, by restoring initial copy of ICOB Wallet.
516-
echo "Resetting ${walletDbPod}${resourceSuffix} ..."
517-
if isScaledUp ${backupPod}${resourceSuffix}; then
518-
local backupStarted=1
558+
if hardReset; then
559+
# - Delete Wallet Database
560+
echoError "Deleting ${walletDbPod}${resourceSuffix} ..."
561+
deleteDatabase "${walletDbPod}"
562+
exitOnError
519563
else
520-
local unset backupStarted
521-
scaleUp -w "${backupPod}${resourceSuffix}"
564+
# - reset OrgBook Wallet Database, by restoring initial copy of OrgBook Wallet.
565+
echo "Resetting ${walletDbPod}${resourceSuffix} ..."
566+
if isScaledUp ${backupPod}${resourceSuffix}; then
567+
local backupStarted=1
568+
else
569+
local unset backupStarted
570+
scaleUp -w "${backupPod}${resourceSuffix}"
571+
exitOnError
572+
fi
573+
574+
runInContainer -i \
575+
${backupPod}${resourceSuffix} \
576+
"./backup.sh -s -a $(getSecret ${walletDbPod}${resourceSuffix} ${walletDbAdminPasswordKey}) -r ${walletDbBackupSpec} -f ${walletDbBackupFileFilter}"
522577
exitOnError
523-
fi
524578

525-
runInContainer -i \
526-
${backupPod}${resourceSuffix} \
527-
"./backup.sh -s -a $(getSecret ${walletDbPod}${resourceSuffix} ${walletDbAdminPasswordKey}) -r ${walletDbBackupSpec} -f ${walletDbBackupFileFilter}"
528-
exitOnError
579+
if [ -z ${backupStarted} ]; then
580+
# Leave the backup container in the same state we found it.
581+
scaleDown "${backupPod}${resourceSuffix}"
582+
exitOnError
583+
fi
529584

530-
if [ -z ${backupStarted} ]; then
531-
# Leave the backup container in the same state we found it.
532-
scaleDown "${backupPod}${resourceSuffix}"
585+
# - verify OrgBook Wallet - There should only be 4 items.
586+
recordCounts=$(getRecordCounts "${walletDbPod}" "${walletDbName}")
587+
numItems=$(echo "${recordCounts}" | grep items | awk '{print $5}')
588+
if (( ${numItems} == 4 )); then
589+
echo "Wallet 'items' count verified; ${numItems} items found."
590+
else
591+
echoError "Wallet 'items' count verification failed; ${numItems} items found. Please fix the issue and try again."
592+
exit 1
593+
fi
533594
exitOnError
534595
fi
535596

536-
# - verify ICOB Wallet - There should only be 4 items.
537-
recordCounts=$(getRecordCounts "${walletDbPod}" "${walletDbName}")
538-
numItems=$(echo "${recordCounts}" | grep items | awk '{print $5}')
539-
if (( ${numItems} == 4 )); then
540-
echo "Wallet 'items' count verified; ${numItems} items found."
541-
else
542-
echoError "Wallet 'items' count verification failed; ${numItems} items found. Please fix the issue and try again."
543-
exit 1
544-
fi
545-
exitOnError
546-
547-
# - scaleup ICOB agent
597+
# - scaleup OrgBook agent
548598
echo "Scaling up ${agentPod}${resourceSuffix} ..."
549599
scaleUp -w "${agentPod}${resourceSuffix}"
550600
exitOnError
551601

552-
# - reset ICOB database
602+
# - reset OrgBook database
603+
echo "Resetting ${dbPod}${resourceSuffix} ..."
553604
resetDatabase "${apiPod}" "${dbPod}"
554605
exitOnError
555606

556-
# - scaleup ICOB msg-queue and msg-queue-worker
557-
echo "Scaling up ${agentPod}${resourceSuffix}, ${apiPod}${resourceSuffix}, ${msgQueuePod}${resourceSuffix} and ${msgQueueWorkerPod}${resourceSuffix} ..."
607+
# - scaleup OrgBook msg-queue and msg-queue-worker
608+
echo "Scaling up ${apiPod}${resourceSuffix}, ${msgQueuePod}${resourceSuffix} and ${msgQueueWorkerPod}${resourceSuffix} ..."
558609
scaleUp -w "${msgQueuePod}${resourceSuffix}" "${msgQueueWorkerPod}${resourceSuffix}"
559610
exitOnError
560-
printAndWait "The ICOB reset process is complete. Please wait here for the associated ICIA instance to finish it's registration process before continuing ..."
611+
printAndWait "The OrgBook reset process is complete. Please wait here for the associated BC Registries Agent instance to finish it's registration process before continuing ..."
561612

562-
# - verify ICIA registered with ICOB
613+
# - verify BC Registries Agent registered with OrgBook
563614
# - >= 3 credential_type records
564615
# - >= 3 schema records
565616
# - >= 1 issuer record
617+
echo "Verifying BC Registries Agent registered with OrgBook ..."
566618
recordCounts=$(getRecordCounts "${dbPod}")
567619
recordCounts=$(echo "${recordCounts}" | tail -n +4)
568620
numCredentialTypes=$(echo "${recordCounts}" | grep credential_type | awk '{print $5}')
569621
numSchemas=$(echo "${recordCounts}" | grep schema | awk '{print $5}')
570622
numIssuers=$(echo "${recordCounts}" | grep issuer | awk '{print $5}')
571623
if (( ${numCredentialTypes} >= 3 )) && (( ${numSchemas} >= 3 )) && (( ${numIssuers} >= 1 )); then
572-
echo "ICIA registration verified; credential_type:${numCredentialTypes}, schema:${numSchemas}, and issuer:${numIssuers} records found."
624+
echo "BC Registries Agent registration verified; credential_type:${numCredentialTypes}, schema:${numSchemas}, and issuer:${numIssuers} records found."
573625
else
574-
echoError "ICIA registration verification failed; credential_type:${numCredentialTypes}, schema:${numSchemas}, and issuer:${numIssuers} records found. Please fix the issue and try again."
626+
echoError "BC Registries Agent registration verification failed; credential_type:${numCredentialTypes}, schema:${numSchemas}, and issuer:${numIssuers} records found. Please fix the issue and try again."
575627
exit 1
576628
fi
577629
exitOnError
578630

579631
# - Test posting a few credentials using the pipelines
580-
echo "Provided ICIA has successfully registered with ICOB you can now test things by issuing a few credentials."
632+
echo "Provided BC Registries Agent has successfully registered with OrgBook you can now test things by issuing a few credentials."
581633
)
582634
}
583635

@@ -693,7 +745,7 @@ function updateSearchIndex() {
693745
}
694746

695747
function indexSynced() {
696-
_quickLoadUrl=${1:-https://orgbook.gov.bc.ca/api/quickload}
748+
_quickLoadUrl=${1:-https://orgbook.gov.bc.ca/api/v2/quickload}
697749
_apiPodName=${2}
698750
_dbPodName=${3}
699751

@@ -705,6 +757,7 @@ function indexSynced() {
705757
indexInfo=$(curl -s ${_quickLoadUrl})
706758
actualCount=$(echo ${indexInfo} | jq -r '.counts.actual_item_count')
707759
indexCount=$(echo ${indexInfo} | jq -r '.credential_counts.total_indexed_items')
760+
708761
indexDiff=$(( ${actualCount} - ${indexCount} ))
709762

710763
if (( ${indexCount} == ${actualCount} )); then
@@ -960,7 +1013,9 @@ function swapIndexStorage() {
9601013
# echoWarning "\nofflineSearchEngineVolume:\n${offlineSearchEngineVolume}\n"
9611014
# echoWarning "\nofflineSearchEnginePvc:\n${offlineSearchEnginePvc}\n"
9621015

963-
printAndAskToContinue "If you contiune the following PVC swap will be performed:\n - PVC[${onlineSearchEnginePvc}] from DC[${_onlineSearchEngine}] to DC[${_offlineSearchEngine}]\n - PVC[${offlineSearchEnginePvc}] from DC[${_offlineSearchEngine}] to DC[${_onlineSearchEngine}]"
1016+
if ( ! printAndWaitForYes "If you contiune the following PVC swap will be performed:\n - PVC[${onlineSearchEnginePvc}] from DC[${_onlineSearchEngine}] to DC[${_offlineSearchEngine}]\n - PVC[${offlineSearchEnginePvc}] from DC[${_offlineSearchEngine}] to DC[${_onlineSearchEngine}]\n" ); then
1017+
exit 1
1018+
fi
9641019

9651020
# Prep patches needed to swap the PVCs
9661021
onlineVolumePatch=$(getVolumePatch "${onlineSearchEngineVolume}" "${offlineSearchEnginePvc}")
@@ -1479,4 +1534,4 @@ case "${_cmd}" in
14791534
;;
14801535
esac
14811536

1482-
popd >/dev/null
1537+
popd >/dev/null

openshift/settings.offline-wallet.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Description: A profile to create an offline wallet instance.
2+
# Setting for the OrgBook-BC environments.
3+
# Uses the existing `8ad0ea-tools` environment for builds and images
4+
export TOOLS="8ad0ea-tools"
5+
export PROJECT_NAMESPACE="8ad0ea"
6+
export SKIP_PIPELINE_PROCESSING=1
7+
8+
export ignore_templates=""
9+
export include_templates="wallet-deploy"

openshift/templates/wallet/wallet-deploy.bc.dev.param

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
# AGENT_ROLE=agent
99
# BACKUP_ROLE=backup
1010
# BACKUP_APP_NAME=Backup
11+
# BACKUP_SUFFIX=-bc
1112
# SUFFIX=-bc
13+
# CREDENTIAL_SUFFIX=-bc
1214
# APP_NAME=orgbook
1315
# APP_GROUP=aries-vcr
1416
# IMAGE_NAMESPACE=8ad0ea-tools
1517
# SOURCE_IMAGE_NAME=db
18+
IMAGE_TAG_NAME=dev
1619
TAG_NAME=dev
1720
# POSTGRESQL_DATABASE_NAME=default_wallet
1821
# POSTGRESQL_USER=[a-zA-Z_][a-zA-Z0-9_]{10}

openshift/templates/wallet/wallet-deploy.bc.param

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ ROLE=wallet
88
AGENT_ROLE=agent
99
BACKUP_ROLE=backup
1010
BACKUP_APP_NAME=Backup
11+
BACKUP_SUFFIX=-bc
1112
SUFFIX=-bc
13+
CREDENTIAL_SUFFIX=-bc
1214
APP_NAME=orgbook
1315
APP_GROUP=aries-vcr
1416
IMAGE_NAMESPACE=8ad0ea-tools
1517
SOURCE_IMAGE_NAME=db
18+
IMAGE_TAG_NAME=dev
1619
TAG_NAME=dev
1720
POSTGRESQL_DATABASE_NAME=default_wallet
1821
# POSTGRESQL_USER=[a-zA-Z_][a-zA-Z0-9_]{10}

openshift/templates/wallet/wallet-deploy.bc.prod.param

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
# AGENT_ROLE=agent
99
# BACKUP_ROLE=backup
1010
# BACKUP_APP_NAME=Backup
11+
# BACKUP_SUFFIX=-bc
1112
# SUFFIX=-bc
13+
# CREDENTIAL_SUFFIX=-bc
1214
# APP_NAME=orgbook
1315
# APP_GROUP=aries-vcr
1416
# IMAGE_NAMESPACE=8ad0ea-tools
1517
# SOURCE_IMAGE_NAME=db
18+
IMAGE_TAG_NAME=prod
1619
TAG_NAME=prod
1720
# POSTGRESQL_DATABASE_NAME=default_wallet
1821
# POSTGRESQL_USER=[a-zA-Z_][a-zA-Z0-9_]{10}

openshift/templates/wallet/wallet-deploy.bc.test.param

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
# AGENT_ROLE=agent
99
# BACKUP_ROLE=backup
1010
# BACKUP_APP_NAME=Backup
11+
# BACKUP_SUFFIX=-bc
1112
# SUFFIX=-bc
13+
# CREDENTIAL_SUFFIX=-bc
1214
# APP_NAME=orgbook
1315
# APP_GROUP=aries-vcr
1416
# IMAGE_NAMESPACE=8ad0ea-tools
1517
# SOURCE_IMAGE_NAME=db
18+
IMAGE_TAG_NAME=test
1619
TAG_NAME=test
1720
# POSTGRESQL_DATABASE_NAME=default_wallet
1821
# POSTGRESQL_USER=[a-zA-Z_][a-zA-Z0-9_]{10}

0 commit comments

Comments
 (0)