@@ -18,30 +18,6 @@ GIT_REPO_NAME=prm-repo-ehr-out-service
1818export OLD_SERVICE=repo-to-gp
1919export NHS_SERVICE=ehr-out-service
2020
21- AWS_HELPERS_VERSION=0.2.27
22- echo " AWS helper scripts version: $AWS_HELPERS_VERSION "
23-
24- # ##########################
25- # Shared utils #
26- # ##########################
27-
28- function download_util() {
29- local UTIL_VERSION=$1
30- local UTIL_FILENAME=$2
31-
32- local UTIL_FILEPATH=" utils/$UTIL_VERSION /$UTIL_FILENAME "
33-
34- mkdir -p " utils/$UTIL_VERSION "
35- if [[ ! -f $UTIL_FILEPATH ]]; then
36- wget --quiet -O $UTIL_FILEPATH https://github.com/nhsconnect/prm-deductions-support-infra/releases/download/${UTIL_VERSION} /${UTIL_FILENAME}
37- fi
38- chmod +x $UTIL_FILEPATH
39-
40- echo " $UTIL_FILEPATH "
41- }
42-
43- AWS_HELPERS_FILE=$( download_util $AWS_HELPERS_VERSION aws-helpers)
44- source $AWS_HELPERS_FILE
4521
4622# ###################################
4723# Instance (Environment) Variables #
@@ -54,13 +30,6 @@ function check_env {
5430 fi
5531}
5632
57- function check_nhs_service {
58- if [[ -z " ${NHS_SERVICE} " ]]; then
59- echo " Must set NHS_SERVICE"
60- exit 1
61- fi
62- }
63-
6433function configure_service_url {
6534 if [[ -z " ${NHS_ENVIRONMENT} " ]]; then
6635 export SERVICE_URL=http://${NHS_SERVICE} :3000
@@ -124,33 +93,17 @@ function configure_local_envs_for_docker_test {
12493 set_image_tag
12594}
12695
127- function get_aws_account_id {
128- AWS_ACCOUNT_ID=$( dojo -c Dojofile-infra " aws sts get-caller-identity | jq -r .Account" )
129- }
130-
13196# ###########################
13297# Docker Related Functions #
13398# ###########################
13499
135- function docker_login {
136- echo Logging in to Amazon ECR...
137- eval $( dojo -c Dojofile-infra " aws ecr get-login --no-include-email --region $AWS_DEFAULT_REGION " )
138- }
139100
140101function configure_docker_repository_uri {
141102 docker_login
142103 get_aws_account_id
143104 export REPOSITORY_URI=$AWS_ACCOUNT_ID .dkr.ecr.${AWS_DEFAULT_REGION} .amazonaws.com/$IMAGE_REPO_NAME
144105}
145106
146- function build_docker_image() {
147- echo Build started on $( date)
148- set_image_tag
149- echo Building the Docker image...
150- docker build --build-arg UTILS_VERSION=$AWS_HELPERS_VERSION -t $REPOSITORY_URI :latest -t $REPOSITORY_URI :$IMAGE_TAG .
151- echo Build completed on ` date`
152- }
153-
154107function kill_container {
155108 local filter=$1
156109 local moniker=$2
@@ -179,81 +132,6 @@ function run_localstack {
179132function run_localstack_itest {
180133 docker-compose -f docker-compose-itest.yml up -d
181134}
182- # ######################
183- # Terraform Functions #
184- # ######################
185-
186- export TF_BUCKET=" prm-deductions-${NHS_ENVIRONMENT} -terraform-state"
187- function tf_init_with_options {
188- local state_key=$1
189- local tf_options=$2
190-
191- terraform init $tf_options \
192- -backend-config key=" ${state_key} " \
193- -backend-config bucket=" ${TF_BUCKET} " \
194- -backend-config dynamodb_table=" prm-deductions-${NHS_ENVIRONMENT} -terraform-table" \
195- -backend-config region=${AWS_DEFAULT_REGION}
196- }
197-
198- function tf_init_or_rename {
199- local state_key_suffix=$1
200-
201- echo checking state file exists
202- set +e
203- aws s3 ls ${TF_BUCKET} /$NHS_SERVICE -${state_key_suffix}
204- local state_file_exists=$?
205- if [ $state_file_exists -ne 0 ]; then
206- echo cannot find state file so assuming rename
207- local RENAME_STATE=true
208- else
209- echo state file exists
210- fi
211- set -e
212-
213- if [ -z " ${RENAME_STATE} " ]; then
214- tf_init_with_options $NHS_SERVICE -${state_key_suffix} -reconfigure
215- else
216- echo doing one-time renaming of state file
217- if [ -z " ${OLD_SERVICE} " ]; then
218- echo OLD_SERVICE needs to be set if RENAME_STATE being used
219- exit 88
220- fi
221- tf_init_with_options $OLD_SERVICE -${state_key_suffix} -reconfigure
222-
223- tf_init_with_options $NHS_SERVICE -${state_key_suffix} ' -migrate-state -force-copy'
224- fi
225- }
226-
227-
228- function tf_init {
229- check_env
230- cd terraform
231-
232- tf_init_or_rename ${NHS_ENVIRONMENT} /terraform.tfstate
233- }
234-
235- function tf_plan {
236- operation=$1
237- set_image_tag
238-
239- tf_init
240- terraform get # modules
241- if [[ " ${operation} " == " create" ]]; then
242- terraform plan -var task_image_tag=$IMAGE_TAG -var-file=$NHS_ENVIRONMENT .tfvars -out=" nhs_deployment.tfplan"
243- elif [[ " ${operation} " == " destroy" ]]; then
244- terraform plan -var task_image_tag=$IMAGE_TAG -var-file=$NHS_ENVIRONMENT .tfvars -out=" nhs_deployment.tfplan" -destroy
245- else
246- echo " Unknown operation (should be create or destroy), got: ${operation} "
247- exit 1
248- fi
249- }
250-
251- function tf_apply {
252- tf_init
253- terraform get # modules
254- terraform apply nhs_deployment.tfplan
255- terraform output -json > tf-out.json
256- }
257135
258136# ##########
259137# Testing #
@@ -356,7 +234,7 @@ case "${command}" in
356234 ;;
357235 run_docker_local)
358236 configure_local_envs
359- dojo -c Dojofile-dtest
237+ run_docker_local
360238 ;;
361239 tf_plan)
362240 check_env
0 commit comments