Skip to content

Commit

Permalink
Merge pull request #95 from ferrumnet/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
zikriya authored May 19, 2022
2 parents a172e2a + ba776e6 commit e7660bd
Show file tree
Hide file tree
Showing 9 changed files with 778 additions and 99 deletions.
103 changes: 103 additions & 0 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Build, Upload and Deploy

on:
push:
branches:
- develop
pull_request:

env:
AppName: gateway-backend
Region: us-east-2

jobs:
Build:
runs-on: ubuntu-latest
env:
s3-bucket: ferrum-gateway-pipeline-artifacts-dev
s3-filename: dev-aws-codedeploy-${{ github.sha }}
Environment: dev
AppName: gateway-backend
# strategy:
# matrix:
# # python-version: [3.8]
# # node-version: ['12.x']
# # appname: ['aws-codedeploy']
# # deploy-group: ['staging']
# s3-bucket: ['ferrum-pipeline-artifacts']
# s3-filename: ['staging-aws-codedeploy-${{ github.sha }}']
# AppName: ['gateway-backend']
# Environment: ['dev']

steps:
- name: checkout code
uses: actions/checkout@v2

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, tag, and push image to Amazon ECR
run: |
docker build -t ${{ secrets.ECR_REGISTRY }}:latest .
docker push ${{ secrets.ECR_REGISTRY }}:latest
- name: AWS Deploy push
run: |
echo "export Region=${{ env.Region }}" >> set_env.sh
echo "export Environment=${{ env.Environment }}" >> set_env.sh
echo "export AppName=${{ env.AppName }}" >> set_env.sh
echo "export ECR_REGISTRY=${{ secrets.ECR_REGISTRY }}" >> set_env.sh
aws deploy push \
--application-name gateway-backend-dev \
--s3-location s3://${{ env.s3-bucket }}/${{ env.s3-filename }}.zip \
--source .
# --description "This is a revision for the ${{ matrix.appname }}-${{ github.sha }}" \
# --ignore-hidden-files \
Deploy:
needs: [Build]
runs-on: ubuntu-latest
env:
s3-bucket: ferrum-gateway-pipeline-artifacts-dev
s3-filename: dev-aws-codedeploy-${{ github.sha }}
Environment: dev
AppName: gateway-backend
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2


- name: CodeDeploy Deployment Api
id: deploy_api
run: |
aws deploy create-deployment \
--application-name ${{ secrets.CODE_DEPLOY_APP }} \
--deployment-group-name ${{ secrets.DEPLOYMENT_GROUP_API }} \
--deployment-config-name CodeDeployDefault.OneAtATime \
--s3-location bucket=${{ env.s3-bucket }},key=${{ env.s3-filename }}.zip,bundleType=zip
# --github-location repository=${{ github.repository }},commitId=${{ github.sha }}
- name: CodeDeploy Deployment Cron
id: deploy_cron
run: |
aws deploy create-deployment \
--application-name ${{ secrets.CODE_DEPLOY_APP }} \
--deployment-group-name ${{ secrets.DEPLOYMENT_GROUP_CRON }} \
--deployment-config-name CodeDeployDefault.OneAtATime \
--s3-location bucket=${{ env.s3-bucket }},key=${{ env.s3-filename }}.zip,bundleType=zip
# --github-location repository=${{ github.repository }},commitId=${{ github.sha }}
15 changes: 4 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
FROM node:16

# Create app directory
WORKDIR /usr/src/app
WORKDIR /app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
COPY . /app

RUN npm install
# If you are building your code for production
# RUN npm ci --only=production

# Bundle app source
COPY . .

EXPOSE 8080
CMD [ "node", "server.js" ]

