From f6987ce6d3d28a515446481d8e1b66f19ece3a36 Mon Sep 17 00:00:00 2001 From: Harish V Date: Thu, 14 Sep 2023 18:05:46 +0800 Subject: [PATCH 01/20] feat: move fetch ssm to prebuild --- .../06_fetch_ssm_parameters.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .platform/hooks/{postdeploy/01_fetch_ssm_parameters.sh => predeploy/06_fetch_ssm_parameters.sh} (100%) diff --git a/.platform/hooks/postdeploy/01_fetch_ssm_parameters.sh b/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh similarity index 100% rename from .platform/hooks/postdeploy/01_fetch_ssm_parameters.sh rename to .platform/hooks/predeploy/06_fetch_ssm_parameters.sh From 9a4f8db000d743fa9f7dadc45f8ac01da4dc8359 Mon Sep 17 00:00:00 2001 From: Harish V Date: Thu, 14 Sep 2023 18:35:03 +0800 Subject: [PATCH 02/20] feat: move to prebuild --- .../hooks/{predeploy => prebuild}/06_fetch_ssm_parameters.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .platform/hooks/{predeploy => prebuild}/06_fetch_ssm_parameters.sh (100%) diff --git a/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh b/.platform/hooks/prebuild/06_fetch_ssm_parameters.sh similarity index 100% rename from .platform/hooks/predeploy/06_fetch_ssm_parameters.sh rename to .platform/hooks/prebuild/06_fetch_ssm_parameters.sh From d9569a017584bd2acf10b190ad25f8a7a5b4103b Mon Sep 17 00:00:00 2001 From: Harish V Date: Fri, 15 Sep 2023 14:29:38 +0800 Subject: [PATCH 03/20] feat: check if env type is received --- .platform/hooks/prebuild/06_fetch_ssm_parameters.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.platform/hooks/prebuild/06_fetch_ssm_parameters.sh b/.platform/hooks/prebuild/06_fetch_ssm_parameters.sh index 3bdc40fa8..863dbbdb8 100644 --- a/.platform/hooks/prebuild/06_fetch_ssm_parameters.sh +++ b/.platform/hooks/prebuild/06_fetch_ssm_parameters.sh @@ -1,6 +1,7 @@ #!/bin/bash ENV_TYPE=$(/opt/elasticbeanstalk/bin/get-config environment -k SSM_PREFIX) +echo "ENV TYPE: $ENV_TYPE" >> /tmp/ssm-type.txt ENV_VARS=("SGID_CLIENT_ID" "SGID_CLIENT_SECRET" "SGID_PRIVATE_KEY" "SGID_REDIRECT_URI") # Add any additional env vars to this array echo "Set AWS region" @@ -10,5 +11,6 @@ for ENV_VAR in "${ENV_VARS[@]}"; do echo "Fetching ${ENV_VAR} from SSM" VALUE=$(aws ssm get-parameter --name "${ENV_TYPE}_${ENV_VAR}" --with-decryption --query "Parameter.Value" --output text) echo "${ENV_VAR}=${VALUE}" >> /opt/elasticbeanstalk/deployment/env + /etc/isomer/.isomer.env echo "Saved ${ENV_VAR}" done From d638fef16f4dc504c43fffad43071de4675a72b0 Mon Sep 17 00:00:00 2001 From: Harish V Date: Fri, 15 Sep 2023 15:21:28 +0800 Subject: [PATCH 04/20] feat: fetch all envs from ssm --- .../hooks/prebuild/01_fetch_ssm_parameters.sh | 84 +++++++++++++++++++ .../hooks/prebuild/06_fetch_ssm_parameters.sh | 16 ---- 2 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 .platform/hooks/prebuild/01_fetch_ssm_parameters.sh delete mode 100644 .platform/hooks/prebuild/06_fetch_ssm_parameters.sh diff --git a/.platform/hooks/prebuild/01_fetch_ssm_parameters.sh b/.platform/hooks/prebuild/01_fetch_ssm_parameters.sh new file mode 100644 index 000000000..ff43012a7 --- /dev/null +++ b/.platform/hooks/prebuild/01_fetch_ssm_parameters.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +# Exit on first error +set -e + +# Create directory if it does not exist +if [ ! -d "/etc/isomer" ]; then + mkdir -p /etc/isomer + chown webapp:webapp /etc/isomer +fi + +ENV_TYPE=$(/opt/elasticbeanstalk/bin/get-config environment -k SSM_PREFIX) +echo "ENV TYPE: $ENV_TYPE" >> /tmp/ssm-type.txt + +# List of all env vars to fetch +ENV_VARS=( + "AUTH_TOKEN_EXPIRY_DURATION_IN_MILLISECONDS" + "AWS_BACKEND_EB_ENV_NAME" + "AWS_REGION" + "CLIENT_ID" + "CLIENT_SECRET" + "CLOUDMERSIVE_API_KEY" + "COOKIE_DOMAIN" + "DB_ACQUIRE" + "DB_MAX_POOL" + "DB_MIN_POOL" + "DB_TIMEOUT" + "DB_URI" + "DD_AGENT_MAJOR_VERSION" + "DD_ENV" + "DD_LOGS_INJECTION" + "DD_SERVICE" + "DD_TAGS" + "DD_TRACE_STARTUP_LOGS" + "E2E_TEST_GH_TOKEN" + "E2E_TEST_REPO" + "E2E_TEST_SECRET" + "EFS_VOL_PATH" + "ENCRYPTION_SECRET" + "FF_DEPRECATE_SITE_QUEUES" + "FRONTEND_URL" + "GGS_EXPERIMENTAL_TRACKING_SITES" + "GH_ORG_NAME" + "GITHUB_BUILD_ORG_NAME" + "GITHUB_BUILD_REPO_NAME" + "GITHUB_ORG_NAME" + "GROWTHBOOK_CLIENT_KEY" + "INCOMING_QUEUE_URL" + "ISOMERPAGES_REPO_PAGE_COUNT" + "JWT_SECRET" + "MAX_NUM_OTP_ATTEMPTS" + "MOCK_AMPLIFY_DOMAIN_ASSOCIATION_CALLS" + "MUTEX_TABLE_NAME" + "NETLIFY_ACCESS_TOKEN" + "NODE_ENV" + "OTP_EXPIRY" + "OTP_SECRET" + "OUTGOING_QUEUE_URL" + "POSTMAN_API_KEY" + "POSTMAN_SMS_CRED_NAME" + "REDIRECT_URI" + "SESSION_SECRET" + "SGID_CLIENT_ID" + "SGID_CLIENT_SECRET" + "SGID_PRIVATE_KEY" + "SGID_REDIRECT_URI" + "SITE_CREATE_FORM_KEY" + "SITE_LAUNCH_DYNAMO_DB_TABLE_NAME" + "SITE_LAUNCH_FORM_KEY" + "SITE_PASSWORD_SECRET_KEY" + "SSM_PREFIX" + "STEP_FUNCTIONS_ARN" + "SYSTEM_GITHUB_TOKEN" +) + +echo "Set AWS region" +aws configure set default.region ap-southeast-1 + +for ENV_VAR in "${ENV_VARS[@]}"; do + echo "Fetching ${ENV_VAR} from SSM" + VALUE=$(aws ssm get-parameter --name "${ENV_TYPE}_${ENV_VAR}" --with-decryption --query "Parameter.Value" --output text) + echo "${ENV_VAR}=${VALUE}" >> /etc/isomer/.isomer.env + echo "Saved ${ENV_VAR}" +done diff --git a/.platform/hooks/prebuild/06_fetch_ssm_parameters.sh b/.platform/hooks/prebuild/06_fetch_ssm_parameters.sh deleted file mode 100644 index 863dbbdb8..000000000 --- a/.platform/hooks/prebuild/06_fetch_ssm_parameters.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -ENV_TYPE=$(/opt/elasticbeanstalk/bin/get-config environment -k SSM_PREFIX) -echo "ENV TYPE: $ENV_TYPE" >> /tmp/ssm-type.txt -ENV_VARS=("SGID_CLIENT_ID" "SGID_CLIENT_SECRET" "SGID_PRIVATE_KEY" "SGID_REDIRECT_URI") # Add any additional env vars to this array - -echo "Set AWS region" -aws configure set default.region ap-southeast-1 - -for ENV_VAR in "${ENV_VARS[@]}"; do - echo "Fetching ${ENV_VAR} from SSM" - VALUE=$(aws ssm get-parameter --name "${ENV_TYPE}_${ENV_VAR}" --with-decryption --query "Parameter.Value" --output text) - echo "${ENV_VAR}=${VALUE}" >> /opt/elasticbeanstalk/deployment/env - /etc/isomer/.isomer.env - echo "Saved ${ENV_VAR}" -done From 62789159813a7098186258712499545d39ddb076 Mon Sep 17 00:00:00 2001 From: Harish V Date: Fri, 15 Sep 2023 15:39:02 +0800 Subject: [PATCH 05/20] fix: remove GH_ORG_NAME --- .platform/hooks/prebuild/01_fetch_ssm_parameters.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/.platform/hooks/prebuild/01_fetch_ssm_parameters.sh b/.platform/hooks/prebuild/01_fetch_ssm_parameters.sh index ff43012a7..78a43fc64 100644 --- a/.platform/hooks/prebuild/01_fetch_ssm_parameters.sh +++ b/.platform/hooks/prebuild/01_fetch_ssm_parameters.sh @@ -40,7 +40,6 @@ ENV_VARS=( "FF_DEPRECATE_SITE_QUEUES" "FRONTEND_URL" "GGS_EXPERIMENTAL_TRACKING_SITES" - "GH_ORG_NAME" "GITHUB_BUILD_ORG_NAME" "GITHUB_BUILD_REPO_NAME" "GITHUB_ORG_NAME" From da586aefe99cf89fead6df02a771afeae2e09b71 Mon Sep 17 00:00:00 2001 From: Harish V Date: Fri, 15 Sep 2023 15:48:06 +0800 Subject: [PATCH 06/20] feat: load from dotenv for start script --- package-lock.json | 12 ++++++++++++ package.json | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 3b4ce2acf..ac1917c47 100644 --- a/package-lock.json +++ b/package-lock.json @@ -37,6 +37,7 @@ "crypto-js": "^4.1.1", "dd-trace": "^4.7.0", "debug": "~2.6.9", + "dotenv": "^16.3.1", "eventsource": "^2.0.2", "exponential-backoff": "^3.1.0", "express": "~4.17.3", @@ -6910,6 +6911,17 @@ "node": ">=8" } }, + "node_modules/dotenv": { + "version": "16.3.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz", + "integrity": "sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/motdotla/dotenv?sponsor=1" + } + }, "node_modules/dottie": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.6.tgz", diff --git a/package.json b/package.json index 2ebf652d7..a94dfbb7f 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "build": "tsc -p tsconfig.build.json", - "start": "node --unhandled-rejections=warn -r ts-node/register/transpile-only -r tsconfig-paths/register build/server.js", + "start": "node --unhandled-rejections=warn -r ts-node/register/transpile-only -r tsconfig-paths/register -r dotenv/config build/server.js dotenv_config_path=/etc/isomer/.isomer.env", "dev:services": "docker compose up -d", "dev:server": "source .env && ts-node-dev --unhandled-rejections=warn --respawn src/server.js", "dev": "npm run dev:services && npm run dev:server", @@ -53,6 +53,7 @@ "crypto-js": "^4.1.1", "dd-trace": "^4.7.0", "debug": "~2.6.9", + "dotenv": "^16.3.1", "eventsource": "^2.0.2", "exponential-backoff": "^3.1.0", "express": "~4.17.3", From fb16708efb48548dc3a1fc36564f1ad3ba64c5f3 Mon Sep 17 00:00:00 2001 From: Harish V Date: Fri, 15 Sep 2023 15:48:54 +0800 Subject: [PATCH 07/20] feat: add test var --- .platform/hooks/prebuild/01_fetch_ssm_parameters.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.platform/hooks/prebuild/01_fetch_ssm_parameters.sh b/.platform/hooks/prebuild/01_fetch_ssm_parameters.sh index 78a43fc64..e3f004fe6 100644 --- a/.platform/hooks/prebuild/01_fetch_ssm_parameters.sh +++ b/.platform/hooks/prebuild/01_fetch_ssm_parameters.sh @@ -70,6 +70,7 @@ ENV_VARS=( "SSM_PREFIX" "STEP_FUNCTIONS_ARN" "SYSTEM_GITHUB_TOKEN" + "TEST_VAR" ) echo "Set AWS region" From 964abe2b783105dbc072faed13c69b494d88ed65 Mon Sep 17 00:00:00 2001 From: Harish V Date: Fri, 15 Sep 2023 16:01:08 +0800 Subject: [PATCH 08/20] fix: remove existing env first --- .platform/hooks/prebuild/01_fetch_ssm_parameters.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.platform/hooks/prebuild/01_fetch_ssm_parameters.sh b/.platform/hooks/prebuild/01_fetch_ssm_parameters.sh index e3f004fe6..d7605cee9 100644 --- a/.platform/hooks/prebuild/01_fetch_ssm_parameters.sh +++ b/.platform/hooks/prebuild/01_fetch_ssm_parameters.sh @@ -9,6 +9,11 @@ if [ ! -d "/etc/isomer" ]; then chown webapp:webapp /etc/isomer fi +# If the .isomer.env file exists, remove it +if [ -f "/etc/isomer/.isomer.env" ]; then + rm /etc/isomer/.isomer.env +fi + ENV_TYPE=$(/opt/elasticbeanstalk/bin/get-config environment -k SSM_PREFIX) echo "ENV TYPE: $ENV_TYPE" >> /tmp/ssm-type.txt @@ -82,3 +87,6 @@ for ENV_VAR in "${ENV_VARS[@]}"; do echo "${ENV_VAR}=${VALUE}" >> /etc/isomer/.isomer.env echo "Saved ${ENV_VAR}" done + +# Ensure the file is owned by webapp so it has access +chown webapp:webapp /etc/isomer/.isomer.env \ No newline at end of file From f3467c45ce756f789823b4d72635aa12df603122 Mon Sep 17 00:00:00 2001 From: Harish V Date: Fri, 15 Sep 2023 16:30:32 +0800 Subject: [PATCH 09/20] test: adding debug statements --- src/config/config.ts | 6 ++++++ src/server.js | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/config/config.ts b/src/config/config.ts index ec89cf26b..944af4857 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -421,6 +421,12 @@ const config = convict({ default: "", }, }, + testVar: { + doc: "Test variable", + env: "TEST_VAR", + format: "required-string", + default: "", + }, }) // Perform validation diff --git a/src/server.js b/src/server.js index 707d1b0b2..ed2d4aa53 100644 --- a/src/server.js +++ b/src/server.js @@ -420,6 +420,8 @@ app.use((req, res, next) => { // error handler app.use(errorHandler) +logger.info(`PRINTING OUT TEST VAR: ${config.get("testVar")}`) + logger.info("Connecting to Sequelize") sequelize .authenticate() From 1067373f29d0114945a7845d555823445e80a89c Mon Sep 17 00:00:00 2001 From: Harish V Date: Fri, 15 Sep 2023 18:29:00 +0800 Subject: [PATCH 10/20] feat: read from efs --- .../06_fetch_ssm_parameters.sh} | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) rename .platform/hooks/{prebuild/01_fetch_ssm_parameters.sh => predeploy/06_fetch_ssm_parameters.sh} (87%) diff --git a/.platform/hooks/prebuild/01_fetch_ssm_parameters.sh b/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh similarity index 87% rename from .platform/hooks/prebuild/01_fetch_ssm_parameters.sh rename to .platform/hooks/predeploy/06_fetch_ssm_parameters.sh index d7605cee9..d1fcf6553 100644 --- a/.platform/hooks/prebuild/01_fetch_ssm_parameters.sh +++ b/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh @@ -4,14 +4,14 @@ set -e # Create directory if it does not exist -if [ ! -d "/etc/isomer" ]; then - mkdir -p /etc/isomer - chown webapp:webapp /etc/isomer +if [ ! -d "/efs/isomer" ]; then + mkdir -p /efs/isomer + chown webapp:webapp /efs/isomer fi # If the .isomer.env file exists, remove it -if [ -f "/etc/isomer/.isomer.env" ]; then - rm /etc/isomer/.isomer.env +if [ -f "/efs/isomer/.isomer.env" ]; then + rm /efs/isomer/.isomer.env fi ENV_TYPE=$(/opt/elasticbeanstalk/bin/get-config environment -k SSM_PREFIX) @@ -84,9 +84,9 @@ aws configure set default.region ap-southeast-1 for ENV_VAR in "${ENV_VARS[@]}"; do echo "Fetching ${ENV_VAR} from SSM" VALUE=$(aws ssm get-parameter --name "${ENV_TYPE}_${ENV_VAR}" --with-decryption --query "Parameter.Value" --output text) - echo "${ENV_VAR}=${VALUE}" >> /etc/isomer/.isomer.env + echo "${ENV_VAR}=${VALUE}" >> /efs/isomer/.isomer.env echo "Saved ${ENV_VAR}" done # Ensure the file is owned by webapp so it has access -chown webapp:webapp /etc/isomer/.isomer.env \ No newline at end of file +chown webapp:webapp /efs/isomer/.isomer.env \ No newline at end of file diff --git a/package.json b/package.json index a94dfbb7f..eb2361794 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "build": "tsc -p tsconfig.build.json", - "start": "node --unhandled-rejections=warn -r ts-node/register/transpile-only -r tsconfig-paths/register -r dotenv/config build/server.js dotenv_config_path=/etc/isomer/.isomer.env", + "start": "node --unhandled-rejections=warn -r ts-node/register/transpile-only -r tsconfig-paths/register -r dotenv/config build/server.js dotenv_config_path=/efs/isomer/.isomer.env", "dev:services": "docker compose up -d", "dev:server": "source .env && ts-node-dev --unhandled-rejections=warn --respawn src/server.js", "dev": "npm run dev:services && npm run dev:server", From 3fd1743dc76b69f043f1550e034f12f0630dae04 Mon Sep 17 00:00:00 2001 From: Harish V Date: Fri, 15 Sep 2023 18:53:10 +0800 Subject: [PATCH 11/20] feat: fix case for multiple instances deploying at same time --- .../predeploy/06_fetch_ssm_parameters.sh | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh b/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh index d1fcf6553..b18166ff6 100644 --- a/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh +++ b/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh @@ -3,7 +3,10 @@ # Exit on first error set -e -# Create directory if it does not exist +# Make sure the local directory exists +mkdir -p /tmp/isomer + +# Create EFS directory if it does not exist if [ ! -d "/efs/isomer" ]; then mkdir -p /efs/isomer chown webapp:webapp /efs/isomer @@ -88,5 +91,26 @@ for ENV_VAR in "${ENV_VARS[@]}"; do echo "Saved ${ENV_VAR}" done -# Ensure the file is owned by webapp so it has access -chown webapp:webapp /efs/isomer/.isomer.env \ No newline at end of file +# Use flock to ensure that the EFS file is locked during the copy operation +( + flock -n 200 || exit 1 + + # Copy the local file to EFS + echo "Copying local env file to EFS" + cp /tmp/isomer/.isomer.env /efs/isomer/.isomer.env + + # Ensure the file on EFS is owned by webapp so it has access + chown webapp:webapp /efs/isomer/.isomer.env + +) 200>/efs/isomer/.isomer.lock + +# Check the exit code of the last command (flock in this case) +if [ $? != 1 ]; then + echo "Lock acquired and data copied successfully." + # Remove the temp file + rm /tmp/isomer/.isomer.env +else + echo "Couldn't acquire the lock. Another instance might be writing to the file." +fi + +echo "Operation completed." \ No newline at end of file From fad8075f747370c94dd60f4b4d2c22b8793d40d1 Mon Sep 17 00:00:00 2001 From: Harish V Date: Fri, 15 Sep 2023 19:06:50 +0800 Subject: [PATCH 12/20] fix: folder paths --- .platform/hooks/predeploy/06_fetch_ssm_parameters.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh b/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh index b18166ff6..9a6186501 100644 --- a/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh +++ b/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh @@ -6,17 +6,17 @@ set -e # Make sure the local directory exists mkdir -p /tmp/isomer +# If the temp .isomer.env file exists, remove it +if [ -f "/tmp/isomer/.isomer.env" ]; then + rm /tmp/isomer/.isomer.env +fi + # Create EFS directory if it does not exist if [ ! -d "/efs/isomer" ]; then mkdir -p /efs/isomer chown webapp:webapp /efs/isomer fi -# If the .isomer.env file exists, remove it -if [ -f "/efs/isomer/.isomer.env" ]; then - rm /efs/isomer/.isomer.env -fi - ENV_TYPE=$(/opt/elasticbeanstalk/bin/get-config environment -k SSM_PREFIX) echo "ENV TYPE: $ENV_TYPE" >> /tmp/ssm-type.txt @@ -87,7 +87,7 @@ aws configure set default.region ap-southeast-1 for ENV_VAR in "${ENV_VARS[@]}"; do echo "Fetching ${ENV_VAR} from SSM" VALUE=$(aws ssm get-parameter --name "${ENV_TYPE}_${ENV_VAR}" --with-decryption --query "Parameter.Value" --output text) - echo "${ENV_VAR}=${VALUE}" >> /efs/isomer/.isomer.env + echo "${ENV_VAR}=${VALUE}" >> /tmp/isomer/.isomer.env echo "Saved ${ENV_VAR}" done From a5a1b876f507f7c13b6cbc986ddeb3a824c7350e Mon Sep 17 00:00:00 2001 From: Harish V Date: Wed, 20 Sep 2023 13:55:52 +0800 Subject: [PATCH 13/20] test: minor log change --- src/server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server.js b/src/server.js index ed2d4aa53..b27fcd38c 100644 --- a/src/server.js +++ b/src/server.js @@ -420,7 +420,7 @@ app.use((req, res, next) => { // error handler app.use(errorHandler) -logger.info(`PRINTING OUT TEST VAR: ${config.get("testVar")}`) +logger.info(`PRINTING OUT TEST VAR 2: ${config.get("testVar")}`) logger.info("Connecting to Sequelize") sequelize From 67d6fe4f7bb00e1c539862fbd8494b6d06000dbe Mon Sep 17 00:00:00 2001 From: Harish V Date: Wed, 20 Sep 2023 14:35:11 +0800 Subject: [PATCH 14/20] feat: skip failures when fetching from SSM --- .platform/hooks/predeploy/06_fetch_ssm_parameters.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh b/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh index 9a6186501..64b2d9b56 100644 --- a/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh +++ b/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh @@ -86,7 +86,15 @@ aws configure set default.region ap-southeast-1 for ENV_VAR in "${ENV_VARS[@]}"; do echo "Fetching ${ENV_VAR} from SSM" + + # Attempt to fetch the parameter; if it fails, skip to the next iteration of the loop VALUE=$(aws ssm get-parameter --name "${ENV_TYPE}_${ENV_VAR}" --with-decryption --query "Parameter.Value" --output text) + + if [ $? -ne 0 ]; then + echo "Failed to fetch ${ENV_VAR}. Skipping." + continue + fi + echo "${ENV_VAR}=${VALUE}" >> /tmp/isomer/.isomer.env echo "Saved ${ENV_VAR}" done From 2b3878f34108947d52cc1c3e0cb9b247dfbbad77 Mon Sep 17 00:00:00 2001 From: Harish V Date: Wed, 20 Sep 2023 15:00:37 +0800 Subject: [PATCH 15/20] feat: skip missing params on ssm --- .platform/hooks/predeploy/06_fetch_ssm_parameters.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh b/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh index 64b2d9b56..be236c668 100644 --- a/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh +++ b/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh @@ -87,8 +87,7 @@ aws configure set default.region ap-southeast-1 for ENV_VAR in "${ENV_VARS[@]}"; do echo "Fetching ${ENV_VAR} from SSM" - # Attempt to fetch the parameter; if it fails, skip to the next iteration of the loop - VALUE=$(aws ssm get-parameter --name "${ENV_TYPE}_${ENV_VAR}" --with-decryption --query "Parameter.Value" --output text) + VALUE=$(aws ssm get-parameter --name "${ENV_TYPE}_${ENV_VAR}" --with-decryption --query "Parameter.Value" --output text 2>/dev/null) if [ $? -ne 0 ]; then echo "Failed to fetch ${ENV_VAR}. Skipping." From 44007aff7f135b92be674d35e698b302ecbc5b28 Mon Sep 17 00:00:00 2001 From: Harish V Date: Wed, 20 Sep 2023 15:05:56 +0800 Subject: [PATCH 16/20] test: add test var --- .platform/hooks/predeploy/06_fetch_ssm_parameters.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh b/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh index be236c668..98e788680 100644 --- a/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh +++ b/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh @@ -22,6 +22,7 @@ echo "ENV TYPE: $ENV_TYPE" >> /tmp/ssm-type.txt # List of all env vars to fetch ENV_VARS=( + "TEST_VAR2" "AUTH_TOKEN_EXPIRY_DURATION_IN_MILLISECONDS" "AWS_BACKEND_EB_ENV_NAME" "AWS_REGION" From 82845d071f67cd65fba5d0fd7dc2738283416e17 Mon Sep 17 00:00:00 2001 From: Harish V Date: Wed, 20 Sep 2023 15:18:45 +0800 Subject: [PATCH 17/20] feat: skip missing params --- .../predeploy/06_fetch_ssm_parameters.sh | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh b/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh index 98e788680..20f049501 100644 --- a/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh +++ b/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh @@ -38,6 +38,7 @@ ENV_VARS=( "DD_AGENT_MAJOR_VERSION" "DD_ENV" "DD_LOGS_INJECTION" + "TEST_VAR3" "DD_SERVICE" "DD_TAGS" "DD_TRACE_STARTUP_LOGS" @@ -85,20 +86,25 @@ ENV_VARS=( echo "Set AWS region" aws configure set default.region ap-southeast-1 +set +e # Do not exit if a command fails + for ENV_VAR in "${ENV_VARS[@]}"; do - echo "Fetching ${ENV_VAR} from SSM" - - VALUE=$(aws ssm get-parameter --name "${ENV_TYPE}_${ENV_VAR}" --with-decryption --query "Parameter.Value" --output text 2>/dev/null) - - if [ $? -ne 0 ]; then - echo "Failed to fetch ${ENV_VAR}. Skipping." - continue - fi - - echo "${ENV_VAR}=${VALUE}" >> /tmp/isomer/.isomer.env - echo "Saved ${ENV_VAR}" + echo "Fetching ${ENV_VAR} from SSM" + + VALUE=$(aws ssm get-parameter --name "${ENV_TYPE}_${ENV_VAR}" --with-decryption --query "Parameter.Value" --output text 2>/dev/null) + STATUS=$? # Capture exit status of the aws ssm command + + if [ $STATUS -ne 0 ]; then + echo "Failed to fetch ${ENV_VAR}. Skipping." + continue + fi + + echo "${ENV_VAR}=${VALUE}" >> /tmp/isomer/.isomer.env + echo "Saved ${ENV_VAR}" done +set -e # Exit on command failure from this point onwards + # Use flock to ensure that the EFS file is locked during the copy operation ( flock -n 200 || exit 1 From 29023e8ba26e128eb9f6106a0f2e1efa745136d6 Mon Sep 17 00:00:00 2001 From: Harish V Date: Wed, 20 Sep 2023 15:49:39 +0800 Subject: [PATCH 18/20] fix: remove test var and console log --- src/config/config.ts | 6 ------ src/server.js | 2 -- 2 files changed, 8 deletions(-) diff --git a/src/config/config.ts b/src/config/config.ts index 944af4857..ec89cf26b 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -421,12 +421,6 @@ const config = convict({ default: "", }, }, - testVar: { - doc: "Test variable", - env: "TEST_VAR", - format: "required-string", - default: "", - }, }) // Perform validation diff --git a/src/server.js b/src/server.js index b27fcd38c..707d1b0b2 100644 --- a/src/server.js +++ b/src/server.js @@ -420,8 +420,6 @@ app.use((req, res, next) => { // error handler app.use(errorHandler) -logger.info(`PRINTING OUT TEST VAR 2: ${config.get("testVar")}`) - logger.info("Connecting to Sequelize") sequelize .authenticate() From 6786df3db18f9532e478d8dd657f238486a92d21 Mon Sep 17 00:00:00 2001 From: Harish V Date: Wed, 20 Sep 2023 15:57:33 +0800 Subject: [PATCH 19/20] fix: remove test vars --- .platform/hooks/predeploy/06_fetch_ssm_parameters.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh b/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh index 20f049501..bde003791 100644 --- a/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh +++ b/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh @@ -22,7 +22,6 @@ echo "ENV TYPE: $ENV_TYPE" >> /tmp/ssm-type.txt # List of all env vars to fetch ENV_VARS=( - "TEST_VAR2" "AUTH_TOKEN_EXPIRY_DURATION_IN_MILLISECONDS" "AWS_BACKEND_EB_ENV_NAME" "AWS_REGION" @@ -38,7 +37,6 @@ ENV_VARS=( "DD_AGENT_MAJOR_VERSION" "DD_ENV" "DD_LOGS_INJECTION" - "TEST_VAR3" "DD_SERVICE" "DD_TAGS" "DD_TRACE_STARTUP_LOGS" @@ -80,7 +78,6 @@ ENV_VARS=( "SSM_PREFIX" "STEP_FUNCTIONS_ARN" "SYSTEM_GITHUB_TOKEN" - "TEST_VAR" ) echo "Set AWS region" From 2a323acdd0dfaa06f050fae1b48fef0bb1a3d784 Mon Sep 17 00:00:00 2001 From: Harish V Date: Wed, 20 Sep 2023 16:13:17 +0800 Subject: [PATCH 20/20] fix: logging for env type --- .platform/hooks/predeploy/06_fetch_ssm_parameters.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh b/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh index bde003791..31cebd0b0 100644 --- a/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh +++ b/.platform/hooks/predeploy/06_fetch_ssm_parameters.sh @@ -18,7 +18,9 @@ if [ ! -d "/efs/isomer" ]; then fi ENV_TYPE=$(/opt/elasticbeanstalk/bin/get-config environment -k SSM_PREFIX) -echo "ENV TYPE: $ENV_TYPE" >> /tmp/ssm-type.txt +TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S') + +echo "Timestamp: $TIMESTAMP - ENV TYPE: $ENV_TYPE" > /tmp/ssm-type.txt # List of all env vars to fetch ENV_VARS=(