definitions: set-variables: &set-variables - variables: - name: VERSION default: "latest" set-variables-jobs: &set-variables-jobs - variables: - name: ENV default: "dev" allowed-values: # Optionally restrict variable values - "dev" - "qa" - "stage" - "prod" - name: JOBNAME default: "mysql-backup" allowed-values: # Optionally restrict variable values - "mysql-backup" - "wp-data-backup" - "mysql-restore" - "wp-data-restore" - name: SUBDOMAIN default: www allowed-values: # Optionally restrict variable values - "www" - "dev01" - "dev02" - "dev03" - "dev04" - "dev05" - name: RESTORE_VERSION default: "PASTE_RESTORE_VERSION_FILE_NAME" set-variables-subdomain: &set-variables-subdomain - variables: - name: ENV default: "dev" allowed-values: # Optionally restrict variable values - "dev" - name: URL_DOMAIN default: dev01.dev-medicalalert.com allowed-values: # Optionally restrict variable values - "dev01.dev-medicalalert.com" - "dev02.dev-medicalalert.com" - "dev03.dev-medicalalert.com" - "dev04.dev-medicalalert.com" - "dev05.dev-medicalalert.com" - name: MYSQL_FILE_NAME default: "MYSQL_FILE_NAME_TO_DEPLOY" - name: STATIC_FILE_NAME default: "STATIC_FILE_NAME_TO_DEPLOY" steps: - step: &deploy name: deploy to $ENV environment image: atlassian/default-image:3 script: # check if env file exists - if [ -e setenv.sh ]; then - cat setenv.sh - source setenv.sh - fi - echo "This is for $ENV environment" - ls -lrth && cd build/${ENV} - curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install - export DB_PASSWORD=$(aws ssm get-parameters --names $ENV-medicalalert-masterdbpass --query "Parameters[*].{Value:Value}" --output text) - export DB_PASSWORD=`echo -n "$DB_PASSWORD" | base64` && sed -i "/DB_PASSWORD/c\ DB_PASSWORD = $DB_PASSWORD" secrets.yaml - envsubst < deployment.tpl > deployment.yaml - cat deployment.yaml - pipe: atlassian/aws-eks-kubectl-run:2.2.0 variables: AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID} AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY} AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION CLUSTER_NAME: $CLUSTER KUBECTL_COMMAND: "apply" RESOURCE_PATH: "../${ENV}" KUBECTL_ARGS: "" KUBECTL_APPLY_ARGS: "-f" DEBUG: "true" pipelines: # our custom pipeline, what shows up Bitbucket web app custom: deploy-dev: - !!merge <<: *set-variables - step: !!merge <<: *deploy deployment: dev name: "deploy to dev" deploy-qa: - !!merge <<: *set-variables - step: !!merge <<: *deploy deployment: qa name: "deploy to qa" release-stg: - !!merge <<: *set-variables - step: !!merge <<: *deploy deployment: stage name: "deploy to stage" release-prod: - !!merge <<: *set-variables - step: !!merge <<: *deploy deployment: prod name: "deploy to prod" common-jobs: - !!merge <<: *set-variables-jobs - step: name: vars for common-jobs script: - source setenv.sh - echo "export JOBNAME=$JOBNAME" >> setenv.sh - echo "export ENV=$ENV" >> setenv.sh - echo "export CLUSTER=caresage-eks-cluster-$ENV" >> setenv.sh - echo "export VERSION=$BITBUCKET_BUILD_NUMBER" >> setenv.sh - echo "export RESTORE_VERSION=$RESTORE_VERSION" >> setenv.sh - echo "export SUBDOMAIN=$SUBDOMAIN" >> setenv.sh - echo "export BITBUCKET_REPO_SLUG=$BITBUCKET_REPO_SLUG" >> setenv.sh artifacts: # define the artifacts to be passed to each future step - setenv.sh - step: name: common jobs for SQL and WWW backup and restore. image: atlassian/pipelines-awscli script: - source setenv.sh && chmod 755 ./common-jobs-bitbucket.sh - if [ "$JOBNAME" = "mysql-restore" ] && [ "$SUBDOMAIN" = "www" ] ; then ./common-jobs-bitbucket.sh subdomain_deploy; fi # - [[ "$SUBDOMAIN" != "www" ]] && [[ "$ENV" = "qa" || "$ENV" = "stage" || "$ENV" = "prod" ]] && exit || echo VALIDATION-PASS - if [[ "$SUBDOMAIN" != "www" ]] && [[ "$ENV" = "qa" || "$ENV" = "stage" || "$ENV" = "prod" ]] ; then echo VALIDATION-FAIL && exit 9 ; else echo VALIDATION-PASS;fi - ./common-jobs-bitbucket.sh $JOBNAME subdomain-deploy: - !!merge <<: *set-variables-subdomain - step: name: vars for subdomain script: - source setenv.sh - echo "export ENV=$ENV" >> setenv.sh - echo "export CLUSTER=caresage-eks-cluster-$ENV" >> setenv.sh - echo "export VERSION=$BITBUCKET_BUILD_NUMBER" >> setenv.sh - echo "export RESTORE_VERSION=$RESTORE_VERSION" >> setenv.sh - echo "export URL_DOMAIN=$URL_DOMAIN" >> setenv.sh - echo "export MYSQL_FILE_NAME=$MYSQL_FILE_NAME" >> setenv.sh - echo "export STATIC_FILE_NAME=$STATIC_FILE_NAME" >> setenv.sh - echo "export BITBUCKET_REPO_SLUG=$BITBUCKET_REPO_SLUG" >> setenv.sh artifacts: - setenv.sh - step: name: Deploy the wp source code trigger: manual image: atlassian/pipelines-awscli script: - source setenv.sh - chmod 755 ./common-jobs-bitbucket.sh && ./common-jobs-bitbucket.sh subdomain_deploy artifacts: - setenv.sh - step: name: Deploy the mysql database trigger: manual image: atlassian/pipelines-awscli script: - source setenv.sh - chmod 755 ./common-jobs-bitbucket.sh && ./common-jobs-bitbucket.sh mysql-restore $MYSQL_FILE_NAME artifacts: - setenv.sh - step: name: Deploy the static data trigger: manual image: atlassian/pipelines-awscli script: - source setenv.sh - chmod 755 ./common-jobs-bitbucket.sh && ./common-jobs-bitbucket.sh wp-data-restore $STATIC_FILE_NAME release: - !!merge <<: *set-variables - step: name: "plan for the release and tag the given version." image: atlassian/pipelines-awscli script: - echo "make sure that release version file and plan has been added to the release repo" - source release - export MANIFEST=$(aws ecr batch-get-image --repository-name medicalalert-web --image-ids imageTag=$VERSION --output json | jq --raw-output --join-output '.images[0].imageManifest') - aws ecr put-image --repository-name medicalalert-web --image-tag $RELEASE --image-manifest "$MANIFEST" && echo ------ image $VERSION has been retagged as $RELEASE || exit 9 - echo "export VERSION=$RELEASE" >> setenv.sh - echo "export ENV=stage" >> setenv.sh artifacts: # define the artifacts to be passed to each future step - setenv.sh - step: !!merge <<: *deploy deployment: stage name: "deploy the release to stage" trigger: manual - step: name: vars for prod script: - source release - echo "export VERSION=$RELEASE" >> setenv.sh - echo "export ENV=prod" >> setenv.sh artifacts: # define the artifacts to be passed to each future step - setenv.sh - step: !!merge <<: *deploy deployment: prod name: "deploy the release to production" trigger: manual pull-requests: develop: - step: name: build the application and push that to dev env. image: atlassian/default-image:3 script: - curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install - export BUILD_D=$BITBUCKET_BRANCH_$BITBUCKET_COMMIT_$BITBUCKET_BUILD_NUMBER - export IMAGE="medicalalert-web" && export VERSION=$BITBUCKET_BUILD_NUMBER - aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 716593996126.dkr.ecr.us-east-1.amazonaws.com - docker build -t ${IMAGE} . - docker tag ${IMAGE} ${IMAGE}:${VERSION} - pipe: atlassian/aws-ecr-push-image:1.6.2 variables: AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION IMAGE_NAME: $IMAGE TAGS: $VERSION services: - docker caches: - docker - step: name: vars for dev script: - echo "export VERSION=$BITBUCKET_BUILD_NUMBER" >> setenv.sh - echo "export ENV=dev" >> setenv.sh artifacts: # define the artifacts to be passed to each future step - setenv.sh - step: !!merge <<: *deploy deployment: dev name: "deploy to dev" - step: name: vars for qa script: - echo "export VERSION=$BITBUCKET_BUILD_NUMBER" >> setenv.sh - echo "export ENV=qa" >> setenv.sh artifacts: - setenv.sh - step: !!merge <<: *deploy deployment: qa name: "deploy to qa" trigger: manual