Skip to content

Commit

Permalink
PAR-2491 & PAR-2492: Updating CF scripts to use new user creds
Browse files Browse the repository at this point in the history
  • Loading branch information
robwild-affinitydigital committed Aug 16, 2024
1 parent e0286de commit e7b7d36
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 55 deletions.
24 changes: 12 additions & 12 deletions devops/cf/check_opensearch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ command -v cf >/dev/null 2>&1 || {
# Set required parameters
# ENV (required) - the environment to check for
# BUILD_VER (optional) - the build tag being pushed
# GOVUK_CF_USER (required) - the user deploying the script
# GOVUK_CF_PWD (required) - the password for the user account
# DEV_GOVUK_CF_USER (required) - the user deploying the script
# DEV_GOVUK_CF_PWD (required) - the password for the user account
# BUILD_DIR - the directory containing the build assets
# VAULT_ADDR - the vault service endpoint
# VAULT_UNSEAL_KEY (required) - the key used to unseal the vault
Expand All @@ -55,8 +55,8 @@ eval set -- "$PARSED"

# Defaults
ENV_ONLY=${ENV_ONLY:=n}
GOVUK_CF_USER=${GOVUK_CF_USER:-}
GOVUK_CF_PWD=${GOVUK_CF_PWD:-}
DEV_GOVUK_CF_USER=${DEV_GOVUK_CF_USER:-}
DEV_GOVUK_CF_PWD=${DEV_GOVUK_CF_PWD:-}
INDEX=${INDEX:="partnership_index"}
LOCAL_PORT=${LOCAL_PORT:="4430"}

Expand All @@ -71,11 +71,11 @@ while true; do
shift 2
;;
-u|--user)
GOVUK_CF_USER="$2"
DEV_GOVUK_CF_USER="$2"
shift 2
;;
-p|--password)
GOVUK_CF_PWD="$2"
DEV_GOVUK_CF_PWD="$2"
shift 2
;;
--)
Expand All @@ -100,17 +100,17 @@ ENV=$1
####################################################################################
# Allow manual input of missing parameters
# ENV (required) - the password for the user account
# GOVUK_CF_USER (required) - the user deploying the script
# GOVUK_CF_PWD (required) - the password for the user account
# DEV_GOVUK_CF_USER (required) - the user deploying the script
# DEV_GOVUK_CF_PWD (required) - the password for the user account
# INDEX - the index to check the health for
####################################################################################
if [[ -z "${GOVUK_CF_USER}" ]]; then
if [[ -z "${DEV_GOVUK_CF_USER}" ]]; then
echo -n "Enter your Cloud Foundry username: "
read GOVUK_CF_USER
read DEV_GOVUK_CF_USER
fi
if [[ -z "${GOVUK_CF_PWD}" ]]; then
if [[ -z "${DEV_GOVUK_CF_PWD}" ]]; then
echo -n "Enter your Cloud Foundry password (will be hidden): "
read -s GOVUK_CF_PWD
read -s DEV_GOVUK_CF_PWD
fi
if [[ -z "${INDEX}" ]]; then
echo -n "Please choose an index to check: "
Expand Down
24 changes: 12 additions & 12 deletions devops/cf/destroy.app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ command -v cf >/dev/null 2>&1 || {
####################################################################################
# Set required parameters
# ENV (required) - the password for the user account
# GOVUK_CF_USER (required) - the user deploying the script
# GOVUK_CF_PWD (required) - the password for the user account
# DEV_GOVUK_CF_USER (required) - the user deploying the script
# DEV_GOVUK_CF_PWD (required) - the password for the user account
####################################################################################
OPTIONS=u:p:
LONGOPTS=user:,password:
Expand All @@ -50,17 +50,17 @@ fi
eval set -- "$PARSED"

# Defaults
GOVUK_CF_USER=${GOVUK_CF_USER:-}
GOVUK_CF_PWD=${GOVUK_CF_PWD:-}
DEV_GOVUK_CF_USER=${DEV_GOVUK_CF_USER:-}
DEV_GOVUK_CF_PWD=${DEV_GOVUK_CF_PWD:-}

while true; do
case "$1" in
-u|--user)
GOVUK_CF_USER="$2"
DEV_GOVUK_CF_USER="$2"
shift 2
;;
-p|--password)
GOVUK_CF_PWD="$2"
DEV_GOVUK_CF_PWD="$2"
shift 2
;;
--)
Expand Down Expand Up @@ -90,19 +90,19 @@ fi
####################################################################################
# Allow manual input of missing parameters
# ENV (required) - the password for the user account
# GOVUK_CF_USER (required) - the user deploying the script
# GOVUK_CF_PWD (required) - the password for the user account
# DEV_GOVUK_CF_USER (required) - the user deploying the script
# DEV_GOVUK_CF_PWD (required) - the password for the user account
# BUILD_DIR - the directory containing the build assets
# VAULT_ADDR - the vault service endpoint
# VAULT_UNSEAL_KEY (required) - the key used to unseal the vault
####################################################################################
if [[ -z "${GOVUK_CF_USER}" ]]; then
if [[ -z "${DEV_GOVUK_CF_USER}" ]]; then
echo -n "Enter your Cloud Foundry username: "
read GOVUK_CF_USER
read DEV_GOVUK_CF_USER
fi
if [[ -z "${GOVUK_CF_PWD}" ]]; then
if [[ -z "${DEV_GOVUK_CF_PWD}" ]]; then
echo -n "Enter your Cloud Foundry password (will be hidden): "
read -s GOVUK_CF_PWD
read -s DEV_GOVUK_CF_PWD
fi


