From ae711571fd97829a166ca31aae292033af69ff8b Mon Sep 17 00:00:00 2001 From: Gunasekar-K Date: Fri, 22 Mar 2019 12:40:38 +0530 Subject: [PATCH] STS integration --- .circleci/config.yml | 116 +++++++++++++++++++++---------------------- build.sh | 20 ++++---- 2 files changed, 66 insertions(+), 70 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 747a1fa..fd2157e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,78 +1,72 @@ version: 2 +defaults: &defaults + docker: + - image: docker:17.06.1-ce-git +install_dependency: &install_dependency + name: Installation of build and deployment dependencies. + command: | + apk update + apk add --no-cache bash curl + apk upgrade + apk add --no-cache jq py-pip sudo + sudo pip install awscli --upgrade +install_deploysuite: &install_deploysuite + name: Installation of install_deploysuite. + command: | + git clone --branch v1.3 https://github.com/topcoder-platform/tc-deploy-scripts ../buildscript + cp ./../buildscript/master_deploy.sh . + cp ./../buildscript/buildenv.sh . + cp ./../buildscript/awsconfiguration.sh . +restore_cache_settings_for_build: &restore_cache_settings_for_build + key: docker-tc-bus-api-{{ checksum "package-lock.json" }} +save_cache_settings: &save_cache_settings + key: docker-tc-bus-api-{{ checksum "package-lock.json" }} + paths: + - node_modules + +run_build: &run_build + name: Build of Docker image + command: ./build.sh jobs: # Build & Deploy against development backend rer "build-dev": - docker: - - image: docker:17.06.1-ce-git + <<: *defaults steps: - # Initialization. - checkout - setup_remote_docker - - run: - name: Installation of build dependencies. - command: apk add --no-cache bash - - # Restoration of node_modules from cache. - - restore_cache: - key: docker-tc-bus-api-{{ checksum "package-lock.json" }} - - # Build of Docker image. - - run: - name: Build of Docker image - command: ./build.sh DEV - - # Caching node modules. - - save_cache: - key: docker-tc-bus-api-{{ checksum "package-lock.json" }} - paths: - - node_modules - - # Deployment. - - run: - name: Installing AWS client - command: | - apk add --no-cache jq py-pip sudo - sudo pip install awscli --upgrade - + - run: *install_dependency + - run: *install_deploysuite + - restore_cache: *restore_cache_settings_for_build + - run: *run_build + - save_cache: *save_cache_settings - deploy: - command: ./deploy.sh DEV $CIRCLE_SHA1 + command: | + ./awsconfiguration.sh DEV + source awsenvconf + ./buildenv.sh -e DEV -b dev-tc-bus-api-deployvar + source buildenvvar + ./master_deploy.sh -d ECS -e DEV -t latest -s dev-global-appvar,dev-tc-bus-api-appvar -i tc-bus-api + #./deploy.sh DEV $CIRCLE_SHA1 "build-prod": - docker: - - image: docker:17.06.1-ce-git + <<: *defaults steps: - # Initialization. - checkout - setup_remote_docker - - run: - name: Installation of build dependencies. - command: apk add --no-cache bash - - # Restoration of node_modules from cache. - - restore_cache: - key: docker-tc-bus-api-{{ checksum "package-lock.json" }} - - # Build of Docker image. - - run: - name: Build of Docker image - command: ./build.sh PROD - - # Caching node modules. - - save_cache: - key: docker-tc-bus-api-{{ checksum "package-lock.json" }} - paths: - - node_modules - - # Deployment. - - run: - name: Installing AWS client - command: | - apk add --no-cache jq py-pip sudo - sudo pip install awscli --upgrade - + - run: *install_dependency + - run: *install_deploysuite + - restore_cache: *restore_cache_settings_for_build + - run: *run_build + - save_cache: *save_cache_settings - deploy: - command: ./deploy.sh PROD $CIRCLE_SHA1 + command: | + ./awsconfiguration.sh PROD + source awsenvconf + ./buildenv.sh -e PROD -b prod-tc-bus-api-deployvar + source buildenvvar + ./master_deploy.sh -d ECS -e PROD -t latest -s prod-global-appvar,prod-tc-bus-api-appvar -i tc-bus-api + #./deploy.sh PROD $CIRCLE_SHA1 workflows: version: 2 @@ -80,10 +74,12 @@ workflows: jobs: # Development builds are executed on "develop" branch only. - "build-dev": + context : org-global filters: branches: only: ['dev'] - "build-prod": + context : org-global filters: branches: only: master diff --git a/build.sh b/build.sh index 3332e3a..d93f6c9 100755 --- a/build.sh +++ b/build.sh @@ -6,19 +6,19 @@ set -eo pipefail # This script expects a single argument: NODE_ENV, which must be either # "development" or "production". -NODE_ENV=$1 +# NODE_ENV=$1 -ENV=$1 -AWS_REGION=$(eval "echo \$${ENV}_AWS_REGION") -AWS_ACCESS_KEY_ID=$(eval "echo \$${ENV}_AWS_ACCESS_KEY_ID") -AWS_SECRET_ACCESS_KEY=$(eval "echo \$${ENV}_AWS_SECRET_ACCESS_KEY") -AWS_ACCOUNT_ID=$(eval "echo \$${ENV}_AWS_ACCOUNT_ID") -AWS_REPOSITORY=$(eval "echo \$${ENV}_AWS_REPOSITORY") +# ENV=$1 +# AWS_REGION=$(eval "echo \$${ENV}_AWS_REGION") +# AWS_ACCESS_KEY_ID=$(eval "echo \$${ENV}_AWS_ACCESS_KEY_ID") +# AWS_SECRET_ACCESS_KEY=$(eval "echo \$${ENV}_AWS_SECRET_ACCESS_KEY") +# AWS_ACCOUNT_ID=$(eval "echo \$${ENV}_AWS_ACCOUNT_ID") +# AWS_REPOSITORY=$(eval "echo \$${ENV}_AWS_REPOSITORY") -# Builds Docker image of the app. -TAG=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/tc-bus-api:$CIRCLE_SHA1 - +# # Builds Docker image of the app. +# TAG=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/tc-bus-api:$CIRCLE_SHA1 +TAG="tc-bus-api:latest" docker build -t $TAG . # Copies "node_modules" from the created image, if necessary for caching.