CMD [ "node", "server.js" ]
6 changes: 3 additions & 3 deletions app/controllers/api/v1/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ module.exports = function (router) {
for (let i = 0; i < data.length; i++) {
let item = data[i]
let path = ''
if(req.user){
if(req.user && req.user.role && req.user.role == 'organizationAdmin'){
path = getItemFromMetaData(product, 'internalDynamicPathForSingle').value
}else {
path = getItemFromMetaData(product, 'internalPubDynamicPathForSingle').value
}
if (item.leaderboardCurrencyAddressesByNetwork.length > 1) {
if(req.user){
if(req.user && req.user.role && req.user.role == 'organizationAdmin'){
path = getItemFromMetaData(product, 'internalDynamicPathForMulti').value
}else {
path = getItemFromMetaData(product, 'internalPubDynamicPathForMulti').value
Expand Down Expand Up @@ -157,7 +157,7 @@ module.exports = function (router) {
for (let i = 0; i < data.length; i++) {
let item = data[i]
let path = ''
if(req.user){
if(req.user && req.user.role && req.user.role == 'organizationAdmin'){
path = getItemFromMetaData(product, 'internalDynamicPathForSingle').value
}else {
path = getItemFromMetaData(product, 'internalPubDynamicPathForSingle').value
Expand Down
10 changes: 10 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 0.0
os: linux
files:
- source: /
destination: /root
hooks:
AfterInstall:
- location: deploy/scripts/code_deploy.sh
timeout: 60
runas: root
34 changes: 18 additions & 16 deletions deploy/codebuild/pre-deploy-buildspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@ version: 0.2
environment_variables:
plaintext:
ARTIFACT_FILE_NAME: ""
ECR_URL: ""
phases:
install:
runtime-versions:
python: 3.8
nodejs: 14
pre_build:
commands:
- AppVersion='SNAPSHOT'
- envsubst '$DevPrefix $AppName $AppVersion $Environment $PipelineArtifactsBucket' <deploy/cloudformation/parameters/app-deploy.json >app-deploy.json
- cat app-deploy.json
- echo "Zip up artifacts ${AppName}.zip"
- ARTIFACT_FILE_NAME="${DevPrefix}${AppName}-${AppVersion}.zip"
- node --version
- npm -v
- ECR_URL="${AccountId}.dkr.ecr.${Region}.amazonaws.com/${DevPrefix}-${AppName}-${Environment}-${Branch}"
- aws ecr get-login-password --region us-east-2 | docker login --username AWS --password-stdin "${ECR_URL}"
build:
commands:
- npm install
- zip -r "${ARTIFACT_FILE_NAME}" *
- aws s3 cp ${ARTIFACT_FILE_NAME} s3://${PipelineArtifactsBucket}/${DevPrefix}${AppName}/artifacts/
- echo "export Region=${Region}" >> set_env.sh
- echo "export Environment=${Environment}" >> set_env.sh
- echo "export Branch=${Branch}" >> set_env.sh
- echo "export AppName=${AppName}" >> set_env.sh
- echo "export DevPrefix=${DevPrefix}" >> set_env.sh
- echo "export AccountId=${AccountId}" >> set_env.sh
- docker build -t ${ECR_URL}:latest .
post_build:
commands:
- rm -f "${ARTIFACT_FILE_NAME}"
- echo Build completed on `date`
- echo Pushing the Docker image...
- echo "${ECR_URL}"
- docker push "${ECR_URL}":latest

artifacts:
files:
- '**/*'
- appspec.yml
- set_env.sh
- deploy/scripts/code_deploy.sh
30 changes: 22 additions & 8 deletions deploy/create-pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@

# *** Change this to the desired name of the Cloudformation stack of
# your Pipeline (*not* the stack name of your app)
GITHUB_OWNER="zikriya"
GITHUB_REPO="leaderboard"
GITHUB_BRANCH="dev"
GITHUB_OWNER="sheraz-ferrum"
GITHUB_REPO="gateway-backend"
# for branch can only contain lowercase letters, numbers, hyphens, underscores, and forward slashes
GITHUB_BRANCH="cicd_configuration"
GITHUB_OAUTH_TOKEN=$1
DEV_PREFIX="zikria-"
APP_NAME="ferrum-network-backend"
DEV_PREFIX="sheraz"
APP_NAME="gateway-backend"
ENVIRONMENT="dev"
CODEPIPELINE_STACK_NAME="${DEV_PREFIX}${APP_NAME}-${ENVIRONMENT}-pipeline"
DEFAULT_VPC=$(aws ec2 describe-vpcs --region us-east-2 \
--filters Name=isDefault,Values=true \
--query 'Vpcs[*].VpcId' \
--output text)
SUBNET_A=$(aws ec2 describe-subnets --region us-east-2 --filter Name=vpc-id,Values=$DEFAULT_VPC --query 'Subnets[0].SubnetId')
SUBNET_B=$(aws ec2 describe-subnets --region us-east-2 --filter Name=vpc-id,Values=$DEFAULT_VPC --query 'Subnets[1].SubnetId')
SUBNET_C=$(aws ec2 describe-subnets --region us-east-2 --filter Name=vpc-id,Values=$DEFAULT_VPC --query 'Subnets[2].SubnetId')



if [ -z ${1} ]
then
Expand All @@ -20,8 +30,8 @@ fi

set -eu

aws cloudformation create-stack \
--capabilities CAPABILITY_IAM \
aws cloudformation create-stack --region us-east-2 \
--capabilities CAPABILITY_NAMED_IAM \
--stack-name $CODEPIPELINE_STACK_NAME \
--parameters ParameterKey=DevPrefix,ParameterValue=${DEV_PREFIX} \
ParameterKey=GitHubOwner,ParameterValue=${GITHUB_OWNER} \
Expand All @@ -30,9 +40,13 @@ aws cloudformation create-stack \
ParameterKey=GitHubOAuthToken,ParameterValue=${GITHUB_OAUTH_TOKEN} \
ParameterKey=AppName,ParameterValue=${APP_NAME} \
ParameterKey=Environment,ParameterValue=${ENVIRONMENT} \
ParameterKey=VPC,ParameterValue=${DEFAULT_VPC} \
ParameterKey=SubnetA,ParameterValue=${SUBNET_A} \
ParameterKey=SubnetB,ParameterValue=${SUBNET_B} \
ParameterKey=SubnetC,ParameterValue=${SUBNET_C} \
--template-body file://pipeline.yaml

sleep 10

aws wait cloudforamtion stack-create-complete \
--stack-name $CODEPIPELINE_STACK_NAME
--stack-name $CODEPIPELINE_STACK_NAME
Loading

0 comments on commit e7660bd

Please sign in to comment.