Expand Down
37 changes: 18 additions & 19 deletions devops/cf/pull.local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ command -v cf >/dev/null 2>&1 || {
# VERSION (required) - the semver tag to be deployed
# ENV (required) - the environment to push to
# AWS_KEY (required) - the user deploying the script
# GOVUK_CF_USER (required) - the user deploying the script
# GOVUK_CF_USER (required) - the user deploying the script
# GOVUK_CF_PWD (required) - the password for the user account
# DEV_GOVUK_CF_USER (required) - the user deploying the script
# DEV_GOVUK_CF_PWD (required) - the password for the user account
# BUILD_DIR - the directory containing the build assets
# VAULT_ADDR - the vault service endpoint
# VAULT_UNSEAL_KEY (required) - the key used to unseal the vault
Expand All @@ -75,8 +74,8 @@ eval set -- "$PARSED"
# Defaults
VERSION=${VERSION:-}
ENV_ONLY=${ENV_ONLY:=n}
GOVUK_CF_USER=${GOVUK_CF_USER:-}
GOVUK_CF_PWD=${GOVUK_CF_PWD:-}
DEV_GOVUK_CF_USER=${DEV_GOVUK_CF_USER:-}
DEV_GOVUK_CF_PWD=${DEV_GOVUK_CF_PWD:-}
CF_INSTANCES=${CF_INSTANCES:=1}
DB_IMPORT=${DB_IMPORT:="$PWD/backups/sanitised-db.sql"}
DB_RESET=${DB_RESET:=n}
Expand All @@ -96,11 +95,11 @@ while true; do
shift
;;
-u|--user)
GOVUK_CF_USER="$2"
DEV_GOVUK_CF_USER="$2"
shift 2
;;
-p|--password)
GOVUK_CF_PWD="$2"
DEV_GOVUK_CF_PWD="$2"
shift 2
;;
-i|--instances)
Expand Down Expand Up @@ -166,23 +165,23 @@ fi
####################################################################################
# Allow manual input of missing parameters
# ENV (required) - the password for the user account
# GOVUK_CF_USER (required) - the user deploying the script
# GOVUK_CF_PWD (required) - the password for the user account
# DEV_GOVUK_CF_USER (required) - the user deploying the script
# DEV_GOVUK_CF_PWD (required) - the password for the user account
# BUILD_DIR - the directory containing the build assets
# VAULT_ADDR - the vault service endpoint
# VAULT_UNSEAL_KEY (required) - the key used to unseal the vault
####################################################################################
if [[ -z "${VERSION}" ]]; then
echo -n "Enter the tag you wish to deploy: "
read GOVUK_CF_USER
read DEV_GOVUK_CF_USER
fi
if [[ -z "${GOVUK_CF_USER}" ]]; then
if [[ -z "${DEV_GOVUK_CF_USER}" ]]; then
echo -n "Enter your Cloud Foundry username: "
read GOVUK_CF_USER
read DEV_GOVUK_CF_USER
fi
if [[ -z "${GOVUK_CF_PWD}" ]]; then
if [[ -z "${DEV_GOVUK_CF_PWD}" ]]; then
echo -n "Enter your Cloud Foundry password (will be hidden): "
read -s GOVUK_CF_PWD
read -s DEV_GOVUK_CF_PWD
fi
if [[ -z "${VAULT_UNSEAL}" ]]; then
echo -n "Enter your Vault unseal key (will be hidden): "
Expand Down Expand Up @@ -218,28 +217,28 @@ vault operator seal -tls-skip-verify
# Pull the packaged version from S3
####################################################################################
printf "Pulling version $VERSION...\n"

mkdir -p $BUILD_DIR
rm -rf $BUILD_DIR/*

printf "Downloading build package s3://beis-par-artifacts/builds/$VERSION.tar.gz...\n"
aws s3 cp s3://beis-par-artifacts/builds/$VERSION.tar.gz /tmp/

## Check that we got the package
if [ ! -f /tmp/$VERSION.tar.gz ]; then
exit
fi

## Unpack and remove package file
printf "Extracting the tar ball to $BUILD_DIR...\n"
tar -zxvf /tmp/$VERSION.tar.gz -C $BUILD_DIR > /dev/null 2>&1
rm /tmp/$VERSION.tar.gz

####################################################################################
# Run the deployment script
####################################################################################
SCRIPT="${BASH_SOURCE%/*}/push.local.sh -d $BUILD_DIR $ENV"

printf "Tag $VERSION has been pulled...\n"
printf "Please deploy this to an environment using the following command...\n"
printf "$SCRIPT\n"
printf "$SCRIPT\n"
24 changes: 12 additions & 12 deletions devops/cf/push.local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ command -v cf >/dev/null 2>&1 || {
# Set required parameters
# ENV (required) - the password for the user account
# BUILD_VER (optional) - the build tag being pushed
# GOVUK_CF_USER (required) - the user deploying the script
# GOVUK_CF_PWD (required) - the password for the user account
# DEV_GOVUK_CF_USER (required) - the user deploying the script
# DEV_GOVUK_CF_PWD (required) - the password for the user account
# BUILD_DIR - the directory containing the build assets
# VAULT_ADDR - the vault service endpoint
# VAULT_UNSEAL_KEY (required) - the key used to unseal the vault
Expand All @@ -63,8 +63,8 @@ eval set -- "$PARSED"

# Defaults
ENV_ONLY=${ENV_ONLY:=n}
GOVUK_CF_USER=${GOVUK_CF_USER:-}
GOVUK_CF_PWD=${GOVUK_CF_PWD:-}
DEV_GOVUK_CF_USER=${DEV_GOVUK_CF_USER:-}
DEV_GOVUK_CF_PWD=${DEV_GOVUK_CF_PWD:-}
CF_INSTANCES=${CF_INSTANCES:=1}
BUILD_VER=${BUILD_VER:-}
BUILD_DIR=${BUILD_DIR:=$PWD}
Expand All @@ -88,11 +88,11 @@ while true; do
shift 2
;;
-u|--user)
GOVUK_CF_USER="$2"
DEV_GOVUK_CF_USER="$2"
shift 2
;;
-p|--password)
GOVUK_CF_PWD="$2"
DEV_GOVUK_CF_PWD="$2"
shift 2
;;
-i|--instances)
Expand Down Expand Up @@ -166,19 +166,19 @@ fi
####################################################################################
# Allow manual input of missing parameters
# ENV (required) - the password for the user account
# GOVUK_CF_USER (required) - the user deploying the script
# GOVUK_CF_PWD (required) - the password for the user account
# DEV_GOVUK_CF_USER (required) - the user deploying the script
# DEV_GOVUK_CF_PWD (required) - the password for the user account
# BUILD_DIR - the directory containing the build assets
# VAULT_ADDR - the vault service endpoint
# VAULT_UNSEAL_KEY (required) - the key used to unseal the vault
####################################################################################
if [[ -z "${GOVUK_CF_USER}" ]]; then
if [[ -z "${DEV_GOVUK_CF_USER}" ]]; then
echo -n "Enter your Cloud Foundry username: "
read GOVUK_CF_USER
read DEV_GOVUK_CF_USER
fi
if [[ -z "${GOVUK_CF_PWD}" ]]; then
if [[ -z "${DEV_GOVUK_CF_PWD}" ]]; then
echo -n "Enter your Cloud Foundry password (will be hidden): "
read -s GOVUK_CF_PWD
read -s DEV_GOVUK_CF_PWD
fi
if [[ -z "${VAULT_UNSEAL}" ]]; then
echo -n "Enter your Vault unseal key (will be hidden): "
Expand Down

0 comments on commit e7b7d36

Please sign in to comment.