Skip to content
Snippets Groups Projects
Commit fd3e26ab authored by Alexandru Munteanu's avatar Alexandru Munteanu
Browse files

Merge branch 'develop' of gitlab.coko.foundation:xpub/xpub-faraday into develop

parents 6bd85115 356b1120
No related branches found
No related tags found
1 merge request!13Sprint #14
variables:
IMAGE_ORG: bogdandev
IMAGE_NAME: xpub-faraday
REPO_URL: https://gitlab.coko.foundation/xpub/xpub-faraday
stages:
- build
- test
- review
- docker
- demo
build-aws:
image: docker:stable
stage: build
services:
- docker:dind
variables:
IMAGE_REPO: faraday-qa
before_script:
- apk add --no-cache curl jq python py-pip
- pip install awscli
script:
- eval $(aws ecr get-login --no-include-email --region eu-west-1 | sed 's|https://||')
- docker build -t $IMAGE_REPO:$CI_COMMIT_SHA .
- docker tag $IMAGE_REPO:$CI_COMMIT_SHA $REPOSITORY_URL:latest
- docker push $REPOSITORY_URL:latest
build:
image: docker:stable
stage: build
script:
- docker version
- docker build -t $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA .
- if [ -z "$DOCKERHUB_USERNAME" ] || [ -z "$DOCKERHUB_PASSWORD" ]; then echo "Not pushing" && exit 0; fi
- docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD
- echo "Ignore warning! Cannot perform an interactive login from a non TTY device"
- docker push $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA
lint:
image: $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA
stage: test
variables:
GIT_STRATEGY: none
script:
- cd ${HOME}
- npm run lint
test:
image: $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA
stage: test
variables:
GIT_STRATEGY: none
script:
- cd ${HOME}
- npm run test
# push:latest:
# image: docker:latest
# stage: docker
# script:
# - if [ -z "$DOCKERHUB_USERNAME" ] || [ -z "$DOCKERHUB_PASSWORD" ]; then echo "Not pushing" && exit 0; fi
# - docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD
# - echo "Ignore warning! Cannot perform an interactive login from a non TTY device"
# - docker build -t $IMAGE_ORG/$IMAGE_NAME:latest --label COMMIT_SHA=$CI_COMMIT_SHA .
# - docker push $IMAGE_ORG/$IMAGE_NAME:latest
# only:
# - master
demo:qa:
image: $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA
stage: demo
when: manual
variables:
PACKAGE_NAME: xpub-faraday
environment:
name: qa/$PACKAGE_NAME
url: https://xpub-faraday-qa.now.sh/
script:
- npm i -g --unsafe-perm now
- cd ${HOME}/now
- echo "FROM ${IMAGE_ORG}/${IMAGE_NAME}:${CI_COMMIT_SHA}" >> Dockerfile
- now --public --docker --token $NOW_TOKEN -e AWS_S3_ACCESS_KEY=$AWS_S3_ACCESS_KEY -e AWS_S3_SECRET_KEY=$AWS_S3_SECRET_KEY -e AWS_S3_REGION=$AWS_S3_REGION -e AWS_S3_BUCKET=$AWS_S3_BUCKET -e AWS_SES_SECRET_KEY=$AWS_SES_SECRET_KEY -e AWS_SES_ACCESS_KEY=$AWS_SES_ACCESS_KEY -e AWS_SES_REGION=$AWS_SES_REGION -e EMAIL_SENDER=$EMAIL_SENDER -e secret=$SECRET -e DATABASE=$DATABASE -e DB_USER=$DB_USER -e DB_PASS=$DB_PASS -e DB_HOST=$DB_HOST
- now alias $NOW_URL xpub-faraday-qa --token $NOW_TOKEN
demo:aws-qa:
image: $REPOSITORY_URL:latest
stage: demo
when: manual
variables:
PACKAGE_NAME: xpub-faraday
CLUSTER_NAME: faraday-cluster
environment:
name: qa/$PACKAGE_NAME
url: http://52.211.238.137/
script:
- export AWS_REGION="eu-west-1"
- export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
- export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
- eval $(aws ecr get-login --no-include-email --region eu-west-1 | sed 's|https://||')
- apk --no-cache add --update python python-dev py-pip
- pip install ecs-deploy
- ecs deploy --region ${AWS_REGION} ${CLUSTER_NAME} ${IMAGE_REPO}:${CI_COMMIT_SHA} --tag ${CI_COMMIT_SHA}
demo:staging:
image: $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA
stage: demo
when: manual
variables:
PACKAGE_NAME: xpub-faraday
only:
- master
environment:
name: demo/$PACKAGE_NAME
url: https://xpub-faraday.now.sh/
script:
- npm i -g --unsafe-perm now
- cd ${HOME}/now
- echo "FROM ${IMAGE_ORG}/${IMAGE_NAME}:${CI_COMMIT_SHA}" >> Dockerfile
- now --public --docker --token $NOW_TOKEN -e AWS_S3_ACCESS_KEY=$AWS_S3_ACCESS_KEY -e AWS_S3_SECRET_KEY=$AWS_S3_SECRET_KEY -e AWS_S3_REGION=$AWS_S3_REGION -e AWS_S3_BUCKET=$AWS_S3_BUCKET -e AWS_SES_SECRET_KEY=$AWS_SES_SECRET_KEY -e AWS_SES_ACCESS_KEY=$AWS_SES_ACCESS_KEY -e AWS_SES_REGION=$AWS_SES_REGION -e EMAIL_SENDER=$EMAIL_SENDER -e secret=$SECRET -e DATABASE=$DATABASE_STAGING -e DB_USER=$DB_USER_STAGING -e DB_PASS=$DB_PASS_STAGING -e DB_HOST=$DB_HOST_STAGING
- now alias $NOW_URL xpub-faraday --token $NOW_TOKEN
\ No newline at end of file
variables:
IMAGE_TAG: latest
REV_BUCKET: faraday-rollback
CI_PROJECT_NAME: faraday-qa
CI_CLUSTER_NAME: faraday-cluster
CI_SERVICE_NAME: faraday-container-service
IMAGE_TAG: $CI_PROJECT_NAME:$CI_COMMIT_SHA
IMAGE_NAME: "$REPOSITORY_URL/$IMAGE_TAG"
image: docker:stable image: docker:stable
services:
- docker:dind
stages: stages:
- build - build
...@@ -24,7 +13,7 @@ build: ...@@ -24,7 +13,7 @@ build:
- export AWS_REGION="eu-west-1" - export AWS_REGION="eu-west-1"
- export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID - export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
- export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY - export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
- export REPO=$REPOSITORY_URL - export REPO=$CI_ECR_URL
- apk update - apk update
- apk --no-cache add --update curl python python-dev py-pip - apk --no-cache add --update curl python python-dev py-pip
- pip install awscli --upgrade --user - pip install awscli --upgrade --user
...@@ -38,9 +27,10 @@ build: ...@@ -38,9 +27,10 @@ build:
- docker push $REPO:latest - docker push $REPO:latest
environment: environment:
name: qa name: qa
url: $CI_ALB_URL
lint: lint:
image: $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA image: $CI_ECR_URL:latest
stage: test stage: test
variables: variables:
GIT_STRATEGY: none GIT_STRATEGY: none
...@@ -49,7 +39,7 @@ lint: ...@@ -49,7 +39,7 @@ lint:
- npm run lint - npm run lint
test: test:
image: $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA image: $CI_ECR_URL:latest
stage: test stage: test
variables: variables:
GIT_STRATEGY: none GIT_STRATEGY: none
...@@ -57,8 +47,36 @@ test: ...@@ -57,8 +47,36 @@ test:
- cd ${HOME} - cd ${HOME}
- npm run test - npm run test
deploy:aws: create-rollback:
stage: test
only:
- master
script:
- export AWS_REGION="eu-west-1"
- export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
- export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
- apk --no-cache add --update curl python python-dev py-pip jq
- pip install awscli --upgrade --user
- export PATH=~/.local/bin:/usr/bin/:$PATH
# Discover the ALB name
- ALB=`aws elbv2 describe-load-balancers --region ${AWS_REGION} --names ${CI_ALB_NAME} | jq .LoadBalancers[0].DNSName`
# Test Keepalive
- /usr/bin/curl --fail http://${ALB//'"'}/keepalive
# IF Keepalive return 200...
# Retrieve & Store this revision as 'last known successful revision' in S3 Bucket
- REV=`aws ecs describe-services --region ${AWS_REGION} --cluster ${CI_CLUSTER_NAME} --service ${CI_SERVICE_NAME} |jq -r '.services[0].deployments[0].taskDefinition'`
- echo successful revision is ${REV} Storing it in S3 Bucket
- echo ${REV} > /${CI_SERVICE_NAME}
# sync rev to S3 here
- aws s3 cp /${CI_SERVICE_NAME} s3://${CI_REV_BUCKET}
environment:
name: qa
url: $CI_ALB_URL
deploy:
stage: deploy stage: deploy
only:
- master
script: script:
- export AWS_REGION="eu-west-1" - export AWS_REGION="eu-west-1"
- export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID - export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
...@@ -66,48 +84,68 @@ deploy:aws: ...@@ -66,48 +84,68 @@ deploy:aws:
- apk --no-cache add --update python python-dev py-pip - apk --no-cache add --update python python-dev py-pip
- pip install ecs-deploy - pip install ecs-deploy
# Deploy # Deploy
- ecs deploy ${CI_CLUSTER_NAME} ${CI_SERVICE_NAME} --region ${AWS_REGION} --timeout 600 - ecs deploy ${CI_CLUSTER_NAME} ${CI_SERVICE_NAME} --region ${AWS_REGION} --timeout 600 -e ${CI_CONTAINER_NAME} AWS_S3_ACCESS_KEY $AWS_S3_ACCESS_KEY -e ${CI_CONTAINER_NAME} AWS_S3_SECRET_KEY $AWS_S3_SECRET_KEY -e ${CI_CONTAINER_NAME} AWS_S3_REGION $AWS_S3_REGION -e ${CI_CONTAINER_NAME} AWS_S3_BUCKET $AWS_S3_BUCKET -e ${CI_CONTAINER_NAME} AWS_SES_SECRET_KEY $AWS_SES_SECRET_KEY -e ${CI_CONTAINER_NAME} AWS_SES_ACCESS_KEY $AWS_SES_ACCESS_KEY -e ${CI_CONTAINER_NAME} AWS_SES_REGION $AWS_SES_REGION -e ${CI_CONTAINER_NAME} EMAIL_SENDER $EMAIL_SENDER -e ${CI_CONTAINER_NAME} secret $SECRET -e ${CI_CONTAINER_NAME} DATABASE $DATABASE -e ${CI_CONTAINER_NAME} DB_USER $DB_USER -e ${CI_CONTAINER_NAME} DB_PASS $DB_PASS -e ${CI_CONTAINER_NAME} DB_HOST $DB_HOST
environment: environment:
name: qa name: qa
url: $CI_ALB_URL
deploy:now: aws-qa:
image: $REPOSITORY_URL:latest stage: deploy
when: manual
only:
- develop
script:
- export AWS_REGION="eu-west-1"
- export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
- export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
- apk --no-cache add --update python python-dev py-pip
- pip install ecs-deploy
# Deploy
- ecs deploy ${CI_CLUSTER_NAME} ${CI_SERVICE_NAME} --region ${AWS_REGION} --timeout 600 -e ${CI_CONTAINER_NAME} AWS_S3_ACCESS_KEY $AWS_S3_ACCESS_KEY -e ${CI_CONTAINER_NAME} AWS_S3_SECRET_KEY $AWS_S3_SECRET_KEY -e ${CI_CONTAINER_NAME} AWS_S3_REGION $AWS_S3_REGION -e ${CI_CONTAINER_NAME} AWS_S3_BUCKET $AWS_S3_BUCKET -e ${CI_CONTAINER_NAME} AWS_SES_SECRET_KEY $AWS_SES_SECRET_KEY -e ${CI_CONTAINER_NAME} AWS_SES_ACCESS_KEY $AWS_SES_ACCESS_KEY -e ${CI_CONTAINER_NAME} AWS_SES_REGION $AWS_SES_REGION -e ${CI_CONTAINER_NAME} EMAIL_SENDER $EMAIL_SENDER -e ${CI_CONTAINER_NAME} secret $SECRET -e ${CI_CONTAINER_NAME} DATABASE $DATABASE -e ${CI_CONTAINER_NAME} DB_USER $DB_USER -e ${CI_CONTAINER_NAME} DB_PASS $DB_PASS -e ${CI_CONTAINER_NAME} DB_HOST $DB_HOST
environment:
name: qa
url: $CI_ALB_URL
now.sh:
image: $CI_ECR_URL:latest
stage: deploy stage: deploy
when: manual when: manual
variables:
PACKAGE_NAME: xpub-faraday
script: script:
- npm i -g --unsafe-perm now - npm i -g --unsafe-perm now
- cd ${HOME}/now - cd ${HOME}/now
- echo "FROM ${REPOSITORY_URL}:latest" >> Dockerfile - echo "FROM ${CI_ECR_URL}:latest" >> Dockerfile
- now --public --docker --token $NOW_TOKEN -e AWS_S3_ACCESS_KEY=$AWS_S3_ACCESS_KEY -e AWS_S3_SECRET_KEY=$AWS_S3_SECRET_KEY -e AWS_S3_REGION=$AWS_S3_REGION -e AWS_S3_BUCKET=$AWS_S3_BUCKET -e AWS_SES_SECRET_KEY=$AWS_SES_SECRET_KEY -e AWS_SES_ACCESS_KEY=$AWS_SES_ACCESS_KEY -e AWS_SES_REGION=$AWS_SES_REGION -e EMAIL_SENDER=$EMAIL_SENDER -e secret=$SECRET -e DATABASE=$DATABASE -e DB_USER=$DB_USER -e DB_PASS=$DB_PASS -e DB_HOST=$DB_HOST - now --public --docker --token $NOW_TOKEN -e AWS_S3_ACCESS_KEY=$AWS_S3_ACCESS_KEY -e AWS_S3_SECRET_KEY=$AWS_S3_SECRET_KEY -e AWS_S3_REGION=$AWS_S3_REGION -e AWS_S3_BUCKET=$AWS_S3_BUCKET -e AWS_SES_SECRET_KEY=$AWS_SES_SECRET_KEY -e AWS_SES_ACCESS_KEY=$AWS_SES_ACCESS_KEY -e AWS_SES_REGION=$AWS_SES_REGION -e EMAIL_SENDER=$EMAIL_SENDER -e secret=$SECRET -e DATABASE=$DATABASE -e DB_USER=$DB_USER -e DB_PASS=$DB_PASS -e DB_HOST=$DB_HOST
- now alias $NOW_URL xpub-faraday-qa --token $NOW_TOKEN - now alias $NOW_URL xpub-faraday-qa --token $NOW_TOKEN
environment:
name: qa
url: https://xpub-faraday-qa.now.sh/
test: rollback:
stage: test stage: rollback
when: on_failure
only:
- master
script: script:
- export AWS_REGION="eu-west-1" - export AWS_REGION="us-east-1"
- export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID - export AWS_ACCESS_KEY_ID=$aws_access_key_id
- export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY - export AWS_SECRET_ACCESS_KEY=$aws_secret_access_key
- apk --no-cache add --update curl python python-dev py-pip jq - apk --no-cache add --update curl python python-dev py-pip
- pip install awscli --upgrade --user - pip install awscli --upgrade --user
- export PATH=~/.local/bin:/usr/bin/:$PATH - export PATH=~/.local/bin:/usr/bin/:$PATH
# Discover the ALB name - pip install ecs-deploy
- ALB=`aws elbv2 describe-load-balancers --region ${AWS_REGION} --names ${CI_PROJECT_NAME} | jq .LoadBalancers[0].DNSName` - aws s3 cp s3://${CI_REV_BUCKET}/${CI_SERVICE_NAME} ./
# Test Keepalive - REV=`cat ./${CI_SERVICE_NAME}`
- /usr/bin/curl --fail http://${ALB//'"'}/keepalive - echo rev is $REV
# IF Keepalive return 200... - ecs deploy --region ${AWS_REGION} ${CLUSTER_NAME} ${CI_SERVICE_NAME} --task ${REV} -e ${CI_CONTAINER_NAME} AWS_S3_ACCESS_KEY $AWS_S3_ACCESS_KEY -e ${CI_CONTAINER_NAME} AWS_S3_SECRET_KEY $AWS_S3_SECRET_KEY -e ${CI_CONTAINER_NAME} AWS_S3_REGION $AWS_S3_REGION -e ${CI_CONTAINER_NAME} AWS_S3_BUCKET $AWS_S3_BUCKET -e ${CI_CONTAINER_NAME} AWS_SES_SECRET_KEY $AWS_SES_SECRET_KEY -e ${CI_CONTAINER_NAME} AWS_SES_ACCESS_KEY $AWS_SES_ACCESS_KEY -e ${CI_CONTAINER_NAME} AWS_SES_REGION $AWS_SES_REGION -e ${CI_CONTAINER_NAME} EMAIL_SENDER $EMAIL_SENDER -e ${CI_CONTAINER_NAME} secret $SECRET -e ${CI_CONTAINER_NAME} DATABASE $DATABASE -e ${CI_CONTAINER_NAME} DB_USER $DB_USER -e ${CI_CONTAINER_NAME} DB_PASS $DB_PASS -e ${CI_CONTAINER_NAME} DB_HOST $DB_HOST
# Retrieve & Store this revision as 'last known successful revision' in S3 Bucket
- REV=`aws ecs describe-services --region ${AWS_REGION} --cluster ${CI_CLUSTER_NAME} --service ${CI_SERVICE_NAME} |jq -r '.services[0].deployments[0].taskDefinition'`
- echo successful revision is ${REV} Storing it in S3 Bucket
- echo ${REV} > /${CI_SERVICE_NAME}
# sync rev to S3 here
- aws s3 cp /${CI_SERVICE_NAME} s3://${REV_BUCKET}
environment: environment:
name: qa name: qa
url: $CI_ALB_URL
rollback: rollback-qa:
stage: rollback stage: rollback
when: manual
only:
- develop
script: script:
- export AWS_REGION="us-east-1" - export AWS_REGION="us-east-1"
- export AWS_ACCESS_KEY_ID=$aws_access_key_id - export AWS_ACCESS_KEY_ID=$aws_access_key_id
...@@ -116,10 +154,10 @@ rollback: ...@@ -116,10 +154,10 @@ rollback:
- pip install awscli --upgrade --user - pip install awscli --upgrade --user
- export PATH=~/.local/bin:/usr/bin/:$PATH - export PATH=~/.local/bin:/usr/bin/:$PATH
- pip install ecs-deploy - pip install ecs-deploy
- aws s3 cp s3://${REV_BUCKET}/${CI_SERVICE_NAME} ./ - aws s3 cp s3://${CI_REV_BUCKET}/${CI_SERVICE_NAME} ./
- REV=`cat ./${CI_SERVICE_NAME}` - REV=`cat ./${CI_SERVICE_NAME}`
- echo rev is $REV - echo rev is $REV
- ecs deploy --region ${AWS_REGION} ${CLUSTER_NAME} ${CI_SERVICE_NAME} --task ${REV} - ecs deploy --region ${AWS_REGION} ${CLUSTER_NAME} ${CI_SERVICE_NAME} --task ${REV} -e ${CI_CONTAINER_NAME} AWS_S3_ACCESS_KEY $AWS_S3_ACCESS_KEY -e ${CI_CONTAINER_NAME} AWS_S3_SECRET_KEY $AWS_S3_SECRET_KEY -e ${CI_CONTAINER_NAME} AWS_S3_REGION $AWS_S3_REGION -e ${CI_CONTAINER_NAME} AWS_S3_BUCKET $AWS_S3_BUCKET -e ${CI_CONTAINER_NAME} AWS_SES_SECRET_KEY $AWS_SES_SECRET_KEY -e ${CI_CONTAINER_NAME} AWS_SES_ACCESS_KEY $AWS_SES_ACCESS_KEY -e ${CI_CONTAINER_NAME} AWS_SES_REGION $AWS_SES_REGION -e ${CI_CONTAINER_NAME} EMAIL_SENDER $EMAIL_SENDER -e ${CI_CONTAINER_NAME} secret $SECRET -e ${CI_CONTAINER_NAME} DATABASE $DATABASE -e ${CI_CONTAINER_NAME} DB_USER $DB_USER -e ${CI_CONTAINER_NAME} DB_PASS $DB_PASS -e ${CI_CONTAINER_NAME} DB_HOST $DB_HOST
environment: environment:
name: qa name: qa
when: on_failure url: $CI_ALB_URL
\ No newline at end of file \ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment