diff --git a/.gitlab-ci.ok.yml b/.gitlab-ci.ok.yml new file mode 100644 index 0000000000000000000000000000000000000000..c6332261a24060b1135c87873dc2449c1381706a --- /dev/null +++ b/.gitlab-ci.ok.yml @@ -0,0 +1,120 @@ +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 + - 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 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c6332261a24060b1135c87873dc2449c1381706a..f9942d03721f137a7191607f221aef268c0d2deb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,120 +1,94 @@ variables: + IMAGE_TAG: latest IMAGE_ORG: bogdandev IMAGE_NAME: xpub-faraday + REV_BUCKET: faraday-rollback + CLUSTER_NAME: faraday-qa + CI_PROJECT_NAME: faraday-qa REPO_URL: https://gitlab.coko.foundation/xpub/xpub-faraday + IMAGE_TAG: $CI_PROJECT_NAME:$CI_COMMIT_SHA + IMAGE_NAME: "$REPOSITORY_URL/$IMAGE_TAG" stages: - build + - deploy - 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 + - rollback 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 + # Setup + - export AWS_REGION="eu-west-1" + - export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID + - export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY + - export REPO=$REPOSITORY_URL + - apk update + - apk --no-cache add --update curl python python-dev py-pip + - pip install awscli --upgrade --user + - export PATH=~/.local/bin:/usr/bin/:$PATH + # AUTH + - CERT=`aws ecr get-login --no-include-email --region ${AWS_REGION}` + - ${CERT} + # Build + - docker build -t ${CI_PROJECT_NAME} . + - docker tag $CI_PROJECT_NAME:latest $REPO/$IMAGE_TAG + - docker tag $CI_PROJECT_NAME:latest $REPO/${CI_PROJECT_NAME}:latest + - docker push $REPO/$IMAGE_TAG + - docker push $REPO/${CI_PROJECT_NAME}:latest 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 + name: staging -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/ +deploy: + stage: deploy 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 - - ecs deploy --region ${AWS_REGION} ${CLUSTER_NAME} ${IMAGE_REPO}:${CI_COMMIT_SHA} --tag ${CI_COMMIT_SHA} + # Deploy + - ecs deploy --region ${AWS_REGION} ${CLUSTER_NAME} ${CI_PROJECT_NAME} --tag ${CI_COMMIT_SHA} + environment: + name: staging -demo:staging: - image: $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA - stage: demo - when: manual - variables: - PACKAGE_NAME: xpub-faraday - only: - - master +test: + stage: test + script: + - export AWS_REGION="us-east-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_PROJECT_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 ${CLUSTER_NAME} --service ${CI_PROJECT_NAME} |jq -r '.services[0].deployments[0].taskDefinition'` + - echo successful revision is ${REV} Storing it in S3 Bucket + - echo ${REV} > /${CI_PROJECT_NAME} + # sync rev to S3 here + - aws s3 cp /${CI_PROJECT_NAME} s3://${REV_BUCKET} environment: - name: demo/$PACKAGE_NAME - url: https://xpub-faraday.now.sh/ + name: staging + +rollback: + stage: rollback 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 + - export AWS_REGION="us-east-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 + - pip install awscli --upgrade --user + - export PATH=~/.local/bin:/usr/bin/:$PATH + - pip install ecs-deploy + - aws s3 cp s3://${REV_BUCKET}/${CI_PROJECT_NAME} ./ + - REV=`cat ./${CI_PROJECT_NAME}` + - echo rev is $REV + - ecs deploy --region ${AWS_REGION} ${CLUSTER_NAME} ${CI_PROJECT_NAME} --task ${REV} + environment: + name: staging + when: on_failure \ No newline at end of file