From d1bf387483971df9fe88a8361fc9e9fdfad4f457 Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Sun, 29 Dec 2019 13:48:30 +0800 Subject: [PATCH 01/46] Simplify to getparam function --- aws-env.dev | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/aws-env.dev b/aws-env.dev index 33cdb8f1..492b525c 100644 --- a/aws-env.dev +++ b/aws-env.dev @@ -1,17 +1,20 @@ -export ROOT_URL=https://case.dev.unee-t.com -export BUGZILLA_ADMIN_KEY=$(aws --profile uneet-dev ssm get-parameters --names BUGZILLA_ADMIN_KEY --with-decryption --query Parameters[0].Value --output text) -export BUGZILLA_URL=https://dashboard.dev.unee-t.com -export INVITE_LAMBDA_URL=https://invite.dev.unee-t.com -export UNIT_CREATE_LAMBDA_URL=https://unit.dev.unee-t.com/create -export APIENROLL_LAMBDA_URL=https://apienroll.dev.unee-t.com -export PDFGEN_LAMBDA_URL=https://pdfgen.dev.unee-t.com -export PDFCONVERT_LAMBDA_URL=https://prince.dev.unee-t.com -export MONGO_PASSWORD=$(aws --profile uneet-dev ssm get-parameters --names MONGO_PASSWORD --with-decryption --query Parameters[0].Value --output text) -export MONGO_CONNECT=$(aws --profile uneet-dev ssm get-parameters --names MONGO_CONNECT --query Parameters[0].Value --output text) -export CLOUDINARY_PRESET=$(aws --profile uneet-dev ssm get-parameters --names CLOUDINARY_PRESET --with-decryption --query Parameters[0].Value --output text) -export CLOUDINARY_URL=$(aws --profile uneet-dev ssm get-parameters --names CLOUDINARY_URL --with-decryption --query Parameters[0].Value --output text) -export API_ACCESS_TOKEN=$(aws --profile uneet-dev ssm get-parameters --names API_ACCESS_TOKEN --with-decryption --query Parameters[0].Value --output text) -export FROM_EMAIL=$(aws --profile uneet-dev ssm get-parameters --names FROM_EMAIL --query Parameters[0].Value --output text) -export MAIL_URL=$(aws --profile uneet-dev ssm get-parameters --names MAIL_URL --with-decryption --query Parameters[0].Value --output text) +getparam () { + aws --profile ins-dev ssm get-parameters --names "$1" --with-decryption --query Parameters[0].Value --output text +} +export ROOT_URL=https://case.dev.ins.unee-t.com +export BUGZILLA_ADMIN_KEY=$(getparam BUGZILLA_ADMIN_KEY) +export BUGZILLA_URL=https://dashboard.dev.ins.unee-t.com +export INVITE_LAMBDA_URL=https://invite.dev.ins.unee-t.com +export UNIT_CREATE_LAMBDA_URL=https://unit.dev.ins.unee-t.com/create +export APIENROLL_LAMBDA_URL=https://apienroll.dev.ins.unee-t.com +export PDFGEN_LAMBDA_URL=https://pdfgen.dev.ins.unee-t.com +export PDFCONVERT_LAMBDA_URL=https://prince.dev.ins.unee-t.com +export MONGO_PASSWORD=$(getparam MONGO_PASSWORD) +export MONGO_CONNECT=$(getparam MONGO_CONNECT) +export CLOUDINARY_PRESET=$(getparam CLOUDINARY_PRESET) +export CLOUDINARY_URL=$(getparam CLOUDINARY_URL) +export API_ACCESS_TOKEN=$(getparam API_ACCESS_TOKEN) +export FROM_EMAIL=$(getparam FROM_EMAIL) +export MAIL_URL=$(getparam MAIL_URL) export STAGE=dev export DOMAIN=unee-t.com From 996c721c41b6740938df2849136edc2f841ccc90 Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Sun, 29 Dec 2019 14:49:40 +0800 Subject: [PATCH 02/46] Re-factor to match BZFE --- AWS-docker-compose.yml | 2 +- aws-env.dev | 1 + backup/connect.sh | 10 +++++----- deploy.sh | 9 ++++++--- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/AWS-docker-compose.yml b/AWS-docker-compose.yml index f460756a..92f47e8c 100644 --- a/AWS-docker-compose.yml +++ b/AWS-docker-compose.yml @@ -1,7 +1,7 @@ version: '2' services: meteor: - image: uneet/frontend:$COMMIT + image: uneet/frontend:latest mem_reservation: 1g mem_limit: 2g ports: diff --git a/aws-env.dev b/aws-env.dev index 492b525c..d0edbb51 100644 --- a/aws-env.dev +++ b/aws-env.dev @@ -18,3 +18,4 @@ export FROM_EMAIL=$(getparam FROM_EMAIL) export MAIL_URL=$(getparam MAIL_URL) export STAGE=dev export DOMAIN=unee-t.com +export MEFE_TARGET_ARN=$(getparam MEFE_TARGET_ARN) diff --git a/backup/connect.sh b/backup/connect.sh index 8e0d94c8..664900c3 100755 --- a/backup/connect.sh +++ b/backup/connect.sh @@ -7,10 +7,10 @@ show_help() { cat << EOF Usage: ${0##*/} [-p] -By default, deploy to dev environment on AWS account 812644853088 +By default, deploy to dev environment on AWS account - -p PRODUCTION 192458993663 - -d DEMO 915001051872 + -p PRODUCTION + -d DEMO EOF } @@ -32,9 +32,9 @@ do ;; esac done -AWS_PROFILE=uneet-$STAGE +AWS_PROFILE=ins-$STAGE shift "$((OPTIND-1))" # Discard the options and sentinel -- -MONGO_PASSWORD=$(aws --profile $AWS_PROFILE ssm get-parameters --names MONGO_PASSWORD --with-decryption --query Parameters[0].Value --output text) +MONGO_PASSWORD=$(aws --profile $AWS_PROFILE ssm get-parameters --names MONGO_MASTER_PASSWORD --with-decryption --query Parameters[0].Value --output text) MONGO_CONNECT=$(aws --profile $AWS_PROFILE ssm get-parameters --names MONGO_CONNECT --query Parameters[0].Value --output text) mongo "mongodb://root:$MONGO_PASSWORD@$MONGO_CONNECT" diff --git a/deploy.sh b/deploy.sh index 84a5842a..33c0b850 100755 --- a/deploy.sh +++ b/deploy.sh @@ -9,10 +9,10 @@ show_help() { cat << EOF Usage: ${0##*/} [-p] -By default, deploy to dev environment on AWS account 812644853088 +By default, deploy to dev environment on AWS account - -p PRODUCTION 192458993663 - -d DEMO 915001051872 + -p PRODUCTION + -d DEMO EOF } @@ -83,6 +83,9 @@ test "$STAGE" == prod && export STAGE="" envsubst < AWS-docker-compose.yml > docker-compose-${service}.yml ecs-cli compose --aws-profile $AWS_PROFILE -p ${service} -f docker-compose-${service}.yml service up \ + --target-group-arn ${MEFE_TARGET_ARN} \ + --container-name meteor \ + --container-port 8080 \ --deployment-max-percent 100 \ --deployment-min-healthy-percent 50 \ --timeout 7 From 18e24589d2b21b7e3257b3ce6f9260fe7ab7d7d4 Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Sun, 29 Dec 2019 19:19:35 +0800 Subject: [PATCH 03/46] Update mongo connect for Mongo 4.0 DB --- backup/connect.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/backup/connect.sh b/backup/connect.sh index 8e0d94c8..de4741ae 100755 --- a/backup/connect.sh +++ b/backup/connect.sh @@ -1,16 +1,15 @@ #!/bin/bash - STAGE=dev show_help() { cat << EOF Usage: ${0##*/} [-p] -By default, deploy to dev environment on AWS account 812644853088 +By default, deploy to dev environment on AWS account - -p PRODUCTION 192458993663 - -d DEMO 915001051872 + -p PRODUCTION + -d DEMO EOF } @@ -32,9 +31,11 @@ do ;; esac done -AWS_PROFILE=uneet-$STAGE +AWS_PROFILE=ins-$STAGE shift "$((OPTIND-1))" # Discard the options and sentinel -- -MONGO_PASSWORD=$(aws --profile $AWS_PROFILE ssm get-parameters --names MONGO_PASSWORD --with-decryption --query Parameters[0].Value --output text) -MONGO_CONNECT=$(aws --profile $AWS_PROFILE ssm get-parameters --names MONGO_CONNECT --query Parameters[0].Value --output text) -mongo "mongodb://root:$MONGO_PASSWORD@$MONGO_CONNECT" +getparam () { + aws --profile ins-${STAGE} ssm get-parameters --names "$1" --with-decryption --query Parameters[0].Value --output text +} + +mongo "mongodb+srv://$(getparam MONGO_MASTER_USERNAME):$(getparam MONGO_MASTER_PASSWORD)@$(getparam MONGO_CONNECT)" From 9906b54f503074f7ab4ad75b6b4320f23109b53d Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Tue, 31 Dec 2019 08:38:31 +0800 Subject: [PATCH 04/46] Use $STAGE and $DOMAIN to build URL --- aws-env.dev | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/aws-env.dev b/aws-env.dev index d0edbb51..bb443a13 100644 --- a/aws-env.dev +++ b/aws-env.dev @@ -1,14 +1,16 @@ getparam () { aws --profile ins-dev ssm get-parameters --names "$1" --with-decryption --query Parameters[0].Value --output text } -export ROOT_URL=https://case.dev.ins.unee-t.com +export DOMAIN=ins.unee-t.com +export STAGE=dev +export ROOT_URL=https://case.$STAGE.$DOMAIN export BUGZILLA_ADMIN_KEY=$(getparam BUGZILLA_ADMIN_KEY) -export BUGZILLA_URL=https://dashboard.dev.ins.unee-t.com -export INVITE_LAMBDA_URL=https://invite.dev.ins.unee-t.com -export UNIT_CREATE_LAMBDA_URL=https://unit.dev.ins.unee-t.com/create -export APIENROLL_LAMBDA_URL=https://apienroll.dev.ins.unee-t.com -export PDFGEN_LAMBDA_URL=https://pdfgen.dev.ins.unee-t.com -export PDFCONVERT_LAMBDA_URL=https://prince.dev.ins.unee-t.com +export BUGZILLA_URL=https://dashboard.$STAGE.$DOMAIN +export INVITE_LAMBDA_URL=https://invite.$STAGE.$DOMAIN +export UNIT_CREATE_LAMBDA_URL=https://unit.$STAGE.$DOMAIN/create +export APIENROLL_LAMBDA_URL=https://apienroll.$STAGE.$DOMAIN +export PDFGEN_LAMBDA_URL=https://pdfgen.$STAGE.$DOMAIN +export PDFCONVERT_LAMBDA_URL=https://prince.$STAGE.$DOMAIN export MONGO_PASSWORD=$(getparam MONGO_PASSWORD) export MONGO_CONNECT=$(getparam MONGO_CONNECT) export CLOUDINARY_PRESET=$(getparam CLOUDINARY_PRESET) @@ -16,6 +18,4 @@ export CLOUDINARY_URL=$(getparam CLOUDINARY_URL) export API_ACCESS_TOKEN=$(getparam API_ACCESS_TOKEN) export FROM_EMAIL=$(getparam FROM_EMAIL) export MAIL_URL=$(getparam MAIL_URL) -export STAGE=dev -export DOMAIN=unee-t.com export MEFE_TARGET_ARN=$(getparam MEFE_TARGET_ARN) From 4e8ca9bb8ae280bb72304dc101b45377b9f2d53f Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Sun, 29 Dec 2019 19:19:35 +0800 Subject: [PATCH 05/46] Update mongo connect for Mongo 4.0 DB --- backup/connect.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/backup/connect.sh b/backup/connect.sh index 2de97355..de4741ae 100755 --- a/backup/connect.sh +++ b/backup/connect.sh @@ -34,6 +34,8 @@ done AWS_PROFILE=ins-$STAGE shift "$((OPTIND-1))" # Discard the options and sentinel -- -MONGO_PASSWORD=$(aws --profile $AWS_PROFILE ssm get-parameters --names MONGO_MASTER_PASSWORD --with-decryption --query Parameters[0].Value --output text) -MONGO_CONNECT=$(aws --profile $AWS_PROFILE ssm get-parameters --names MONGO_CONNECT --query Parameters[0].Value --output text) -mongo "mongodb://root:$MONGO_PASSWORD@$MONGO_CONNECT" +getparam () { + aws --profile ins-${STAGE} ssm get-parameters --names "$1" --with-decryption --query Parameters[0].Value --output text +} + +mongo "mongodb+srv://$(getparam MONGO_MASTER_USERNAME):$(getparam MONGO_MASTER_PASSWORD)@$(getparam MONGO_CONNECT)" From ea9229bbedca4681a5cecb3728dca01121dfdd9c Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Tue, 31 Dec 2019 09:26:50 +0800 Subject: [PATCH 06/46] Sync with bugzilla deploy.sh --- deploy.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy.sh b/deploy.sh index 33c0b850..a739aa9d 100755 --- a/deploy.sh +++ b/deploy.sh @@ -34,7 +34,7 @@ do ;; esac done -AWS_PROFILE=uneet-$STAGE +AWS_PROFILE=ins-$STAGE shift "$((OPTIND-1))" # Discard the options and sentinel -- export COMMIT=$(git rev-parse --short HEAD) @@ -71,7 +71,7 @@ else ecs-cli -version fi -ecs-cli configure --cluster master --region ap-southeast-1 --compose-service-name-prefix ecscompose-service- +ecs-cli configure --cluster master --region ap-southeast-1 test -f aws-env.$STAGE && source aws-env.$STAGE service=$(grep -A1 services AWS-docker-compose.yml | tail -n1 | tr -cd '[[:alnum:]]') From c8b24720c98aa85504f24ce54bd5334298c1754e Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Tue, 31 Dec 2019 09:37:36 +0800 Subject: [PATCH 07/46] Mongo 4 issue perhaps with "MongoError: command listIndexes requires authentication" --- AWS-docker-compose.yml | 3 +-- deploy.sh | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/AWS-docker-compose.yml b/AWS-docker-compose.yml index 92f47e8c..b8ba15ce 100644 --- a/AWS-docker-compose.yml +++ b/AWS-docker-compose.yml @@ -10,10 +10,9 @@ services: - ROOT_URL=${ROOT_URL} - BUGZILLA_URL=${BUGZILLA_URL} - BUGZILLA_ADMIN_KEY=${BUGZILLA_ADMIN_KEY} - - MONGO_URL=mongodb://root:${MONGO_PASSWORD}@${MONGO_CONNECT} + - MONGO_URL=mongodb+srv://${MONGO_MASTER_USERNAME}:${MONGO_MASTER_PASSWORD}@${MONGO_CONNECT} - CLOUDINARY_URL=${CLOUDINARY_URL} - CLOUDINARY_PRESET=${CLOUDINARY_PRESET} - - COMMIT=${COMMIT} - API_ACCESS_TOKEN=${API_ACCESS_TOKEN} - FROM_EMAIL=${FROM_EMAIL} - MAIL_URL=${MAIL_URL} diff --git a/deploy.sh b/deploy.sh index a739aa9d..d866b1b4 100755 --- a/deploy.sh +++ b/deploy.sh @@ -85,7 +85,8 @@ envsubst < AWS-docker-compose.yml > docker-compose-${service}.yml ecs-cli compose --aws-profile $AWS_PROFILE -p ${service} -f docker-compose-${service}.yml service up \ --target-group-arn ${MEFE_TARGET_ARN} \ --container-name meteor \ - --container-port 8080 \ + --container-port 3000 \ + --create-log-groups \ --deployment-max-percent 100 \ --deployment-min-healthy-percent 50 \ --timeout 7 From 7fde80ca17359061397d37fef0db1b52c7d2ebed Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Tue, 31 Dec 2019 12:11:32 +0800 Subject: [PATCH 08/46] Add MASTER variant --- aws-env.dev | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aws-env.dev b/aws-env.dev index bb443a13..8a4134a0 100644 --- a/aws-env.dev +++ b/aws-env.dev @@ -11,7 +11,8 @@ export UNIT_CREATE_LAMBDA_URL=https://unit.$STAGE.$DOMAIN/create export APIENROLL_LAMBDA_URL=https://apienroll.$STAGE.$DOMAIN export PDFGEN_LAMBDA_URL=https://pdfgen.$STAGE.$DOMAIN export PDFCONVERT_LAMBDA_URL=https://prince.$STAGE.$DOMAIN -export MONGO_PASSWORD=$(getparam MONGO_PASSWORD) +export MONGO_MASTER_USERNAME=$(getparam MONGO_MASTER_USERNAME) +export MONGO_MASTER_PASSWORD=$(getparam MONGO_MASTER_PASSWORD) export MONGO_CONNECT=$(getparam MONGO_CONNECT) export CLOUDINARY_PRESET=$(getparam CLOUDINARY_PRESET) export CLOUDINARY_URL=$(getparam CLOUDINARY_URL) From 6ec91bcf1b1f327b2b6fd3d98ba158a301f5c551 Mon Sep 17 00:00:00 2001 From: tuananh1508 <58845900+tuananh1508@users.noreply.github.com> Date: Wed, 15 Jan 2020 16:05:04 +0700 Subject: [PATCH 09/46] Remove hard coded variables (#7) * create new branch * Change some hardcoded to environment variable * Add config to use travis ci for dev * check deploy dev * check deploy dev * check deploy dev * check deploy dev * Deploy with full steps * change build branch Master * remove sudo and skip_cleanup in .travis.yml * remove hardcode in AWS-docker-compose.yml file * add a comment to buildspec.yml * test the meteor build step * change bcrypt from 1.0.3 (which is not supported in node12) to 3.0.6 * change deploy branch for dev to master --- .travis.yml | 85 ++++++++++++++++++++++++++++++++---------- AWS-docker-compose.yml | 30 +++++++++++++-- aws-env.dev | 64 ++++++++++++++++++++----------- buildspec.yml | 1 + deploy.sh | 30 +++++++++------ package.json | 2 +- 6 files changed, 155 insertions(+), 57 deletions(-) diff --git a/.travis.yml b/.travis.yml index 72f8365a..dfde86a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,41 @@ -sudo: required +# Variables needed for this script are: -language: node_js -node_js: - - lts/* +# Case 1: Stored on Travis Settings + # For all environments: + # - DOCKER_CI_REPO_NAME + # - DOCKER_USERNAME + # - DOCKER_PASSWORD + + #For dev environment: + # - AWS_ACCOUNT_USER_ID_DEV + # - AWS_ACCOUNT_SECRET_DEV + # - AWS_PROFILE_DEV <-- is this needed? + + #For Prod environment: + # - AWS_ACCOUNT_USER_ID_PROD + # - AWS_ACCOUNT_SECRET_PROD + # - AWS_PROFILE_PROD <-- is this needed? + + #For Demo environment: + # - AWS_ACCOUNT_USER_ID_DEMO + # - AWS_ACCOUNT_SECRET_DEMO + # - AWS_PROFILE_DEMO <-- is this needed? + +# Case 2: Created when Travis CI runs + # - IMAGE_TAG + +# language: node_js +# node_js: +# - lts/* +language: generic +services: + - docker + +env: + global: + - COMMIT=${TRAVIS_COMMIT::7} + #Add IMAGE_TAG variable to build docker image + - IMAGE_TAG=${TRAVIS_COMMIT::7} before_install: # Removed command as pyenv is no longer found during deploy @@ -15,36 +48,48 @@ before_install: https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest && chmod +x $HOME/.local/bin/ecs-cli -cache: - directories: - - node_modules +# cache: +# directories: +# - node_modules install: - - meteor npm install + # - meteor npm install + # #Adding script build docker image + - docker build -t $DOCKER_CI_REPO_NAME . + +# script: +# - npm t -script: - - npm t +# #Adding script deploy docker image to docker repository + +after_success: + - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"; + - docker build -t $DOCKER_CI_REPO_NAME:latest . + - docker tag $DOCKER_CI_REPO_NAME:latest $DOCKER_CI_REPO_NAME:$IMAGE_TAG + - docker push $DOCKER_CI_REPO_NAME:latest + - docker push $DOCKER_CI_REPO_NAME:$IMAGE_TAG matrix: include: - - env: DEPLOY=none + # add deploy stage for dev + - env: DEPLOY=dev + if: branch = master + deploy: + provider: script + script: PROFILE=$AWS_PROFILE_DEV AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_DEV AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_DEV AWS_REGION=$AWS_DEFAULT_REGION ./deploy.sh -d + on: + branch: master - env: DEPLOY=demo if: tag IS present deploy: provider: script - skip_cleanup: true - script: AWS_ACCESS_KEY_ID=$AWS_915001051872_ID AWS_SECRET_ACCESS_KEY=$AWS_915001051872_SECRET ./deploy.sh -d + script: PROFILE=$AWS_PROFILE_DEMO AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_DEMO AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_DEMO AWS_REGION=$AWS_DEFAULT_REGION ./deploy.sh -s on: tags: true - env: DEPLOY=prod if: tag IS present deploy: provider: script - skip_cleanup: true - script: AWS_ACCESS_KEY_ID=$AWS_192458993663_ID AWS_SECRET_ACCESS_KEY=$AWS_192458993663_SECRET ./deploy.sh -p && AWS_ACCESS_KEY_ID=$AWS_192458993663_ID AWS_SECRET_ACCESS_KEY=$AWS_192458993663_SECRET aws cloudfront create-invalidation --distribution-id E173XT6X8V4A18 --paths '/*' + script: PROFILE=$AWS_PROFILE_PROD AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_PROD AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_PROD AWS_REGION=$AWS_DEFAULT_REGION ./deploy.sh -p && AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_PROD AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_PROD aws cloudfront create-invalidation --distribution-id E173XT6X8V4A18 --paths '/*' on: - tags: true - -env: - global: - - COMMIT=${TRAVIS_COMMIT::7} + tags: true \ No newline at end of file diff --git a/AWS-docker-compose.yml b/AWS-docker-compose.yml index b8ba15ce..f29b0baf 100644 --- a/AWS-docker-compose.yml +++ b/AWS-docker-compose.yml @@ -1,7 +1,31 @@ +#Variable for this script are set in: + # - Travis CI: + # - DOCKER_CI_REPO_NAME + # - AWS_DEFAULT_REGION + # - AWS Parameter Store: + # - ROOT_URL + # - BUGZILLA_URL + # - BUGZILLA_ADMIN_KEY + # - MONGO_MASTER_USERNAME + # - MONGO_MASTER_PASSWORD + # - MONGO_CONNECT + # - CLOUDINARY_URL + # - CLOUDINARY_PRESET + # - API_ACCESS_TOKEN + # - FROM_EMAIL + # - MAIL_URL + # - INVITE_LAMBDA_URL + # - APIENROLL_LAMBDA_URL + # - UNIT_CREATE_LAMBDA_URL + # - PDFGEN_LAMBDA_URL + # - PDFCONVERT_LAMBDA_URL + # - STAGE + # - DOMAIN + version: '2' services: meteor: - image: uneet/frontend:latest + image: $(DOCKER_CI_REPO_NAME):latest mem_reservation: 1g mem_limit: 2g ports: @@ -26,6 +50,6 @@ services: logging: driver: awslogs options: - awslogs-region: ap-southeast-1 - awslogs-group: meteor + awslogs-region: $(AWS_DEFAULT_REGION) + awslogs-group: meteor awslogs-stream-prefix: ecs diff --git a/aws-env.dev b/aws-env.dev index 8a4134a0..8adb73bd 100644 --- a/aws-env.dev +++ b/aws-env.dev @@ -1,22 +1,44 @@ -getparam () { - aws --profile ins-dev ssm get-parameters --names "$1" --with-decryption --query Parameters[0].Value --output text -} -export DOMAIN=ins.unee-t.com +#!/bin/bash +### This file stores all environment variables for the DEV environment for this repo + +# This script is called as part of the Travis CI deployment routine +# We can use the default aws profile configured in Travis CI settings to get the variables we need + +# We create a procedure to retrieve the variables from the AWS parameter store +# Make sure to +# - configure your AWS CLI accordingly +# - update the profile you need to use to access these variables if needed +# - PROFILE is set when .travis.yml run + + getparam () { + aws --profile ${PROFILE} ssm get-parameters --names "$1" --with-decryption --query Parameters[0].Value --output text + } + +# We prepare the hardcoded variables that we will need to deploy what's needed + export STAGE=dev -export ROOT_URL=https://case.$STAGE.$DOMAIN -export BUGZILLA_ADMIN_KEY=$(getparam BUGZILLA_ADMIN_KEY) -export BUGZILLA_URL=https://dashboard.$STAGE.$DOMAIN -export INVITE_LAMBDA_URL=https://invite.$STAGE.$DOMAIN -export UNIT_CREATE_LAMBDA_URL=https://unit.$STAGE.$DOMAIN/create -export APIENROLL_LAMBDA_URL=https://apienroll.$STAGE.$DOMAIN -export PDFGEN_LAMBDA_URL=https://pdfgen.$STAGE.$DOMAIN -export PDFCONVERT_LAMBDA_URL=https://prince.$STAGE.$DOMAIN -export MONGO_MASTER_USERNAME=$(getparam MONGO_MASTER_USERNAME) -export MONGO_MASTER_PASSWORD=$(getparam MONGO_MASTER_PASSWORD) -export MONGO_CONNECT=$(getparam MONGO_CONNECT) -export CLOUDINARY_PRESET=$(getparam CLOUDINARY_PRESET) -export CLOUDINARY_URL=$(getparam CLOUDINARY_URL) -export API_ACCESS_TOKEN=$(getparam API_ACCESS_TOKEN) -export FROM_EMAIL=$(getparam FROM_EMAIL) -export MAIL_URL=$(getparam MAIL_URL) -export MEFE_TARGET_ARN=$(getparam MEFE_TARGET_ARN) + +# Variables that are maintained in the AWS parameter store for the environment: + + export DOMAIN=$(getparam DOMAIN) + export BUGZILLA_ADMIN_KEY=$(getparam BUGZILLA_ADMIN_KEY) + export MONGO_MASTER_USERNAME=$(getparam MONGO_MASTER_USERNAME) + export MONGO_MASTER_PASSWORD=$(getparam MONGO_MASTER_PASSWORD) + export MONGO_CONNECT=$(getparam MONGO_CONNECT) + export CLOUDINARY_PRESET=$(getparam CLOUDINARY_PRESET) + export CLOUDINARY_URL=$(getparam CLOUDINARY_URL) + export API_ACCESS_TOKEN=$(getparam API_ACCESS_TOKEN) + export FROM_EMAIL=$(getparam FROM_EMAIL) + export MAIL_URL=$(getparam MAIL_URL) + export MEFE_TARGET_ARN=$(getparam MEFE_TARGET_ARN) + +# Variables that are built from other variables: + + export ROOT_URL=https://case.$STAGE.$DOMAIN + export BUGZILLA_URL=https://dashboard.$STAGE.$DOMAIN + export INVITE_LAMBDA_URL=https://invite.$STAGE.$DOMAIN + export UNIT_CREATE_LAMBDA_URL=https://unit.$STAGE.$DOMAIN/create + export APIENROLL_LAMBDA_URL=https://apienroll.$STAGE.$DOMAIN + export PDFGEN_LAMBDA_URL=https://pdfgen.$STAGE.$DOMAIN + export PDFCONVERT_LAMBDA_URL=https://prince.$STAGE.$DOMAIN + diff --git a/buildspec.yml b/buildspec.yml index 8fc70167..fbef95e1 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -1,3 +1,4 @@ +#This file is used by AWS codebuild. --- version: 0.2 diff --git a/deploy.sh b/deploy.sh index d866b1b4..f3f054bf 100755 --- a/deploy.sh +++ b/deploy.sh @@ -20,11 +20,17 @@ EOF while getopts "pd" opt do case $opt in + #Add option d for development + d) + echo "DEVELOPMENT" >&2 + STAGE=dev + ;; p) echo "PRODUCTION" >&2 STAGE=prod ;; - d) + #Change option demo from d to s + s) echo "DEMO" >&2 STAGE=demo ;; @@ -34,14 +40,14 @@ do ;; esac done -AWS_PROFILE=ins-$STAGE + shift "$((OPTIND-1))" # Discard the options and sentinel -- export COMMIT=$(git rev-parse --short HEAD) -if ! aws configure --profile $AWS_PROFILE list +if ! aws configure --profile $PROFILE list then - echo Profile $AWS_PROFILE does not exist >&2 + echo Profile $PROFILE does not exist >&2 if ! test "$AWS_ACCESS_KEY_ID" then @@ -50,13 +56,13 @@ then fi echo Attempting to setup one from the environment >&2 - aws configure set profile.uneet-${STAGE}.aws_access_key_id $AWS_ACCESS_KEY_ID - aws configure set profile.uneet-${STAGE}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY - aws configure set profile.uneet-${STAGE}.region ap-southeast-1 + aws configure set profile.${PROFILE}.aws_access_key_id $AWS_ACCESS_KEY_ID + aws configure set profile.${PROFILE}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY + aws configure set profile.${PROFILE}.region $AWS_REGION - if ! aws configure --profile $AWS_PROFILE list + if ! aws configure --profile $PROFILE list then - echo Profile $AWS_PROFILE does not exist >&2 + echo Profile $PROFILE does not exist >&2 exit 1 fi @@ -71,7 +77,7 @@ else ecs-cli -version fi -ecs-cli configure --cluster master --region ap-southeast-1 +ecs-cli configure --cluster master --region $AWS_REGION test -f aws-env.$STAGE && source aws-env.$STAGE service=$(grep -A1 services AWS-docker-compose.yml | tail -n1 | tr -cd '[[:alnum:]]') @@ -82,7 +88,7 @@ test "$STAGE" == prod && export STAGE="" envsubst < AWS-docker-compose.yml > docker-compose-${service}.yml -ecs-cli compose --aws-profile $AWS_PROFILE -p ${service} -f docker-compose-${service}.yml service up \ +ecs-cli compose --aws-profile $PROFILE -p ${service} -f docker-compose-${service}.yml service up \ --target-group-arn ${MEFE_TARGET_ARN} \ --container-name meteor \ --container-port 3000 \ @@ -91,6 +97,6 @@ ecs-cli compose --aws-profile $AWS_PROFILE -p ${service} -f docker-compose-${ser --deployment-min-healthy-percent 50 \ --timeout 7 -ecs-cli compose --aws-profile $AWS_PROFILE -p ${service} -f docker-compose-${service}.yml service ps +ecs-cli compose --aws-profile $PROFILE -p ${service} -f docker-compose-${service}.yml service ps echo "END $0 $(date)" diff --git a/package.json b/package.json index 91317c63..ca7345bd 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "dependencies": { "@babel/runtime": "^7.1.5", - "bcrypt": "^1.0.3", + "bcrypt": "^3.0.6", "body-parser": "^1.18.2", "classnames": "^2.2.5", "hammerjs": "^2.0.8", From 84cd02eccffa1ccf4bac3fca932426d0bee02358 Mon Sep 17 00:00:00 2001 From: tuananh1508 <58845900+tuananh1508@users.noreply.github.com> Date: Thu, 16 Jan 2020 09:01:21 +0700 Subject: [PATCH 10/46] Fix broken travis ci (#9) * Use clear variable names * Check variables * update variable in aws-env.dev * change build dev on branch master --- .travis.yml | 9 ++++++++- AWS-docker-compose.yml | 4 ++-- aws-env.dev | 2 +- deploy.sh | 24 ++++++++++++------------ 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index dfde86a2..9e9b1af4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -76,7 +76,14 @@ matrix: if: branch = master deploy: provider: script - script: PROFILE=$AWS_PROFILE_DEV AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_DEV AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_DEV AWS_REGION=$AWS_DEFAULT_REGION ./deploy.sh -d + # We need to set variables that are comming from travis ci setting + # Variables: + # - DOCKER_CI_REPO_NAME + # - AWS_PROFILE_DEV + # - AWS_ACCOUNT_USER_ID_DEV + # - AWS_ACCOUNT_SECRET_DEV + # - AWS_DEFAULT_REGION + script: TRAVIS_DOCKER_REPO_NAME=$DOCKER_CI_REPO_NAME TRAVIS_PROFILE=$AWS_PROFILE_DEV TRAVIS_AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_DEV TRAVIS_AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_DEV TRAVIS_AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION ./deploy.sh -d on: branch: master - env: DEPLOY=demo diff --git a/AWS-docker-compose.yml b/AWS-docker-compose.yml index f29b0baf..67cc25f1 100644 --- a/AWS-docker-compose.yml +++ b/AWS-docker-compose.yml @@ -25,7 +25,7 @@ version: '2' services: meteor: - image: $(DOCKER_CI_REPO_NAME):latest + image: ${TRAVIS_DOCKER_REPO_NAME}:latest mem_reservation: 1g mem_limit: 2g ports: @@ -50,6 +50,6 @@ services: logging: driver: awslogs options: - awslogs-region: $(AWS_DEFAULT_REGION) + awslogs-region: ${TRAVIS_AWS_DEFAULT_REGION} awslogs-group: meteor awslogs-stream-prefix: ecs diff --git a/aws-env.dev b/aws-env.dev index 8adb73bd..8a8c2627 100644 --- a/aws-env.dev +++ b/aws-env.dev @@ -11,7 +11,7 @@ # - PROFILE is set when .travis.yml run getparam () { - aws --profile ${PROFILE} ssm get-parameters --names "$1" --with-decryption --query Parameters[0].Value --output text + aws --profile ${TRAVIS_PROFILE} ssm get-parameters --names "$1" --with-decryption --query Parameters[0].Value --output text } # We prepare the hardcoded variables that we will need to deploy what's needed diff --git a/deploy.sh b/deploy.sh index f3f054bf..c7a51a2c 100755 --- a/deploy.sh +++ b/deploy.sh @@ -45,24 +45,24 @@ shift "$((OPTIND-1))" # Discard the options and sentinel -- export COMMIT=$(git rev-parse --short HEAD) -if ! aws configure --profile $PROFILE list +if ! aws configure --profile $TRAVIS_PROFILE list then - echo Profile $PROFILE does not exist >&2 + echo Profile $TRAVIS_PROFILE does not exist >&2 - if ! test "$AWS_ACCESS_KEY_ID" + if ! test "$TRAVIS_AWS_ACCESS_KEY_ID" then - echo Missing $AWS_ACCESS_KEY_ID >&2 + echo Missing $TRAVIS_AWS_ACCESS_KEY_ID >&2 exit 1 fi echo Attempting to setup one from the environment >&2 - aws configure set profile.${PROFILE}.aws_access_key_id $AWS_ACCESS_KEY_ID - aws configure set profile.${PROFILE}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY - aws configure set profile.${PROFILE}.region $AWS_REGION + aws configure set profile.${TRAVIS_PROFILE}.aws_access_key_id $TRAVIS_AWS_ACCESS_KEY_ID + aws configure set profile.${TRAVIS_PROFILE}.aws_secret_access_key $TRAVIS_AWS_SECRET_ACCESS_KEY + aws configure set profile.${TRAVIS_PROFILE}.region $TRAVIS_AWS_DEFAULT_REGION - if ! aws configure --profile $PROFILE list + if ! aws configure --profile $TRAVIS_PROFILE list then - echo Profile $PROFILE does not exist >&2 + echo Profile $TRAVIS_PROFILE does not exist >&2 exit 1 fi @@ -77,7 +77,7 @@ else ecs-cli -version fi -ecs-cli configure --cluster master --region $AWS_REGION +ecs-cli configure --cluster master --region $TRAVIS_AWS_DEFAULT_REGION test -f aws-env.$STAGE && source aws-env.$STAGE service=$(grep -A1 services AWS-docker-compose.yml | tail -n1 | tr -cd '[[:alnum:]]') @@ -88,7 +88,7 @@ test "$STAGE" == prod && export STAGE="" envsubst < AWS-docker-compose.yml > docker-compose-${service}.yml -ecs-cli compose --aws-profile $PROFILE -p ${service} -f docker-compose-${service}.yml service up \ +ecs-cli compose --aws-profile $TRAVIS_PROFILE -p ${service} -f docker-compose-${service}.yml service up \ --target-group-arn ${MEFE_TARGET_ARN} \ --container-name meteor \ --container-port 3000 \ @@ -97,6 +97,6 @@ ecs-cli compose --aws-profile $PROFILE -p ${service} -f docker-compose-${service --deployment-min-healthy-percent 50 \ --timeout 7 -ecs-cli compose --aws-profile $PROFILE -p ${service} -f docker-compose-${service}.yml service ps +ecs-cli compose --aws-profile $TRAVIS_PROFILE -p ${service} -f docker-compose-${service}.yml service ps echo "END $0 $(date)" From 47896d10028909148f9fdc7c27afb4d42a20e4d4 Mon Sep 17 00:00:00 2001 From: Franck <31331637+franck-boullier@users.noreply.github.com> Date: Wed, 22 Jan 2020 13:33:23 +0800 Subject: [PATCH 11/46] Fix cloudinary issue (#17) * replace confusing variable name with a better name * update aws-env.[STAGE] for DEMO and PROD * fix linting * rename variable CLOUDINARY_URL to CLOUDINARY_API_ENDPOINT --- .env.sample | 2 +- AWS-docker-compose.yml | 49 ++++++------- app.json | 2 +- aws-env.demo | 68 ++++++++++++++----- aws-env.dev | 17 +++-- aws-env.prod | 67 +++++++++++++----- env-setup.bash | 6 +- .../state/epics/base/file-upload-processor.js | 4 +- imports/state/epics/create-attachment.test.js | 6 +- imports/ui/case/case-messages.test.js | 2 +- imports/util/matchers.js | 2 +- server/main.js | 2 +- 12 files changed, 152 insertions(+), 75 deletions(-) diff --git a/.env.sample b/.env.sample index 2b0e5416..dc82d8e0 100644 --- a/.env.sample +++ b/.env.sample @@ -5,7 +5,7 @@ UNIT_CREATE_LAMBDA_URL= PDFCONVERT_LAMBDA_URL= MAIL_URL= -CLOUDINARY_URL= +CLOUDINARY_API_ENDPOINT= CLOUDINARY_PRESET= API_ACCESS_TOKEN= FROM_EMAIL="Local Unee-T Case " diff --git a/AWS-docker-compose.yml b/AWS-docker-compose.yml index 67cc25f1..bb3176e7 100644 --- a/AWS-docker-compose.yml +++ b/AWS-docker-compose.yml @@ -1,26 +1,29 @@ #Variable for this script are set in: - # - Travis CI: - # - DOCKER_CI_REPO_NAME - # - AWS_DEFAULT_REGION - # - AWS Parameter Store: - # - ROOT_URL - # - BUGZILLA_URL - # - BUGZILLA_ADMIN_KEY - # - MONGO_MASTER_USERNAME - # - MONGO_MASTER_PASSWORD - # - MONGO_CONNECT - # - CLOUDINARY_URL - # - CLOUDINARY_PRESET - # - API_ACCESS_TOKEN - # - FROM_EMAIL - # - MAIL_URL - # - INVITE_LAMBDA_URL - # - APIENROLL_LAMBDA_URL - # - UNIT_CREATE_LAMBDA_URL - # - PDFGEN_LAMBDA_URL - # - PDFCONVERT_LAMBDA_URL - # - STAGE - # - DOMAIN +# - Travis CI: +# - DOCKER_CI_REPO_NAME +# - AWS_DEFAULT_REGION +# - AWS Parameter Store: +# - DOMAIN +# - STAGE +# - BUGZILLA_ADMIN_KEY +# - MONGO_MASTER_USERNAME +# - MONGO_MASTER_PASSWORD +# - MONGO_CONNECT +# - API_ACCESS_TOKEN +# - FROM_EMAIL +# - MAIL_URL +# - The file `aws-env.[STAGE]` +# - ROOT_URL +# - BUGZILLA_URL +# - CLOUDINARY_API_ENDPOINT +# - INVITE_LAMBDA_URL +# - APIENROLL_LAMBDA_URL +# - UNIT_CREATE_LAMBDA_URL +# - PDFGEN_LAMBDA_URL +# - PDFCONVERT_LAMBDA_URL +# - The File `.travis.yml` +# - TRAVIS_DOCKER_REPO_NAME +# - TRAVIS_AWS_DEFAULT_REGION version: '2' services: @@ -35,7 +38,7 @@ services: - BUGZILLA_URL=${BUGZILLA_URL} - BUGZILLA_ADMIN_KEY=${BUGZILLA_ADMIN_KEY} - MONGO_URL=mongodb+srv://${MONGO_MASTER_USERNAME}:${MONGO_MASTER_PASSWORD}@${MONGO_CONNECT} - - CLOUDINARY_URL=${CLOUDINARY_URL} + - CLOUDINARY_API_ENDPOINT=${CLOUDINARY_API_ENDPOINT} - CLOUDINARY_PRESET=${CLOUDINARY_PRESET} - API_ACCESS_TOKEN=${API_ACCESS_TOKEN} - FROM_EMAIL=${FROM_EMAIL} diff --git a/app.json b/app.json index aaa60d38..3d71a495 100644 --- a/app.json +++ b/app.json @@ -22,7 +22,7 @@ "CLOUDINARY_PRESET": { "required": true }, - "CLOUDINARY_URL": { + "CLOUDINARY_API_ENDPOINT": { "required": true }, "FROM_EMAIL": { diff --git a/aws-env.demo b/aws-env.demo index 0e4ff53a..ad226733 100644 --- a/aws-env.demo +++ b/aws-env.demo @@ -1,18 +1,50 @@ -export ROOT_URL=https://case.demo.unee-t.com -export BUGZILLA_ADMIN_KEY=$(aws --profile uneet-demo ssm get-parameters --names BUGZILLA_ADMIN_KEY --with-decryption --query Parameters[0].Value --output text) -export BUGZILLA_URL=https://dashboard.demo.unee-t.com -export INVITE_LAMBDA_URL=https://invite.demo.unee-t.com -export UNIT_CREATE_LAMBDA_URL=https://unit.demo.unee-t.com/create -export APIENROLL_LAMBDA_URL=https://apienroll.demo.unee-t.com -export PDFGEN_LAMBDA_URL=https://pdfgen.demo.unee-t.com -export PDFCONVERT_LAMBDA_URL=https://prince.demo.unee-t.com -export MONGO_PASSWORD=$(aws --profile uneet-demo ssm get-parameters --names MONGO_PASSWORD --with-decryption --query Parameters[0].Value --output text) -export MONGO_CONNECT=$(aws --profile uneet-demo ssm get-parameters --names MONGO_CONNECT --query Parameters[0].Value --output text) -# couldinary.demo@unee-t.com -export CLOUDINARY_PRESET=$(aws --profile uneet-demo ssm get-parameters --names CLOUDINARY_PRESET --with-decryption --query Parameters[0].Value --output text) -export CLOUDINARY_URL=$(aws --profile uneet-demo ssm get-parameters --names CLOUDINARY_URL --with-decryption --query Parameters[0].Value --output text) -export API_ACCESS_TOKEN=$(aws --profile uneet-demo ssm get-parameters --names API_ACCESS_TOKEN --with-decryption --query Parameters[0].Value --output text) -export FROM_EMAIL="DEMO Unee-T Case " -export MAIL_URL=$(aws --profile uneet-demo ssm get-parameters --names MAIL_URL --with-decryption --query Parameters[0].Value --output text) -export STAGE=demo -export DOMAIN=unee-t.com +#!/bin/bash +### This file stores all environment variables for the DEV environment for this repo + +# This script is called as part of the Travis CI deployment routine +# We can use the default aws profile configured in Travis CI settings to get the variables we need + +# We create a procedure to retrieve the variables from the AWS parameter store +# Make sure to +# - configure your AWS CLI accordingly +# - update the profile you need to use to access these variables if needed +# - PROFILE is set when .travis.yml run + + getparam () { + aws --profile ${TRAVIS_PROFILE} ssm get-parameters --names "$1" --with-decryption --query Parameters[0].Value --output text + } + +# Variables that are maintained in the AWS parameter store for the environment: + + export DOMAIN=$(getparam DOMAIN) + export BUGZILLA_ADMIN_KEY=$(getparam BUGZILLA_ADMIN_KEY) + export STAGE=$(getparam STAGE) + + export MONGO_MASTER_USERNAME=$(getparam MONGO_MASTER_USERNAME) + export MONGO_MASTER_PASSWORD=$(getparam MONGO_MASTER_PASSWORD) + export MONGO_CONNECT=$(getparam MONGO_CONNECT) + + export CLOUDINARY_CLOUD_NAME=$(getparam CLOUDINARY_CLOUD_NAME) + export CLOUDINARY_PRESET=$(getparam CLOUDINARY_PRESET) + + export API_ACCESS_TOKEN=$(getparam API_ACCESS_TOKEN) + + export FROM_EMAIL=$(getparam FROM_EMAIL) + export MAIL_URL=$(getparam MAIL_URL) + export MEFE_TARGET_ARN=$(getparam MEFE_TARGET_ARN) + +# Variables that are built from other variables: + + export ROOT_URL=https://case.$STAGE.$DOMAIN + export BUGZILLA_URL=https://dashboard.$STAGE.$DOMAIN + + export CLOUDINARY_API_ENDPOINT=https://api.cloudinary.com/v1_1/$CLOUDINARY_CLOUD_NAME/image/upload + # Temporary fix until issue https://github.com/Unee-T-INS/frontend/issues/15 is closed + export CLOUDINARY_URL=$CLOUDINARY_API_ENDPOINT + # END Temporary fix + + export INVITE_LAMBDA_URL=https://invite.$STAGE.$DOMAIN + export UNIT_CREATE_LAMBDA_URL=https://unit.$STAGE.$DOMAIN/create + export APIENROLL_LAMBDA_URL=https://apienroll.$STAGE.$DOMAIN + export PDFGEN_LAMBDA_URL=https://pdfgen.$STAGE.$DOMAIN + export PDFCONVERT_LAMBDA_URL=https://prince.$STAGE.$DOMAIN \ No newline at end of file diff --git a/aws-env.dev b/aws-env.dev index 8a8c2627..17f49a97 100644 --- a/aws-env.dev +++ b/aws-env.dev @@ -14,20 +14,21 @@ aws --profile ${TRAVIS_PROFILE} ssm get-parameters --names "$1" --with-decryption --query Parameters[0].Value --output text } -# We prepare the hardcoded variables that we will need to deploy what's needed - -export STAGE=dev - # Variables that are maintained in the AWS parameter store for the environment: export DOMAIN=$(getparam DOMAIN) export BUGZILLA_ADMIN_KEY=$(getparam BUGZILLA_ADMIN_KEY) + export STAGE=$(getparam STAGE) + export MONGO_MASTER_USERNAME=$(getparam MONGO_MASTER_USERNAME) export MONGO_MASTER_PASSWORD=$(getparam MONGO_MASTER_PASSWORD) export MONGO_CONNECT=$(getparam MONGO_CONNECT) + + export CLOUDINARY_CLOUD_NAME=$(getparam CLOUDINARY_CLOUD_NAME) export CLOUDINARY_PRESET=$(getparam CLOUDINARY_PRESET) - export CLOUDINARY_URL=$(getparam CLOUDINARY_URL) + export API_ACCESS_TOKEN=$(getparam API_ACCESS_TOKEN) + export FROM_EMAIL=$(getparam FROM_EMAIL) export MAIL_URL=$(getparam MAIL_URL) export MEFE_TARGET_ARN=$(getparam MEFE_TARGET_ARN) @@ -36,6 +37,12 @@ export STAGE=dev export ROOT_URL=https://case.$STAGE.$DOMAIN export BUGZILLA_URL=https://dashboard.$STAGE.$DOMAIN + + export CLOUDINARY_API_ENDPOINT=https://api.cloudinary.com/v1_1/$CLOUDINARY_CLOUD_NAME/image/upload + # Temporary fix until issue https://github.com/Unee-T-INS/frontend/issues/15 is closed + export CLOUDINARY_URL=$CLOUDINARY_API_ENDPOINT + # END Temporary fix + export INVITE_LAMBDA_URL=https://invite.$STAGE.$DOMAIN export UNIT_CREATE_LAMBDA_URL=https://unit.$STAGE.$DOMAIN/create export APIENROLL_LAMBDA_URL=https://apienroll.$STAGE.$DOMAIN diff --git a/aws-env.prod b/aws-env.prod index 657965f0..39d38b93 100644 --- a/aws-env.prod +++ b/aws-env.prod @@ -1,16 +1,51 @@ -export ROOT_URL=https://case.unee-t.com -export BUGZILLA_ADMIN_KEY=$(aws --profile uneet-prod ssm get-parameters --names BUGZILLA_ADMIN_KEY --with-decryption --query Parameters[0].Value --output text) -export BUGZILLA_URL=https://dashboard.unee-t.com -export INVITE_LAMBDA_URL=https://invite.unee-t.com -export UNIT_CREATE_LAMBDA_URL=https://unit.unee-t.com/create -export APIENROLL_LAMBDA_URL=https://apienroll.unee-t.com -export PDFGEN_LAMBDA_URL=https://pdfgen.unee-t.com -export PDFCONVERT_LAMBDA_URL=https://prince.unee-t.com -export MONGO_PASSWORD=$(aws --profile uneet-prod ssm get-parameters --names MONGO_PASSWORD --with-decryption --query Parameters[0].Value --output text) -export MONGO_CONNECT=$(aws --profile uneet-prod ssm get-parameters --names MONGO_CONNECT --query Parameters[0].Value --output text) -export CLOUDINARY_PRESET=$(aws --profile uneet-prod ssm get-parameters --names CLOUDINARY_PRESET --with-decryption --query Parameters[0].Value --output text) -export CLOUDINARY_URL=$(aws --profile uneet-prod ssm get-parameters --names CLOUDINARY_URL --with-decryption --query Parameters[0].Value --output text) -export API_ACCESS_TOKEN=$(aws --profile uneet-prod ssm get-parameters --names API_ACCESS_TOKEN --with-decryption --query Parameters[0].Value --output text) -export FROM_EMAIL=$(aws --profile uneet-prod ssm get-parameters --names FROM_EMAIL --query Parameters[0].Value --output text) -export MAIL_URL=$(aws --profile uneet-prod ssm get-parameters --names MAIL_URL --with-decryption --query Parameters[0].Value --output text) -export DOMAIN=unee-t.com +#!/bin/bash +### This file stores all environment variables for the DEV environment for this repo + +# This script is called as part of the Travis CI deployment routine +# We can use the default aws profile configured in Travis CI settings to get the variables we need + +# We create a procedure to retrieve the variables from the AWS parameter store +# Make sure to +# - configure your AWS CLI accordingly +# - update the profile you need to use to access these variables if needed +# - PROFILE is set when .travis.yml run + + getparam () { + aws --profile ${TRAVIS_PROFILE} ssm get-parameters --names "$1" --with-decryption --query Parameters[0].Value --output text + } + +# Variables that are maintained in the AWS parameter store for the environment: + + export DOMAIN=$(getparam DOMAIN) + export BUGZILLA_ADMIN_KEY=$(getparam BUGZILLA_ADMIN_KEY) + export STAGE=$(getparam STAGE) + + export MONGO_MASTER_USERNAME=$(getparam MONGO_MASTER_USERNAME) + export MONGO_MASTER_PASSWORD=$(getparam MONGO_MASTER_PASSWORD) + export MONGO_CONNECT=$(getparam MONGO_CONNECT) + + export CLOUDINARY_CLOUD_NAME=$(getparam CLOUDINARY_CLOUD_NAME) + export CLOUDINARY_PRESET=$(getparam CLOUDINARY_PRESET) + + export API_ACCESS_TOKEN=$(getparam API_ACCESS_TOKEN) + + export FROM_EMAIL=$(getparam FROM_EMAIL) + export MAIL_URL=$(getparam MAIL_URL) + export MEFE_TARGET_ARN=$(getparam MEFE_TARGET_ARN) + +# Variables that are built from other variables: + + export ROOT_URL=https://case.$DOMAIN + export BUGZILLA_URL=https://dashboard.$DOMAIN + + export CLOUDINARY_API_ENDPOINT=https://api.cloudinary.com/v1_1/$CLOUDINARY_CLOUD_NAME/image/upload + # Temporary fix until issue https://github.com/Unee-T-INS/frontend/issues/15 is closed + export CLOUDINARY_URL=$CLOUDINARY_API_ENDPOINT + # END Temporary fix + + export INVITE_LAMBDA_URL=https://invite.$DOMAIN + export UNIT_CREATE_LAMBDA_URL=https://unit.$DOMAIN/create + export APIENROLL_LAMBDA_URL=https://apienroll.$DOMAIN + export PDFGEN_LAMBDA_URL=https://pdfgen.$DOMAIN + export PDFCONVERT_LAMBDA_URL=https://prince.$DOMAIN + \ No newline at end of file diff --git a/env-setup.bash b/env-setup.bash index 19467b10..282e2790 100755 --- a/env-setup.bash +++ b/env-setup.bash @@ -21,12 +21,12 @@ EOF cat << EOF > .env BUGZILLA_ADMIN_KEY=$(ssm BUGZILLA_ADMIN_KEY) MAIL_URL=smtps://$(ssm SES_SMTP_USERNAME):$(ssm SES_SMTP_PASSWORD)@email-smtp.us-west-2.amazonaws.com:465 -CLOUDINARY_URL=https://api.cloudinary.com/v1_1/unee-t-staging/image/upload +CLOUDINARY_API_ENDPOINT=https://api.cloudinary.com/v1_1/unee-t-staging/image/upload CLOUDINARY_PRESET=$(ssm CLOUDINARY_PRESET) API_ACCESS_TOKEN=$(ssm API_ACCESS_TOKEN) FROM_EMAIL="Local Unee-T Case " -STAGE=dev -DOMAIN=unee-t.com +STAGE=$(ssm STAGE) +DOMAIN=$(ssm DOMAIN) PDFGEN_LAMBDA_URL=https://pdfgen.dev.unee-t.com PDFCONVERT_LAMBDA_URL=https://prince.dev.unee-t.com EOF diff --git a/imports/state/epics/base/file-upload-processor.js b/imports/state/epics/base/file-upload-processor.js index fd3f2640..66f6aaf7 100644 --- a/imports/state/epics/base/file-upload-processor.js +++ b/imports/state/epics/base/file-upload-processor.js @@ -26,7 +26,7 @@ type ActionGenerators = { } export const fileUploadProcessor = (actionType: string, actionGenerators: ActionGenerators) => (action$: Observable, store: {}, deps: { ajax: (opts: {}) => Observable }) => { - const { CLOUDINARY_URL, CLOUDINARY_PRESET } = Meteor.settings.public + const { CLOUDINARY_API_ENDPOINT, CLOUDINARY_PRESET } = Meteor.settings.public // Creating a stream to publish upload progress actions const buildProgressStream = (action: T) => { @@ -44,7 +44,7 @@ export const fileUploadProcessor = (actionType: string, actionGe formData.append('upload_preset', CLOUDINARY_PRESET) return deps.ajax({ - url: CLOUDINARY_URL, + url: CLOUDINARY_API_ENDPOINT, responseType: 'json', method: 'POST', body: formData, diff --git a/imports/state/epics/create-attachment.test.js b/imports/state/epics/create-attachment.test.js index cb94704a..7121a374 100644 --- a/imports/state/epics/create-attachment.test.js +++ b/imports/state/epics/create-attachment.test.js @@ -18,7 +18,7 @@ import { Subject } from 'rxjs/Subject' if (Meteor.isClient) { describe('CreateAttachment epic', () => { let input, output, nextSpy, ajaxStub, ajaxStream, clock, initialPublicSettings - const CLOUDINARY_URL = 'https://api.cloudinary.com/v1_1/demo-env/image/upload' + const CLOUDINARY_API_ENDPOINT = 'https://api.cloudinary.com/v1_1/demo-env/image/upload' const CLOUDINARY_PRESET = 'asddsd23asd' const inputAction = { type: CREATE_ATTACHMENT, @@ -34,7 +34,7 @@ if (Meteor.isClient) { clock = sinon.useFakeTimers() initialPublicSettings = Meteor.settings.public Meteor.settings.public = { - CLOUDINARY_URL, + CLOUDINARY_API_ENDPOINT, CLOUDINARY_PRESET } }) @@ -125,7 +125,7 @@ if (Meteor.isClient) { output.subscribe(nextSpy, null, () => { // Asserting proper ajax request execution expect(ajaxStub).to.have.been.calledWithMatch({ - url: CLOUDINARY_URL, + url: CLOUDINARY_API_ENDPOINT, responseType: 'json', method: 'POST', body: sinon.match.any, diff --git a/imports/ui/case/case-messages.test.js b/imports/ui/case/case-messages.test.js index 16d7562a..ae5b9831 100644 --- a/imports/ui/case/case-messages.test.js +++ b/imports/ui/case/case-messages.test.js @@ -32,7 +32,7 @@ if (Meteor.isClient) { before(() => { initialPublicSettings = Meteor.settings.public Meteor.settings.public = { - CLOUDINARY_URL: 'https://api.cloudinary.com/v1_1/demo-env/image/upload', + CLOUDINARY_API_ENDPOINT: 'https://api.cloudinary.com/v1_1/demo-env/image/upload', CLOUDINARY_PRESET: 'asddsd23asd' } return Promise.all([import('./case-messages.jsx'), import('./case.mss')]).then(([module, stylesModule]) => { diff --git a/imports/util/matchers.js b/imports/util/matchers.js index 7a629476..d0832f0c 100644 --- a/imports/util/matchers.js +++ b/imports/util/matchers.js @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor' export const attachmentTextMatcher = text => { - const cloudinaryDownloadUrl = Meteor.settings.public.CLOUDINARY_URL.replace('/api.', '/res.').replace(/\/v1_1(\/[^/]+\/).*/, '$1') + const cloudinaryDownloadUrl = Meteor.settings.public.CLOUDINARY_API_ENDPOINT.replace('/api.', '/res.').replace(/\/v1_1(\/[^/]+\/).*/, '$1') const attachmentRegexStr = '^\\[!attachment\\(([a-zA-Z]+)\\)\\]\\n' const previewPrefixRegex = new RegExp(attachmentRegexStr + 'data:') const blobPrefixRegex = new RegExp(attachmentRegexStr + 'blob:') diff --git a/server/main.js b/server/main.js index 67a8cb00..03b57a96 100644 --- a/server/main.js +++ b/server/main.js @@ -24,7 +24,7 @@ import '../imports/server/auth/otp-authenticator' import '../imports/config/email' import '../imports/migrations' -const publicClientEnvVars = ['CLOUDINARY_URL', 'CLOUDINARY_PRESET'] +const publicClientEnvVars = ['CLOUDINARY_API_ENDPOINT', 'CLOUDINARY_PRESET'] Object.assign(Meteor.settings.public, publicClientEnvVars.reduce((obj, key) => { obj[key] = process.env[key] return obj From 080ef434eb1741845932c1c1fb0a901ae63a62ec Mon Sep 17 00:00:00 2001 From: Franck <31331637+franck-boullier@users.noreply.github.com> Date: Wed, 22 Jan 2020 15:42:57 +0800 Subject: [PATCH 12/46] Force deployment with Travis This is related to issue #17: we need to use redeploy and use the correct value for the AWS variable `CLOUDINARY_CLOUD_NAME` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4fcf8188..a958a0b1 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Overview * [How to test with Bugzilla in a local environment](https://unee-t-media.s3-accelerate.amazonaws.com/frontend/MEFE.mp4) -* [ECS deploy](https://unee-t-media.s3-accelerate.amazonaws.com/2017/ecs-deploy.mp4) with `./deploy.sh` +* [ECS deploy](https://unee-t-media.s3-accelerate.amazonaws.com/2017/ecs-deploy.mp4) with `./deploy.sh`. # Demo - How to see how it works: From c6a852d7eb6b0b6181a935eabc3f6ad967c441c6 Mon Sep 17 00:00:00 2001 From: franck Date: Tue, 28 Jan 2020 10:48:11 +0800 Subject: [PATCH 13/46] quickfix for issue #18 --- aws-env.demo | 2 +- aws-env.dev | 2 +- aws-env.prod | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/aws-env.demo b/aws-env.demo index ad226733..22fe2e53 100644 --- a/aws-env.demo +++ b/aws-env.demo @@ -38,7 +38,7 @@ export ROOT_URL=https://case.$STAGE.$DOMAIN export BUGZILLA_URL=https://dashboard.$STAGE.$DOMAIN - export CLOUDINARY_API_ENDPOINT=https://api.cloudinary.com/v1_1/$CLOUDINARY_CLOUD_NAME/image/upload + export CLOUDINARY_API_ENDPOINT=https://api.cloudinary.com/v1_1/$CLOUDINARY_CLOUD_NAME/auto/upload # Temporary fix until issue https://github.com/Unee-T-INS/frontend/issues/15 is closed export CLOUDINARY_URL=$CLOUDINARY_API_ENDPOINT # END Temporary fix diff --git a/aws-env.dev b/aws-env.dev index 17f49a97..faf677b2 100644 --- a/aws-env.dev +++ b/aws-env.dev @@ -38,7 +38,7 @@ export ROOT_URL=https://case.$STAGE.$DOMAIN export BUGZILLA_URL=https://dashboard.$STAGE.$DOMAIN - export CLOUDINARY_API_ENDPOINT=https://api.cloudinary.com/v1_1/$CLOUDINARY_CLOUD_NAME/image/upload + export CLOUDINARY_API_ENDPOINT=https://api.cloudinary.com/v1_1/$CLOUDINARY_CLOUD_NAME/auto/upload # Temporary fix until issue https://github.com/Unee-T-INS/frontend/issues/15 is closed export CLOUDINARY_URL=$CLOUDINARY_API_ENDPOINT # END Temporary fix diff --git a/aws-env.prod b/aws-env.prod index 39d38b93..064773a2 100644 --- a/aws-env.prod +++ b/aws-env.prod @@ -38,7 +38,7 @@ export ROOT_URL=https://case.$DOMAIN export BUGZILLA_URL=https://dashboard.$DOMAIN - export CLOUDINARY_API_ENDPOINT=https://api.cloudinary.com/v1_1/$CLOUDINARY_CLOUD_NAME/image/upload + export CLOUDINARY_API_ENDPOINT=https://api.cloudinary.com/v1_1/$CLOUDINARY_CLOUD_NAME/auto/upload # Temporary fix until issue https://github.com/Unee-T-INS/frontend/issues/15 is closed export CLOUDINARY_URL=$CLOUDINARY_API_ENDPOINT # END Temporary fix From 3e1d656fb31617c5316a5917052f54a394265def Mon Sep 17 00:00:00 2001 From: franck Date: Thu, 6 Feb 2020 20:43:47 +0800 Subject: [PATCH 14/46] WIP - review the changes made to `.travis.yml` --- .travis.yml | 50 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9e9b1af4..85502ac1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,10 +24,13 @@ # Case 2: Created when Travis CI runs # - IMAGE_TAG -# language: node_js -# node_js: -# - lts/* +language: node_js + +node_js: + - lts/* + language: generic + services: - docker @@ -48,19 +51,19 @@ before_install: https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest && chmod +x $HOME/.local/bin/ecs-cli -# cache: -# directories: -# - node_modules +cache: + directories: + - node_modules install: - # - meteor npm install - # #Adding script build docker image + - meteor npm install + #Adding script build docker image - docker build -t $DOCKER_CI_REPO_NAME . -# script: -# - npm t +script: + - npm t -# #Adding script deploy docker image to docker repository +#Adding script deploy docker image to docker repository after_success: - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"; @@ -71,21 +74,16 @@ after_success: matrix: include: - # add deploy stage for dev - - env: DEPLOY=dev - if: branch = master - deploy: - provider: script - # We need to set variables that are comming from travis ci setting - # Variables: - # - DOCKER_CI_REPO_NAME - # - AWS_PROFILE_DEV - # - AWS_ACCOUNT_USER_ID_DEV - # - AWS_ACCOUNT_SECRET_DEV - # - AWS_DEFAULT_REGION - script: TRAVIS_DOCKER_REPO_NAME=$DOCKER_CI_REPO_NAME TRAVIS_PROFILE=$AWS_PROFILE_DEV TRAVIS_AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_DEV TRAVIS_AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_DEV TRAVIS_AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION ./deploy.sh -d - on: - branch: master + # For DEV, we are using AWS Codebuild for the deployment (NOT TRAVIS) + # This will need to be evaluated going forward but for now we continue like this... + # We comment out the DEV option +# - env: DEPLOY=dev +# if: branch = master +# deploy: +# provider: script +# script: TRAVIS_DOCKER_REPO_NAME=$DOCKER_CI_REPO_NAME TRAVIS_PROFILE=$AWS_PROFILE_DEV TRAVIS_AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_DEV TRAVIS_AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_DEV TRAVIS_AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION ./deploy.sh -d +# on: +# branch: master - env: DEPLOY=demo if: tag IS present deploy: From ad2ed71c41fab12b27ff5b837e3938ae4935135c Mon Sep 17 00:00:00 2001 From: franck Date: Thu, 6 Feb 2020 20:49:41 +0800 Subject: [PATCH 15/46] WIP - review the changes made to `AWS-docker-compose.yml` --- AWS-docker-compose.yml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/AWS-docker-compose.yml b/AWS-docker-compose.yml index bb3176e7..48e2c21e 100644 --- a/AWS-docker-compose.yml +++ b/AWS-docker-compose.yml @@ -28,7 +28,10 @@ version: '2' services: meteor: - image: ${TRAVIS_DOCKER_REPO_NAME}:latest + # INS change commented out - revert to previous version of the master + image: uneet/frontend:$COMMIT + # image: ${TRAVIS_DOCKER_REPO_NAME}:latest + # END INS change commented out - revert mem_reservation: 1g mem_limit: 2g ports: @@ -37,9 +40,15 @@ services: - ROOT_URL=${ROOT_URL} - BUGZILLA_URL=${BUGZILLA_URL} - BUGZILLA_ADMIN_KEY=${BUGZILLA_ADMIN_KEY} - - MONGO_URL=mongodb+srv://${MONGO_MASTER_USERNAME}:${MONGO_MASTER_PASSWORD}@${MONGO_CONNECT} + # INS change commented out - revert to previous version of the master + - MONGO_URL=mongodb://root:${MONGO_PASSWORD}@${MONGO_CONNECT} + #- MONGO_URL=mongodb+srv://${MONGO_MASTER_USERNAME}:${MONGO_MASTER_PASSWORD}@${MONGO_CONNECT} + # END INS change commented out - revert - CLOUDINARY_API_ENDPOINT=${CLOUDINARY_API_ENDPOINT} - CLOUDINARY_PRESET=${CLOUDINARY_PRESET} + # This was deleted - revert to previous version of the master + - COMMIT=${COMMIT} + # END This was deleted - revert to previous version of the master - API_ACCESS_TOKEN=${API_ACCESS_TOKEN} - FROM_EMAIL=${FROM_EMAIL} - MAIL_URL=${MAIL_URL} @@ -53,6 +62,6 @@ services: logging: driver: awslogs options: - awslogs-region: ${TRAVIS_AWS_DEFAULT_REGION} - awslogs-group: meteor + awslogs-region: ${TRAVIS_AWS_DEFAULT_REGION} + awslogs-group: meteor awslogs-stream-prefix: ecs From 575dbca401c9c67a2a6dbef45d001cd6279c4a6e Mon Sep 17 00:00:00 2001 From: franck Date: Thu, 6 Feb 2020 20:55:53 +0800 Subject: [PATCH 16/46] WIP - review the changes made to `aws-env.dev` --- aws-env.dev | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/aws-env.dev b/aws-env.dev index faf677b2..280e53fc 100644 --- a/aws-env.dev +++ b/aws-env.dev @@ -21,10 +21,14 @@ export STAGE=$(getparam STAGE) export MONGO_MASTER_USERNAME=$(getparam MONGO_MASTER_USERNAME) + # REVIEW - In previous version this was named `MONGO_PASSWORD` export MONGO_MASTER_PASSWORD=$(getparam MONGO_MASTER_PASSWORD) + # END - REVIEW export MONGO_CONNECT=$(getparam MONGO_CONNECT) + # REVIEW - In previous version this was named `CLOUDINARY_URL` export CLOUDINARY_CLOUD_NAME=$(getparam CLOUDINARY_CLOUD_NAME) + # END - REVIEW export CLOUDINARY_PRESET=$(getparam CLOUDINARY_PRESET) export API_ACCESS_TOKEN=$(getparam API_ACCESS_TOKEN) From ee25aa0175160783d1f55b8351eb8fe48246e043 Mon Sep 17 00:00:00 2001 From: franck Date: Thu, 6 Feb 2020 20:59:44 +0800 Subject: [PATCH 17/46] use the correct AWS profile `uneet-STAGE` --- backup/connect.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backup/connect.sh b/backup/connect.sh index de4741ae..8918b1c4 100755 --- a/backup/connect.sh +++ b/backup/connect.sh @@ -31,7 +31,7 @@ do ;; esac done -AWS_PROFILE=ins-$STAGE +AWS_PROFILE=uneet-$STAGE shift "$((OPTIND-1))" # Discard the options and sentinel -- getparam () { From 93681d525d56547ad57b0e17442913368d82e092 Mon Sep 17 00:00:00 2001 From: franck Date: Thu, 6 Feb 2020 21:07:31 +0800 Subject: [PATCH 18/46] ud `d` for `demo` to deploy (we will use `s` for `staging` for DEV in the future`) --- .travis.yml | 2 +- deploy.sh | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 85502ac1..29bc7c17 100644 --- a/.travis.yml +++ b/.travis.yml @@ -88,7 +88,7 @@ matrix: if: tag IS present deploy: provider: script - script: PROFILE=$AWS_PROFILE_DEMO AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_DEMO AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_DEMO AWS_REGION=$AWS_DEFAULT_REGION ./deploy.sh -s + script: PROFILE=$AWS_PROFILE_DEMO AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_DEMO AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_DEMO AWS_REGION=$AWS_DEFAULT_REGION ./deploy.sh -d on: tags: true - env: DEPLOY=prod diff --git a/deploy.sh b/deploy.sh index c7a51a2c..8166b0a3 100755 --- a/deploy.sh +++ b/deploy.sh @@ -21,16 +21,18 @@ while getopts "pd" opt do case $opt in #Add option d for development - d) - echo "DEVELOPMENT" >&2 - STAGE=dev - ;; + # For DEV, we are using AWS Codebuild for the deployment (NOT TRAVIS) + # This will need to be evaluated going forward but for now we continue like this... + # We comment out the DEV option + # d) + # echo "DEVELOPMENT" >&2 + # STAGE=dev + # ;; p) echo "PRODUCTION" >&2 STAGE=prod ;; - #Change option demo from d to s - s) + d) echo "DEMO" >&2 STAGE=demo ;; From 82fe2241105ce246ef13db6d3ee8095630297c96 Mon Sep 17 00:00:00 2001 From: franck Date: Thu, 6 Feb 2020 21:11:59 +0800 Subject: [PATCH 19/46] WIP - review the changes made to `deploy.sh` --- deploy.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/deploy.sh b/deploy.sh index 8166b0a3..f8294c11 100755 --- a/deploy.sh +++ b/deploy.sh @@ -43,6 +43,10 @@ do esac done +# This was deleted - revert to previous version of the master +AWS_PROFILE=uneet-$STAGE +# END This was deleted - revert + shift "$((OPTIND-1))" # Discard the options and sentinel -- export COMMIT=$(git rev-parse --short HEAD) @@ -79,7 +83,7 @@ else ecs-cli -version fi -ecs-cli configure --cluster master --region $TRAVIS_AWS_DEFAULT_REGION +ecs-cli configure --cluster master --region $TRAVIS_AWS_DEFAULT_REGION --compose-service-name-prefix ecscompose-service- test -f aws-env.$STAGE && source aws-env.$STAGE service=$(grep -A1 services AWS-docker-compose.yml | tail -n1 | tr -cd '[[:alnum:]]') From 93deb1e2dd893fb479eabc36f8fa97bc85ef5d89 Mon Sep 17 00:00:00 2001 From: franck Date: Thu, 6 Feb 2020 21:14:12 +0800 Subject: [PATCH 20/46] WIP - review the changes made to `env-setup.bash` --- env-setup.bash | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/env-setup.bash b/env-setup.bash index 282e2790..4eeb039f 100755 --- a/env-setup.bash +++ b/env-setup.bash @@ -25,8 +25,12 @@ CLOUDINARY_API_ENDPOINT=https://api.cloudinary.com/v1_1/unee-t-staging/image/upl CLOUDINARY_PRESET=$(ssm CLOUDINARY_PRESET) API_ACCESS_TOKEN=$(ssm API_ACCESS_TOKEN) FROM_EMAIL="Local Unee-T Case " -STAGE=$(ssm STAGE) -DOMAIN=$(ssm DOMAIN) +# INS change commented out - revert to previous version of the master +STAGE=dev +DOMAIN=unee-t.com +#STAGE=$(ssm STAGE) +#DOMAIN=$(ssm DOMAIN) +#END INS change commented out - revert to previous version of the master PDFGEN_LAMBDA_URL=https://pdfgen.dev.unee-t.com PDFCONVERT_LAMBDA_URL=https://prince.dev.unee-t.com EOF From a0f228e18a239b5e044c8b71bd407d7a44d4cb80 Mon Sep 17 00:00:00 2001 From: franck Date: Thu, 6 Feb 2020 21:30:22 +0800 Subject: [PATCH 21/46] make sure we can connect to older version of Mongo/Atlas --- aws-env.dev | 2 ++ backup/connect.sh | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/aws-env.dev b/aws-env.dev index 280e53fc..b53a3037 100644 --- a/aws-env.dev +++ b/aws-env.dev @@ -22,6 +22,8 @@ export MONGO_MASTER_USERNAME=$(getparam MONGO_MASTER_USERNAME) # REVIEW - In previous version this was named `MONGO_PASSWORD` + # We need the old version so we can still connect to Mongo + export MONGO_PASSWORD=$(getparam MONGO_PASSWORD) export MONGO_MASTER_PASSWORD=$(getparam MONGO_MASTER_PASSWORD) # END - REVIEW export MONGO_CONNECT=$(getparam MONGO_CONNECT) diff --git a/backup/connect.sh b/backup/connect.sh index 8918b1c4..982d6e04 100755 --- a/backup/connect.sh +++ b/backup/connect.sh @@ -34,8 +34,21 @@ done AWS_PROFILE=uneet-$STAGE shift "$((OPTIND-1))" # Discard the options and sentinel -- -getparam () { - aws --profile ins-${STAGE} ssm get-parameters --names "$1" --with-decryption --query Parameters[0].Value --output text -} -mongo "mongodb+srv://$(getparam MONGO_MASTER_USERNAME):$(getparam MONGO_MASTER_PASSWORD)@$(getparam MONGO_CONNECT)" +# REVIEW AND REVERT +# In previous version we were connection to the Mongo like this (older version) +# OLD CODE +MONGO_PASSWORD=$(aws --profile $AWS_PROFILE ssm get-parameters --names MONGO_PASSWORD --with-decryption --query Parameters[0].Value --output text) +MONGO_CONNECT=$(aws --profile $AWS_PROFILE ssm get-parameters --names MONGO_CONNECT --query Parameters[0].Value --output text) +mongo "mongodb://root:$MONGO_PASSWORD@$MONGO_CONNECT" +# END OLD CODE +# NEW CODE + +#getparam () { +# aws --profile ins-${STAGE} ssm get-parameters --names "$1" --with-decryption --query Parameters[0].Value --output text +#} +# +#mongo "mongodb+srv://$(getparam MONGO_MASTER_USERNAME):$(getparam MONGO_MASTER_PASSWORD)@$(getparam MONGO_CONNECT)" + +# END NEW CODE +# END REVIEW AND REVERT From 68681fa2118f0de90e8adc614b52dac387300a5e Mon Sep 17 00:00:00 2001 From: franck Date: Thu, 6 Feb 2020 21:34:36 +0800 Subject: [PATCH 22/46] make sure we only deploy on Master --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 29bc7c17..c753af25 100644 --- a/.travis.yml +++ b/.travis.yml @@ -90,6 +90,7 @@ matrix: provider: script script: PROFILE=$AWS_PROFILE_DEMO AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_DEMO AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_DEMO AWS_REGION=$AWS_DEFAULT_REGION ./deploy.sh -d on: + branch: master tags: true - env: DEPLOY=prod if: tag IS present @@ -97,4 +98,5 @@ matrix: provider: script script: PROFILE=$AWS_PROFILE_PROD AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_PROD AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_PROD AWS_REGION=$AWS_DEFAULT_REGION ./deploy.sh -p && AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_PROD AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_PROD aws cloudfront create-invalidation --distribution-id E173XT6X8V4A18 --paths '/*' on: + branch: master tags: true \ No newline at end of file From 4001723aa88e4cd483e5584866e9b055c66b929d Mon Sep 17 00:00:00 2001 From: franck Date: Thu, 6 Feb 2020 21:53:14 +0800 Subject: [PATCH 23/46] update Node from 8 to 12 --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index e456dd4d..1fc2956e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:8 AS builder +FROM node:12 AS builder RUN curl -sL https://install.meteor.com | sed s/--progress-bar/-sL/g | /bin/sh RUN mkdir /src /bundle @@ -13,7 +13,7 @@ RUN meteor npm install RUN meteor build --architecture os.linux.x86_64 --directory /bundle RUN cd /bundle/bundle/programs/server && npm install -FROM node:8-slim +FROM node:12-slim USER node:node From acba07f9b7771a9f970dd55286fb0603546c62d3 Mon Sep 17 00:00:00 2001 From: franck Date: Thu, 6 Feb 2020 22:12:29 +0800 Subject: [PATCH 24/46] do not let Travis CI build the Docker image on each PR or branch --- .travis.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index c753af25..9b08ab6e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,7 +58,7 @@ cache: install: - meteor npm install #Adding script build docker image - - docker build -t $DOCKER_CI_REPO_NAME . +# - docker build -t $DOCKER_CI_REPO_NAME . script: - npm t @@ -66,11 +66,11 @@ script: #Adding script deploy docker image to docker repository after_success: - - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"; - - docker build -t $DOCKER_CI_REPO_NAME:latest . - - docker tag $DOCKER_CI_REPO_NAME:latest $DOCKER_CI_REPO_NAME:$IMAGE_TAG - - docker push $DOCKER_CI_REPO_NAME:latest - - docker push $DOCKER_CI_REPO_NAME:$IMAGE_TAG +# - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"; +# - docker build -t $DOCKER_CI_REPO_NAME:latest . +# - docker tag $DOCKER_CI_REPO_NAME:latest $DOCKER_CI_REPO_NAME:$IMAGE_TAG +# - docker push $DOCKER_CI_REPO_NAME:latest +# - docker push $DOCKER_CI_REPO_NAME:$IMAGE_TAG matrix: include: From 5f4dbadf0397dc71156a534cef2157ce8a62846a Mon Sep 17 00:00:00 2001 From: franck Date: Thu, 6 Feb 2020 22:27:46 +0800 Subject: [PATCH 25/46] fix linting and make it closer to older version --- .travis.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9b08ab6e..72888b9e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,12 +27,10 @@ language: node_js node_js: - - lts/* + - lts/* -language: generic - -services: - - docker +#services: +# - docker env: global: From 05a474466e9e83b8f72af5d94709c45026d72ec2 Mon Sep 17 00:00:00 2001 From: franck Date: Thu, 6 Feb 2020 22:30:27 +0800 Subject: [PATCH 26/46] fix issue - missing line --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 72888b9e..844e609d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -72,6 +72,7 @@ after_success: matrix: include: + - env: DEPLOY=none # For DEV, we are using AWS Codebuild for the deployment (NOT TRAVIS) # This will need to be evaluated going forward but for now we continue like this... # We comment out the DEV option From 3bd4e8bc0c2d4c8153fba63c14e8725d5fa8b245 Mon Sep 17 00:00:00 2001 From: franck Date: Thu, 6 Feb 2020 22:42:00 +0800 Subject: [PATCH 27/46] Use native implementation of bcrypt for better performances --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 844e609d..c6583c8f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -55,6 +55,8 @@ cache: install: - meteor npm install + # Use native implementation of bcrypt for better performances + - meteor npm install --save bcrypt #Adding script build docker image # - docker build -t $DOCKER_CI_REPO_NAME . From ba2f4193db1e9ded31b03ab8ce2922f09cec9e00 Mon Sep 17 00:00:00 2001 From: franck Date: Thu, 6 Feb 2020 22:44:40 +0800 Subject: [PATCH 28/46] Use native implementation of bcrypt for better performances --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 1fc2956e..3ac0c2a6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,8 @@ WORKDIR /src COPY --chown=node:node . . RUN meteor npm install +# Use native implementation of bcrypt for better performances +RUN meteor npm install --save bcrypt RUN meteor build --architecture os.linux.x86_64 --directory /bundle RUN cd /bundle/bundle/programs/server && npm install From 3346d3d57e251ea7667ce7c5ce132b9f2f2fde85 Mon Sep 17 00:00:00 2001 From: franck Date: Fri, 7 Feb 2020 10:34:05 +0800 Subject: [PATCH 29/46] make sure we build the latest version of the Docker image if Travis Tests are OK --- .travis.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index c6583c8f..aab665c3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,8 +57,6 @@ install: - meteor npm install # Use native implementation of bcrypt for better performances - meteor npm install --save bcrypt - #Adding script build docker image -# - docker build -t $DOCKER_CI_REPO_NAME . script: - npm t @@ -66,18 +64,23 @@ script: #Adding script deploy docker image to docker repository after_success: -# - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"; -# - docker build -t $DOCKER_CI_REPO_NAME:latest . -# - docker tag $DOCKER_CI_REPO_NAME:latest $DOCKER_CI_REPO_NAME:$IMAGE_TAG -# - docker push $DOCKER_CI_REPO_NAME:latest -# - docker push $DOCKER_CI_REPO_NAME:$IMAGE_TAG + # If we have passed the Travis CI Test, we need to build the latest version of the Docker image + # This latest version is the version that will be used when we will deploy in our environments (DEV, DEMO, PROD) + # TODO: See https://github.com/unee-t/frontend/issues/893 + - echo "START - We are building the `latest` version of the Docker image we need for deployment" + - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"; + - docker build -t $DOCKER_CI_REPO_NAME:latest . + - docker tag $DOCKER_CI_REPO_NAME:latest $DOCKER_CI_REPO_NAME:$IMAGE_TAG + - docker push $DOCKER_CI_REPO_NAME:latest + - docker push $DOCKER_CI_REPO_NAME:$IMAGE_TAG + - echo "END - We are building the `latest` version of the Docker image we need for deployment" matrix: include: - env: DEPLOY=none # For DEV, we are using AWS Codebuild for the deployment (NOT TRAVIS) - # This will need to be evaluated going forward but for now we continue like this... # We comment out the DEV option + # This will need to be evaluated going forward (shall we revert back to TRAVIS for deployment?) # - env: DEPLOY=dev # if: branch = master # deploy: From 70fe283ecce600d6335193cc7721659820a8de11 Mon Sep 17 00:00:00 2001 From: franck Date: Fri, 7 Feb 2020 10:41:35 +0800 Subject: [PATCH 30/46] remove ` from echo <-- causes weird behavior and should have been escaped --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index aab665c3..d4f1c79d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -67,7 +67,7 @@ after_success: # If we have passed the Travis CI Test, we need to build the latest version of the Docker image # This latest version is the version that will be used when we will deploy in our environments (DEV, DEMO, PROD) # TODO: See https://github.com/unee-t/frontend/issues/893 - - echo "START - We are building the `latest` version of the Docker image we need for deployment" + - echo "START - We are building the latest version of the Docker image we need for deployment" - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"; - docker build -t $DOCKER_CI_REPO_NAME:latest . - docker tag $DOCKER_CI_REPO_NAME:latest $DOCKER_CI_REPO_NAME:$IMAGE_TAG From 8764b032a0b9eafbe325b049a047397f12378f2a Mon Sep 17 00:00:00 2001 From: franck Date: Fri, 7 Feb 2020 10:54:39 +0800 Subject: [PATCH 31/46] no need for AWS Codebuild to replace latest Docker image in DockerHub --- .travis.yml | 2 +- buildspec.yml | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index d4f1c79d..64d3ed48 100644 --- a/.travis.yml +++ b/.travis.yml @@ -73,7 +73,7 @@ after_success: - docker tag $DOCKER_CI_REPO_NAME:latest $DOCKER_CI_REPO_NAME:$IMAGE_TAG - docker push $DOCKER_CI_REPO_NAME:latest - docker push $DOCKER_CI_REPO_NAME:$IMAGE_TAG - - echo "END - We are building the `latest` version of the Docker image we need for deployment" + - echo "END - We are building the latest version of the Docker image we need for deployment" matrix: include: diff --git a/buildspec.yml b/buildspec.yml index fbef95e1..e1edd75e 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -15,6 +15,7 @@ phases: - echo Logging into Docker Hub... - docker login --username $DOCKER_USERNAME --password $DOCKER_PASSWORD - IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7) + - echo image that we are using is $IMAGE_TAG install: runtime-versions: @@ -24,6 +25,9 @@ phases: commands: - echo Build starting on `date` - echo Build the Docker image... + - echo We are using the docker image available at $IMAGE_REPO_NAME + - echo image that we are using is $IMAGE_TAG + - echo we are using the latest build for that image for deployment - 'sed -i "s,<\!-- COMMIT: -->,<\!-- COMMIT: $CODEBUILD_RESOLVED_SOURCE_VERSION -->,g" client/main.html' - docker build -t $IMAGE_REPO_NAME:latest . - docker tag $IMAGE_REPO_NAME:latest $IMAGE_REPO_NAME:$IMAGE_TAG @@ -31,10 +35,12 @@ phases: post_build: commands: - test "$CODEBUILD_BUILD_SUCCEEDING" == "1" || exit 1 - - echo Pushing build to Docker Hub... - - docker push $IMAGE_REPO_NAME:latest - - docker push $IMAGE_REPO_NAME:$IMAGE_TAG - - printf '[{"name":"%s","imageUri":"%s"}]' meteor $IMAGE_REPO_NAME:$IMAGE_TAG > $CODEBUILD_SRC_DIR/imagedefinitions.json + # START - Why do we need to push the Docker image to Docker Hub again?? + #- echo Pushing build to Docker Hub... + #- docker push $IMAGE_REPO_NAME:latest + #- docker push $IMAGE_REPO_NAME:$IMAGE_TAG + #- printf '[{"name":"%s","imageUri":"%s"}]' meteor $IMAGE_REPO_NAME:$IMAGE_TAG > $CODEBUILD_SRC_DIR/imagedefinitions.json + # END - Why do we need to push the Docker image to Docker Hub again?? artifacts: files: imagedefinitions.json From 9b418326422015dabbfb0a4d53e335a26b7af33d Mon Sep 17 00:00:00 2001 From: franck Date: Fri, 7 Feb 2020 11:29:53 +0800 Subject: [PATCH 32/46] Make sure we are uploading an image to DockerHub if needed --- .travis.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 64d3ed48..2eb2b9bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,14 +29,14 @@ language: node_js node_js: - lts/* -#services: -# - docker +services: + - docker env: global: - COMMIT=${TRAVIS_COMMIT::7} #Add IMAGE_TAG variable to build docker image - - IMAGE_TAG=${TRAVIS_COMMIT::7} + - IMAGE_TAG=${COMMIT} before_install: # Removed command as pyenv is no longer found during deploy @@ -67,13 +67,15 @@ after_success: # If we have passed the Travis CI Test, we need to build the latest version of the Docker image # This latest version is the version that will be used when we will deploy in our environments (DEV, DEMO, PROD) # TODO: See https://github.com/unee-t/frontend/issues/893 - - echo "START - We are building the latest version of the Docker image we need for deployment" + - echo START - We are building the latest version of the Docker image we need for deployment + - docker build -t $DOCKER_CI_REPO_NAME - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"; - - docker build -t $DOCKER_CI_REPO_NAME:latest . - docker tag $DOCKER_CI_REPO_NAME:latest $DOCKER_CI_REPO_NAME:$IMAGE_TAG + - echo We are pushing the latest Docker image as latest version in Dockerhub - docker push $DOCKER_CI_REPO_NAME:latest + - echo we are pushing the latest Docker image as $IMAGE_TAG version in DockerHub - docker push $DOCKER_CI_REPO_NAME:$IMAGE_TAG - - echo "END - We are building the latest version of the Docker image we need for deployment" + - echo END - We are building the latest version of the Docker image we need for deployment matrix: include: From 34cf37b0d44448f62a9a3013aa52dbd0dca3890d Mon Sep 17 00:00:00 2001 From: franck Date: Fri, 7 Feb 2020 11:40:14 +0800 Subject: [PATCH 33/46] clarify documentation --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2eb2b9bf..4459e448 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,17 +9,17 @@ #For dev environment: # - AWS_ACCOUNT_USER_ID_DEV # - AWS_ACCOUNT_SECRET_DEV - # - AWS_PROFILE_DEV <-- is this needed? + # - AWS_PROFILE_DEV #For Prod environment: # - AWS_ACCOUNT_USER_ID_PROD # - AWS_ACCOUNT_SECRET_PROD - # - AWS_PROFILE_PROD <-- is this needed? + # - AWS_PROFILE_PROD #For Demo environment: # - AWS_ACCOUNT_USER_ID_DEMO # - AWS_ACCOUNT_SECRET_DEMO - # - AWS_PROFILE_DEMO <-- is this needed? + # - AWS_PROFILE_DEMO # Case 2: Created when Travis CI runs # - IMAGE_TAG From a4fe8e8bf741f30fec0ce0fa18d0185049d4f306 Mon Sep 17 00:00:00 2001 From: franck Date: Sat, 8 Feb 2020 14:25:57 +0800 Subject: [PATCH 34/46] cherry pick from https://github.com/unee-t/frontend/pull/894 --- .travis.yml | 27 +++++++++++++++++------ buildspec.yml | 46 ---------------------------------------- buildspec.yml.deprecated | 46 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 53 deletions(-) delete mode 100644 buildspec.yml create mode 100644 buildspec.yml.deprecated diff --git a/.travis.yml b/.travis.yml index 4459e448..877cfc4f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,8 +39,6 @@ env: - IMAGE_TAG=${COMMIT} before_install: - # Removed command as pyenv is no longer found during deploy - #- pyenv global 2.7.14 # For removing SNIMissingWarning warnings - curl https://install.meteor.com | /bin/sh - export PATH="$HOME/.meteor:$PATH" - pip install --user awscli @@ -67,9 +65,9 @@ after_success: # If we have passed the Travis CI Test, we need to build the latest version of the Docker image # This latest version is the version that will be used when we will deploy in our environments (DEV, DEMO, PROD) # TODO: See https://github.com/unee-t/frontend/issues/893 - - echo START - We are building the latest version of the Docker image we need for deployment - - docker build -t $DOCKER_CI_REPO_NAME - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"; + - echo START - We are building the latest version of the Docker image we need for deployment + - docker build -t $DOCKER_CI_REPO_NAME:latest . - docker tag $DOCKER_CI_REPO_NAME:latest $DOCKER_CI_REPO_NAME:$IMAGE_TAG - echo We are pushing the latest Docker image as latest version in Dockerhub - docker push $DOCKER_CI_REPO_NAME:latest @@ -79,7 +77,18 @@ after_success: matrix: include: - - env: DEPLOY=none + - env: DEPLOY=dev + if: branch = master + deploy: + provider: script + script: TRAVIS_DOCKER_REPO_NAME=$DOCKER_CI_REPO_NAME + TRAVIS_PROFILE=$AWS_PROFILE_DEV + TRAVIS_AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_DEV + TRAVIS_AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_DEV + TRAVIS_AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION + ./deploy.sh + on: + branch: master # For DEV, we are using AWS Codebuild for the deployment (NOT TRAVIS) # We comment out the DEV option # This will need to be evaluated going forward (shall we revert back to TRAVIS for deployment?) @@ -94,7 +103,7 @@ matrix: if: tag IS present deploy: provider: script - script: PROFILE=$AWS_PROFILE_DEMO AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_DEMO AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_DEMO AWS_REGION=$AWS_DEFAULT_REGION ./deploy.sh -d + script: TRAVIS_PROFILE=$AWS_PROFILE_DEMO AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_DEMO AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_DEMO AWS_REGION=$AWS_DEFAULT_REGION ./deploy.sh -d on: branch: master tags: true @@ -102,7 +111,11 @@ matrix: if: tag IS present deploy: provider: script - script: PROFILE=$AWS_PROFILE_PROD AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_PROD AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_PROD AWS_REGION=$AWS_DEFAULT_REGION ./deploy.sh -p && AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_PROD AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_PROD aws cloudfront create-invalidation --distribution-id E173XT6X8V4A18 --paths '/*' + # TODO - Distribution-id uses a hardcoded value + # This will ONLY work for the main Unee-T installation but no other Unee-T Installation + # This is a problem we need to fix + script: TRAVIS_PROFILE=$AWS_PROFILE_PROD AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_PROD AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_PROD AWS_REGION=$AWS_DEFAULT_REGION ./deploy.sh -p && AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_PROD AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_PROD aws cloudfront create-invalidation --distribution-id E173XT6X8V4A18 --paths '/*' + # END - TODO - Distribution-id uses a hardcoded value on: branch: master tags: true \ No newline at end of file diff --git a/buildspec.yml b/buildspec.yml deleted file mode 100644 index e1edd75e..00000000 --- a/buildspec.yml +++ /dev/null @@ -1,46 +0,0 @@ -#This file is used by AWS codebuild. ---- -version: 0.2 - -env: - variables: - IMAGE_REPO_NAME: uneet/frontend - parameter-store: - DOCKER_USERNAME: DOCKER_USERNAME - DOCKER_PASSWORD: DOCKER_PASSWORD - -phases: - pre_build: - commands: - - echo Logging into Docker Hub... - - docker login --username $DOCKER_USERNAME --password $DOCKER_PASSWORD - - IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7) - - echo image that we are using is $IMAGE_TAG - - install: - runtime-versions: - docker: 18 - - build: - commands: - - echo Build starting on `date` - - echo Build the Docker image... - - echo We are using the docker image available at $IMAGE_REPO_NAME - - echo image that we are using is $IMAGE_TAG - - echo we are using the latest build for that image for deployment - - 'sed -i "s,<\!-- COMMIT: -->,<\!-- COMMIT: $CODEBUILD_RESOLVED_SOURCE_VERSION -->,g" client/main.html' - - docker build -t $IMAGE_REPO_NAME:latest . - - docker tag $IMAGE_REPO_NAME:latest $IMAGE_REPO_NAME:$IMAGE_TAG - - post_build: - commands: - - test "$CODEBUILD_BUILD_SUCCEEDING" == "1" || exit 1 - # START - Why do we need to push the Docker image to Docker Hub again?? - #- echo Pushing build to Docker Hub... - #- docker push $IMAGE_REPO_NAME:latest - #- docker push $IMAGE_REPO_NAME:$IMAGE_TAG - #- printf '[{"name":"%s","imageUri":"%s"}]' meteor $IMAGE_REPO_NAME:$IMAGE_TAG > $CODEBUILD_SRC_DIR/imagedefinitions.json - # END - Why do we need to push the Docker image to Docker Hub again?? - -artifacts: - files: imagedefinitions.json diff --git a/buildspec.yml.deprecated b/buildspec.yml.deprecated new file mode 100644 index 00000000..61b56eed --- /dev/null +++ b/buildspec.yml.deprecated @@ -0,0 +1,46 @@ +# #This file is used by AWS codebuild. +# --- +# version: 0.2 + +# env: +# variables: +# IMAGE_REPO_NAME: uneet/frontend +# parameter-store: +# DOCKER_USERNAME: DOCKER_USERNAME +# DOCKER_PASSWORD: DOCKER_PASSWORD + +# phases: +# pre_build: +# commands: +# - echo Logging into Docker Hub... +# - docker login --username $DOCKER_USERNAME --password $DOCKER_PASSWORD +# - IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7) +# - echo image that we are using is $IMAGE_TAG + +# install: +# runtime-versions: +# docker: 18 + +# build: +# commands: +# - echo Build starting on `date` +# - echo Build the Docker image... +# - echo We are using the docker image available at $IMAGE_REPO_NAME +# - echo image that we are using is $IMAGE_TAG +# - echo we are using the latest build for that image for deployment +# - 'sed -i "s,<\!-- COMMIT: -->,<\!-- COMMIT: $CODEBUILD_RESOLVED_SOURCE_VERSION -->,g" client/main.html' +# - docker build -t $IMAGE_REPO_NAME:latest . +# - docker tag $IMAGE_REPO_NAME:latest $IMAGE_REPO_NAME:$IMAGE_TAG + +# post_build: +# commands: +# - test "$CODEBUILD_BUILD_SUCCEEDING" == "1" || exit 1 +# # START - Why do we need to push the Docker image to Docker Hub again?? +# #- echo Pushing build to Docker Hub... +# #- docker push $IMAGE_REPO_NAME:latest +# #- docker push $IMAGE_REPO_NAME:$IMAGE_TAG +# #- printf '[{"name":"%s","imageUri":"%s"}]' meteor $IMAGE_REPO_NAME:$IMAGE_TAG > $CODEBUILD_SRC_DIR/imagedefinitions.json +# # END - Why do we need to push the Docker image to Docker Hub again?? + +# artifacts: +# files: imagedefinitions.json From 5e0b8e14882da35059e9c6bfe91a0455e9261270 Mon Sep 17 00:00:00 2001 From: franck Date: Sat, 8 Feb 2020 15:15:17 +0800 Subject: [PATCH 35/46] TEMPORARY - Do no deploy yet --- .travis.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 877cfc4f..99179776 100644 --- a/.travis.yml +++ b/.travis.yml @@ -78,17 +78,17 @@ after_success: matrix: include: - env: DEPLOY=dev - if: branch = master - deploy: - provider: script - script: TRAVIS_DOCKER_REPO_NAME=$DOCKER_CI_REPO_NAME - TRAVIS_PROFILE=$AWS_PROFILE_DEV - TRAVIS_AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_DEV - TRAVIS_AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_DEV - TRAVIS_AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION - ./deploy.sh - on: - branch: master + # if: branch = master + # deploy: + # provider: script + # script: TRAVIS_DOCKER_REPO_NAME=$DOCKER_CI_REPO_NAME + # TRAVIS_PROFILE=$AWS_PROFILE_DEV + # TRAVIS_AWS_ACCESS_KEY_ID=$AWS_ACCOUNT_USER_ID_DEV + # TRAVIS_AWS_SECRET_ACCESS_KEY=$AWS_ACCOUNT_SECRET_DEV + # TRAVIS_AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION + # ./deploy.sh + # on: + # branch: master # For DEV, we are using AWS Codebuild for the deployment (NOT TRAVIS) # We comment out the DEV option # This will need to be evaluated going forward (shall we revert back to TRAVIS for deployment?) From cadf6034c09d1ac373f240809641ed41d9c3ba41 Mon Sep 17 00:00:00 2001 From: franck Date: Sat, 8 Feb 2020 15:18:35 +0800 Subject: [PATCH 36/46] Tweak DockerFile to avoid error --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3ac0c2a6..266d85e4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ COPY --chown=node:node . . RUN meteor npm install # Use native implementation of bcrypt for better performances -RUN meteor npm install --save bcrypt +# RUN meteor npm install --save bcrypt RUN meteor build --architecture os.linux.x86_64 --directory /bundle RUN cd /bundle/bundle/programs/server && npm install From ba8c043088cfad886e0b54a1deba4f203045c893 Mon Sep 17 00:00:00 2001 From: franck Date: Sat, 8 Feb 2020 16:12:34 +0800 Subject: [PATCH 37/46] try to get the docker image to build --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 266d85e4..215fefd9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,8 @@ USER node:node WORKDIR /src COPY --chown=node:node . . +RUN npm install +RUN npm install -global node-gyp \ RUN meteor npm install # Use native implementation of bcrypt for better performances # RUN meteor npm install --save bcrypt From 5851b23e3e67dcbff0e48849d73dc506fedbe924 Mon Sep 17 00:00:00 2001 From: franck Date: Sat, 8 Feb 2020 16:13:57 +0800 Subject: [PATCH 38/46] tentative fix for issue #896 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 99179776..b21945f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,6 +52,7 @@ cache: - node_modules install: + - npm install -global node-gyp \ - meteor npm install # Use native implementation of bcrypt for better performances - meteor npm install --save bcrypt From c55694355a44b71c64c57c04881cca3a40934eee Mon Sep 17 00:00:00 2001 From: franck Date: Sat, 8 Feb 2020 16:26:28 +0800 Subject: [PATCH 39/46] rever previous chandge - try something else to fix `bcryp` installation warning --- .travis.yml | 8 +++++--- Dockerfile | 2 -- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index b21945f9..f0ff1a4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,12 +52,14 @@ cache: - node_modules install: - - npm install -global node-gyp \ - meteor npm install - # Use native implementation of bcrypt for better performances - - meteor npm install --save bcrypt script: + # Use native implementation of bcrypt for better performances + - cd ~/unee-t/frontend/ + - meteor npm install --save bcrypt + - cd ~ + # Test that all is working as intended - npm t #Adding script deploy docker image to docker repository diff --git a/Dockerfile b/Dockerfile index 215fefd9..266d85e4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,8 +9,6 @@ USER node:node WORKDIR /src COPY --chown=node:node . . -RUN npm install -RUN npm install -global node-gyp \ RUN meteor npm install # Use native implementation of bcrypt for better performances # RUN meteor npm install --save bcrypt From 9c088210935c4dc919f682e2cf313c3d88293450 Mon Sep 17 00:00:00 2001 From: franck Date: Sat, 8 Feb 2020 16:36:06 +0800 Subject: [PATCH 40/46] reverting change - try another way to get `bcryp` native to work --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f0ff1a4d..bb4ddc3b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,9 +56,7 @@ install: script: # Use native implementation of bcrypt for better performances - - cd ~/unee-t/frontend/ - meteor npm install --save bcrypt - - cd ~ # Test that all is working as intended - npm t From 95d7d4fb4b05613042a20f9a40f998ead9e712cd Mon Sep 17 00:00:00 2001 From: franck Date: Sat, 8 Feb 2020 16:37:14 +0800 Subject: [PATCH 41/46] reverting change - try another way to get `bcryp` native to work --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bb4ddc3b..3e024595 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,7 +56,7 @@ install: script: # Use native implementation of bcrypt for better performances - - meteor npm install --save bcrypt + - meteor npm install -global --save bcrypt # Test that all is working as intended - npm t From cf6cbb7983d316a73270c2ad1de136636ea6578d Mon Sep 17 00:00:00 2001 From: franck Date: Sat, 8 Feb 2020 17:01:21 +0800 Subject: [PATCH 42/46] reverting previous commit and downgrade to node v8 --- .travis.yml | 3 ++- Dockerfile | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3e024595..8da99acd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,8 @@ language: node_js node_js: - - lts/* + - '8' +# - lts/* services: - docker diff --git a/Dockerfile b/Dockerfile index 266d85e4..438d44b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:12 AS builder +FROM node:8 AS builder RUN curl -sL https://install.meteor.com | sed s/--progress-bar/-sL/g | /bin/sh RUN mkdir /src /bundle @@ -15,7 +15,7 @@ RUN meteor npm install RUN meteor build --architecture os.linux.x86_64 --directory /bundle RUN cd /bundle/bundle/programs/server && npm install -FROM node:12-slim +FROM node:8-slim USER node:node From 4824d8c1520a824857c2e0b86aabb6e6e29dc49a Mon Sep 17 00:00:00 2001 From: franck Date: Sun, 9 Feb 2020 12:29:56 +0800 Subject: [PATCH 43/46] revert back to node 12 (this is working with Travis CI build) --- .travis.yml | 3 +-- Dockerfile | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8da99acd..3e024595 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,8 +27,7 @@ language: node_js node_js: - - '8' -# - lts/* + - lts/* services: - docker diff --git a/Dockerfile b/Dockerfile index 438d44b2..266d85e4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:8 AS builder +FROM node:12 AS builder RUN curl -sL https://install.meteor.com | sed s/--progress-bar/-sL/g | /bin/sh RUN mkdir /src /bundle @@ -15,7 +15,7 @@ RUN meteor npm install RUN meteor build --architecture os.linux.x86_64 --directory /bundle RUN cd /bundle/bundle/programs/server && npm install -FROM node:8-slim +FROM node:12-slim USER node:node From 91e14a9963d6b9b0a58d83b1a25e7bdd63683b55 Mon Sep 17 00:00:00 2001 From: franck Date: Sun, 9 Feb 2020 14:07:26 +0800 Subject: [PATCH 44/46] make sure we use fibers v4.0.0+ - https://github.com/vuejs/vue-cli/pull/4109/files --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index ca7345bd..6dfd79eb 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,8 @@ "babel-plugin-syntax-dynamic-import": "^6.18.0", "enzyme": "^2.9.1", "eslint": "^5.4.0", - "eslint-plugin-flowtype": "^3.2.0", + "eslint-plugin-flowtype": "^3.2.0",, + "fibers": "^4.0.0", "flow-bin": "^0.85.0", "postcss-easy-import": "^2.1.0", "postcss-modules-extract-imports": "^1.1.0", From 6bbc688d70e60ebd67aa5eab0a1751a260489a49 Mon Sep 17 00:00:00 2001 From: franck Date: Sun, 9 Feb 2020 14:11:04 +0800 Subject: [PATCH 45/46] fix tyupo error --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6dfd79eb..0abd5f18 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "babel-plugin-syntax-dynamic-import": "^6.18.0", "enzyme": "^2.9.1", "eslint": "^5.4.0", - "eslint-plugin-flowtype": "^3.2.0",, + "eslint-plugin-flowtype": "^3.2.0", "fibers": "^4.0.0", "flow-bin": "^0.85.0", "postcss-easy-import": "^2.1.0", From 53a566b4b16695aea73065c2e3d0f3861f6f5dad Mon Sep 17 00:00:00 2001 From: franck Date: Sun, 9 Feb 2020 14:37:37 +0800 Subject: [PATCH 46/46] another try to make Docker user fibers v4.0.0+ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0abd5f18..40f570af 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "bcrypt": "^3.0.6", "body-parser": "^1.18.2", "classnames": "^2.2.5", + "fibers": "^4.0.0", "hammerjs": "^2.0.8", "history": "^4.6.3", "iso-3166-1-codes": "^1.0.0", @@ -57,7 +58,6 @@ "enzyme": "^2.9.1", "eslint": "^5.4.0", "eslint-plugin-flowtype": "^3.2.0", - "fibers": "^4.0.0", "flow-bin": "^0.85.0", "postcss-easy-import": "^2.1.0", "postcss-modules-extract-imports": "^1.1.0",