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/.travis.yml b/.travis.yml index 72f8365a..3e024595 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,44 @@ -sudo: required +# Variables needed for this script are: + +# 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 + + #For Prod environment: + # - AWS_ACCOUNT_USER_ID_PROD + # - AWS_ACCOUNT_SECRET_PROD + # - AWS_PROFILE_PROD + + #For Demo environment: + # - AWS_ACCOUNT_USER_ID_DEMO + # - AWS_ACCOUNT_SECRET_DEMO + # - AWS_PROFILE_DEMO + +# Case 2: Created when Travis CI runs + # - IMAGE_TAG language: node_js + node_js: - lts/* +services: + - docker + +env: + global: + - COMMIT=${TRAVIS_COMMIT::7} + #Add IMAGE_TAG variable to build docker image + - 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 @@ -23,28 +55,68 @@ install: - meteor npm install script: + # Use native implementation of bcrypt for better performances + - meteor npm install -global --save bcrypt + # Test that all is working as intended - npm t +#Adding script deploy docker image to docker repository + +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 + - 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 + - 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 + 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?) +# - 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: provider: script - skip_cleanup: true - script: AWS_ACCESS_KEY_ID=$AWS_915001051872_ID AWS_SECRET_ACCESS_KEY=$AWS_915001051872_SECRET ./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 - 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 '/*' + # 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: - tags: true - -env: - global: - - COMMIT=${TRAVIS_COMMIT::7} + branch: master + tags: true \ No newline at end of file diff --git a/AWS-docker-compose.yml b/AWS-docker-compose.yml index f460756a..48e2c21e 100644 --- a/AWS-docker-compose.yml +++ b/AWS-docker-compose.yml @@ -1,7 +1,37 @@ +#Variable for this script are set in: +# - 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: meteor: + # 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: @@ -10,10 +40,15 @@ services: - ROOT_URL=${ROOT_URL} - BUGZILLA_URL=${BUGZILLA_URL} - BUGZILLA_ADMIN_KEY=${BUGZILLA_ADMIN_KEY} + # INS change commented out - revert to previous version of the master - MONGO_URL=mongodb://root:${MONGO_PASSWORD}@${MONGO_CONNECT} - - CLOUDINARY_URL=${CLOUDINARY_URL} + #- 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} @@ -27,6 +62,6 @@ services: logging: driver: awslogs options: - awslogs-region: ap-southeast-1 + awslogs-region: ${TRAVIS_AWS_DEFAULT_REGION} awslogs-group: meteor awslogs-stream-prefix: ecs diff --git a/Dockerfile b/Dockerfile index e456dd4d..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 @@ -10,10 +10,12 @@ 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 node:8-slim +FROM node:12-slim USER node:node 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: 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..22fe2e53 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/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 + + 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 33cdb8f1..b53a3037 100644 --- a/aws-env.dev +++ b/aws-env.dev @@ -1,17 +1,57 @@ -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) -export STAGE=dev -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) + # 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) + + # 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) + + 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/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 + + 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/aws-env.prod b/aws-env.prod index 657965f0..064773a2 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/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 + + 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/backup/connect.sh b/backup/connect.sh index 8e0d94c8..982d6e04 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 } @@ -35,6 +34,21 @@ done AWS_PROFILE=uneet-$STAGE shift "$((OPTIND-1))" # Discard the options and sentinel -- + +# 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 diff --git a/buildspec.yml b/buildspec.yml deleted file mode 100644 index 8fc70167..00000000 --- a/buildspec.yml +++ /dev/null @@ -1,39 +0,0 @@ ---- -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) - - install: - runtime-versions: - docker: 18 - - build: - commands: - - echo Build starting on `date` - - echo Build the Docker image... - - '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 - - 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 - -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 diff --git a/deploy.sh b/deploy.sh index 84a5842a..f8294c11 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 } @@ -20,6 +20,14 @@ EOF while getopts "pd" opt do case $opt in + #Add option d for development + # 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 @@ -34,29 +42,33 @@ 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) -if ! aws configure --profile $AWS_PROFILE list +if ! aws configure --profile $TRAVIS_PROFILE list then - echo Profile $AWS_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.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.${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 $AWS_PROFILE list + if ! aws configure --profile $TRAVIS_PROFILE list then - echo Profile $AWS_PROFILE does not exist >&2 + echo Profile $TRAVIS_PROFILE does not exist >&2 exit 1 fi @@ -71,7 +83,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 $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:]]') @@ -82,11 +94,15 @@ 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 $TRAVIS_PROFILE -p ${service} -f docker-compose-${service}.yml service up \ + --target-group-arn ${MEFE_TARGET_ARN} \ + --container-name meteor \ + --container-port 3000 \ + --create-log-groups \ --deployment-max-percent 100 \ --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 $TRAVIS_PROFILE -p ${service} -f docker-compose-${service}.yml service ps echo "END $0 $(date)" diff --git a/env-setup.bash b/env-setup.bash index 19467b10..4eeb039f 100755 --- a/env-setup.bash +++ b/env-setup.bash @@ -21,12 +21,16 @@ 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 " +# 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 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/package.json b/package.json index 91317c63..40f570af 100644 --- a/package.json +++ b/package.json @@ -19,9 +19,10 @@ }, "dependencies": { "@babel/runtime": "^7.1.5", - "bcrypt": "^1.0.3", + "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", 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