Apply validations

This commit is contained in:
Jay Sharma
2023-10-05 21:56:11 +05:30
parent 599ceff274
commit 7b3f2d4ff0
11 changed files with 425 additions and 87 deletions

View File

@@ -4,18 +4,44 @@ definitions:
- name: VERSION
default: "latest"
set-variables-jobs: &set-variables-jobs
set-variables-jobs: &set-variables-jobs-dev
- variables:
- name: ENV
default: "dev"
allowed-values: # Optionally restrict variable values
- "dev"
- name: JOBNAME
default: "mysql-backup"
allowed-values: # Optionally restrict variable values
- "wp-auto-patch"
- "mysql-backup"
- "wp-data-backup"
- "mysql-restore"
- "wp-data-restore"
- name: SUBDOMAIN
default: dev01
allowed-values: # Optionally restrict variable values
- "dev01"
- "www"
- "dev02"
- "dev03"
- "dev04"
- "dev05"
- name: RESTORE_VERSION
default: "PASTE_RESTORE_VERSION_FILE_NAME"
set-variables-jobs: &set-variables-jobs
- variables:
- name: ENV
default: "qa"
allowed-values: # Optionally restrict variable values
- "qa"
- "stage"
- "prod"
- name: JOBNAME
default: "mysql-backup"
allowed-values: # Optionally restrict variable values
- "wp-auto-patch"
- "mysql-backup"
- "wp-data-backup"
- "mysql-restore"
@@ -24,14 +50,10 @@ definitions:
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
@@ -51,7 +73,6 @@ definitions:
- name: STATIC_FILE_NAME
default: "STATIC_FILE_NAME_TO_DEPLOY"
steps:
- step: &deploy
name: deploy to $ENV environment
@@ -63,8 +84,10 @@ definitions:
- source setenv.sh
- fi
- echo "This is for $ENV environment"
- chmod 755 ./validation.sh && ./validation.sh default && echo validation-done || exit 9
- ls -lrth && cd build/${ENV}
- curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install
- curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x ./kubectl && mv ./kubectl /usr/local/bin/kubectl
- 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
@@ -80,43 +103,45 @@ definitions:
KUBECTL_ARGS: ""
KUBECTL_APPLY_ARGS: "-f"
DEBUG: "true"
after-script:
- aws eks update-kubeconfig --name caresage-eks-cluster-$ENV --region us-east-1
- sleep 10 && while kubectl get po -A |egrep -i '0/1|crash'; do sleep 10; echo "--- still getting 0/1 or crash pods | fix the issue"; done
pipelines:
# our custom pipeline, what shows up Bitbucket web app
custom:
deploy-dev:
- !!merge <<: *set-variables
- <<: *set-variables
- step:
!!merge <<: *deploy
<<: *deploy
deployment: dev
name: "deploy to dev"
deploy-qa:
- !!merge <<: *set-variables
- <<: *set-variables
- step:
!!merge <<: *deploy
<<: *deploy
deployment: qa
name: "deploy to qa"
release-stg:
- !!merge <<: *set-variables
- <<: *set-variables
- step:
!!merge <<: *deploy
<<: *deploy
deployment: stage
name: "deploy to stage"
release-prod:
- !!merge <<: *set-variables
- <<: *set-variables
- step:
!!merge <<: *deploy
<<: *deploy
deployment: prod
name: "deploy to prod"
common-jobs:
- !!merge <<: *set-variables-jobs
common-jobs-dev:
- <<: *set-variables-jobs-dev
- step:
name: vars for common-jobs
name: vars for common-jobs-dev
script:
- echo "export JOBNAME=$JOBNAME" >> setenv.sh
- echo "export ENV=$ENV" >> setenv.sh
@@ -124,7 +149,35 @@ pipelines:
- 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
- echo "export BITBUCKET_REPO_SLUG=$BITBUCKET_REPO_SLUG" >> setenv.sh
- echo "export TOKEN=$TOKEN" >> 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 DEV
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
common-jobs:
- <<: *set-variables-jobs
- step:
name: vars for common-jobs qa/stage/prod
script:
- 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
- echo "export TOKEN=$TOKEN" >> setenv.sh
artifacts: # define the artifacts to be passed to each future step
- setenv.sh
@@ -138,9 +191,8 @@ pipelines:
- 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
- <<: *set-variables-subdomain
- step:
name: vars for subdomain
script:
@@ -152,7 +204,8 @@ pipelines:
- 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
- echo "export BITBUCKET_REPO_SLUG=$BITBUCKET_REPO_SLUG" >> setenv.sh
- echo "export TOKEN=$TOKEN" >> setenv.sh
artifacts:
- setenv.sh
@@ -187,11 +240,12 @@ pipelines:
release:
- !!merge <<: *set-variables
- <<: *set-variables
- step:
name: "plan for the release and tag the given version."
image: atlassian/pipelines-awscli
script:
- chmod 755 ./validation.sh && ./validation.sh default
- 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')
@@ -201,7 +255,7 @@ pipelines:
artifacts: # define the artifacts to be passed to each future step
- setenv.sh
- step:
!!merge <<: *deploy
<<: *deploy
deployment: stage
name: "deploy the release to stage"
trigger: manual
@@ -214,7 +268,7 @@ pipelines:
artifacts: # define the artifacts to be passed to each future step
- setenv.sh
- step:
!!merge <<: *deploy
<<: *deploy
deployment: prod
name: "deploy the release to production"
trigger: manual
@@ -225,6 +279,7 @@ pipelines:
name: build the application and push that to dev env.
image: atlassian/default-image:3
script:
- chmod 755 ./validation.sh && ./validation.sh default
- 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
@@ -251,7 +306,7 @@ pipelines:
artifacts: # define the artifacts to be passed to each future step
- setenv.sh
- step:
!!merge <<: *deploy
<<: *deploy
deployment: dev
name: "deploy to dev"
- step:
@@ -262,7 +317,7 @@ pipelines:
artifacts:
- setenv.sh
- step:
!!merge <<: *deploy
<<: *deploy
deployment: qa
name: "deploy to qa"
trigger: manual