From 81cba7c5bc4bed060901d6e19c84d5acee054b3e Mon Sep 17 00:00:00 2001 From: Alex Schofield Date: Mon, 19 Aug 2024 14:53:43 +0100 Subject: feat: create shell script for creating lambda layer zip --- scripts/make_layer_zip.sh | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100755 scripts/make_layer_zip.sh (limited to 'scripts') diff --git a/scripts/make_layer_zip.sh b/scripts/make_layer_zip.sh new file mode 100755 index 0000000..0e7560f --- /dev/null +++ b/scripts/make_layer_zip.sh @@ -0,0 +1,7 @@ +# Description: Make the zip file for the layer + +cd "$(dirname "$0")/.." +mkdir tmp_python +pip3 install --upgrade -r requirements.txt -t tmp_python/ +zip -r layer.zip tmp_python +rm -r tmp_python/ -- cgit v1.2.3 From 024de7d7947f46cf6c0c829dc29eb8298e029576 Mon Sep 17 00:00:00 2001 From: Alex Schofield Date: Mon, 19 Aug 2024 15:37:54 +0100 Subject: fix(make_layer_zip): change folder structure of layer.zip --- scripts/make_layer_zip.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/make_layer_zip.sh b/scripts/make_layer_zip.sh index 0e7560f..eabe301 100755 --- a/scripts/make_layer_zip.sh +++ b/scripts/make_layer_zip.sh @@ -1,7 +1,8 @@ # Description: Make the zip file for the layer cd "$(dirname "$0")/.." -mkdir tmp_python -pip3 install --upgrade -r requirements.txt -t tmp_python/ -zip -r layer.zip tmp_python -rm -r tmp_python/ +mkdir -p python/lib/python3.11/site-packages +pip3 install --upgrade -r requirements.txt -t python/lib/python3.11/site-packages +rm layer.zip +zip -r layer.zip python +rm -r python/ -- cgit v1.2.3 From 22e7de562e62495e547eeff187d86bf9524ae5ca Mon Sep 17 00:00:00 2001 From: Alex Schofield Date: Mon, 19 Aug 2024 20:22:16 +0100 Subject: feat: create shell script for terraform destroy/apply --- scripts/deploy.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 scripts/deploy.sh (limited to 'scripts') diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100755 index 0000000..0446184 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,15 @@ +# Deploy Script +# Description: Deploy and destroy Terraform +# WARNING: This will most likely destroy any current infrastructure if protections +# are not in place. Be careful! + +echo "WARNING: This script will destroy any infrastructure for testing." +echo "It should not be used once a proper deployment has been setup." +echo "Would you like to continue?" + +select yn in "Yes" "No"; do + case $yn in + Yes ) cd ../terraform/; terraform destroy -auto-approve; terraform apply -auto-approve; terraform destroy -auto-approve; break;; + No ) exit;; + esac +done -- cgit v1.2.3 From 50302044c64e414ffe0435908146bc718bf6bed9 Mon Sep 17 00:00:00 2001 From: Alex Schofield Date: Mon, 19 Aug 2024 20:24:35 +0100 Subject: feat(deploy.sh): exit if any command returns non-zero status --- scripts/deploy.sh | 3 +++ 1 file changed, 3 insertions(+) (limited to 'scripts') diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 0446184..16a9e13 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -3,6 +3,9 @@ # WARNING: This will most likely destroy any current infrastructure if protections # are not in place. Be careful! +# Exit if any command has a non-zero status +set -e + echo "WARNING: This script will destroy any infrastructure for testing." echo "It should not be used once a proper deployment has been setup." echo "Would you like to continue?" -- cgit v1.2.3 From 18f7ea0e4254890cd810ff2ee257306d94467faf Mon Sep 17 00:00:00 2001 From: Alex Schofield Date: Mon, 19 Aug 2024 20:49:28 +0100 Subject: refactor: Improve deploy script user interaction --- scripts/deploy.sh | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 16a9e13..d7d18ff 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -11,8 +11,30 @@ echo "It should not be used once a proper deployment has been setup." echo "Would you like to continue?" select yn in "Yes" "No"; do - case $yn in - Yes ) cd ../terraform/; terraform destroy -auto-approve; terraform apply -auto-approve; terraform destroy -auto-approve; break;; - No ) exit;; - esac + case $yn in + Yes) + cd ../terraform/ + echo "Would you like to destroy the current infrastructure?" + select destroy_1 in "Yes" "No"; do + case $destroy_1 in + Yes) + terraform destroy + break + ;; + No) + echo "Skipping initial destroy..." + break + ;; + esac + done + + terraform apply -auto-approve + + break + ;; + No) + echo "Operation cancelled..." + exit + ;; + esac done -- cgit v1.2.3 From 68be61c22703d56a10e654702d15407231385b65 Mon Sep 17 00:00:00 2001 From: Alex Schofield Date: Mon, 19 Aug 2024 20:51:30 +0100 Subject: feat: ask user if they want to destroy new infrastructure --- scripts/deploy.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/deploy.sh b/scripts/deploy.sh index d7d18ff..e56088e 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -28,7 +28,21 @@ select yn in "Yes" "No"; do esac done - terraform apply -auto-approve + terraform apply + + echo "Would you like to destroy the newly-created infrastructure?" + select destroy_2 in "Yes" "No"; do + case $destroy_2 in + Yes) + terraform destroy + break + ;; + No) + echo "Skipping final destroy... Infrastructure will remain." + break + ;; + esac + done break ;; -- cgit v1.2.3 From b75b7197f08e933cfcd4b69ad5182a01c2886d8e Mon Sep 17 00:00:00 2001 From: Alex Schofield Date: Mon, 19 Aug 2024 21:05:33 +0100 Subject: refactor: change directory at start of the script to terraform folder --- scripts/deploy.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/deploy.sh b/scripts/deploy.sh index e56088e..f631bbc 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -6,6 +6,9 @@ # Exit if any command has a non-zero status set -e +# Change current directory to terraform folder at the start +cd ../terraform/ + echo "WARNING: This script will destroy any infrastructure for testing." echo "It should not be used once a proper deployment has been setup." echo "Would you like to continue?" @@ -13,7 +16,6 @@ echo "Would you like to continue?" select yn in "Yes" "No"; do case $yn in Yes) - cd ../terraform/ echo "Would you like to destroy the current infrastructure?" select destroy_1 in "Yes" "No"; do case $destroy_1 in -- cgit v1.2.3