definitions: scripts: - script: &aws-context-dev export AWS_ROLE_ARN=arn:aws:iam::$AWS_ACCOUNT_NO:role/$OIDC_ROLE; export AWS_WEB_IDENTITY_TOKEN_FILE=$(pwd)/web-identity-token; echo $BITBUCKET_STEP_OIDC_TOKEN > $(pwd)/web-identity-token; export AWS_ACCESS_KEY_ID=$(echo $STS_OUTPUT | jq -r '.Credentials.AccessKeyId'); export AWS_SECRET_ACCESS_KEY=$(echo $STS_OUTPUT | jq -r '.Credentials.SecretAccessKey'); export AWS_SECURITY_TOKEN=$(echo $STS_OUTPUT | jq -r '.Credentials.SessionToken'); export AWS_REGION='us-east-2'; - script: &aws-context-uat export AWS_ROLE_ARN=arn:aws:iam::$AWS_ACCOUNT_NO_UAT:role/$OIDC_ROLE_UAT; export AWS_WEB_IDENTITY_TOKEN_FILE=$(pwd)/web-identity-token; echo $BITBUCKET_STEP_OIDC_TOKEN > $(pwd)/web-identity-token; export AWS_ACCESS_KEY_ID=$(echo $STS_OUTPUT | jq -r '.Credentials.AccessKeyId'); export AWS_SECRET_ACCESS_KEY=$(echo $STS_OUTPUT | jq -r '.Credentials.SecretAccessKey'); export AWS_SECURITY_TOKEN=$(echo $STS_OUTPUT | jq -r '.Credentials.SessionToken'); export AWS_REGION='us-east-2'; - script: &aws-context-prod export AWS_ROLE_ARN=arn:aws:iam::$AWS_ACCOUNT_NO_PROD:role/$OIDC_ROLE_PROD; export AWS_WEB_IDENTITY_TOKEN_FILE=$(pwd)/web-identity-token; echo $BITBUCKET_STEP_OIDC_TOKEN > $(pwd)/web-identity-token; export AWS_ACCESS_KEY_ID=$(echo $STS_OUTPUT | jq -r '.Credentials.AccessKeyId'); export AWS_SECRET_ACCESS_KEY=$(echo $STS_OUTPUT | jq -r '.Credentials.SecretAccessKey'); export AWS_SECURITY_TOKEN=$(echo $STS_OUTPUT | jq -r '.Credentials.SessionToken'); export AWS_REGION='us-east-2'; - script: &ssm-send-command-dev aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids $DEV_INSTANCE_ID_TF --region $AWS_DEFAULT_REGION --parameters commands='[ "sudo -u ubuntu -i < $(pwd)/web-identity-token - export STS_OUTPUT=$(aws sts assume-role-with-web-identity --role-arn $AWS_ROLE_ARN --role-session-name BitbucketPipeline --web-identity-token "$BITBUCKET_STEP_OIDC_TOKEN" --duration-seconds 3600) - export AWS_ACCESS_KEY_ID=$(echo $STS_OUTPUT | jq -r '.Credentials.AccessKeyId') - export AWS_SECRET_ACCESS_KEY=$(echo $STS_OUTPUT | jq -r '.Credentials.SecretAccessKey') - export AWS_SESSION_TOKEN=$(echo $STS_OUTPUT | jq -r '.Credentials.SessionToken') - aws sts get-caller-identity - aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids $DEV_INSTANCE_ID --region $AWS_DEFAULT_REGION --parameters commands='["cd /home/ubuntu/streamlit","su -l ubuntu","(if [ -d doczy.ai ]; then cd doczy.ai && git fetch && git pull; else git clone git@bitbucket.org:aarete/doczy.ai.git; fi)"]' trigger: automatic # uncomment after testing - step: &airflow_dags_deploy name: "Deploy Airflow DAGs to S3 bucket" image: python:3.8 oidc: true script: - python -m pip install --upgrade pip - apt-get update && apt-get install -y jq git - pip install awscli - export AWS_ROLE_ARN=arn:aws:iam::$AWS_ACCOUNT_NO:role/$OIDC_ROLE - export AWS_WEB_IDENTITY_TOKEN_FILE=$(pwd)/web-identity-token - echo $BITBUCKET_STEP_OIDC_TOKEN > $(pwd)/web-identity-token - export STS_OUTPUT=$(aws sts assume-role-with-web-identity --role-arn $AWS_ROLE_ARN --role-session-name BitbucketPipeline --web-identity-token "$BITBUCKET_STEP_OIDC_TOKEN" --duration-seconds 3600) - export AWS_ACCESS_KEY_ID=$(echo $STS_OUTPUT | jq -r '.Credentials.AccessKeyId') - export AWS_SECRET_ACCESS_KEY=$(echo $STS_OUTPUT | jq -r '.Credentials.SecretAccessKey') - export AWS_SESSION_TOKEN=$(echo $STS_OUTPUT | jq -r '.Credentials.SessionToken') - aws sts get-caller-identity - aws s3 sync ./airflow/dags s3://doczy-dev-infra-mwaa-resources/dags trigger: automatic # uncomment after testing pipelines: branches: DEV: - step: <<: *snowflake_deploy condition: changesets: includePaths: - snowflake/DEV/* - snowflake/DEV/**/* - snowflake/DEV/**/**/* - step: image: python:3.8 name: "Deploy streamlit to EC2" oidc: true script: - python -m pip install --upgrade pip - apt-get update && apt-get install -y jq git - pip install awscli - *aws-context-dev - *ssm-send-command-dev condition: changesets: includePaths: - streamlit/* - streamlit/**/* - step: <<: *airflow_dags_deploy condition: changesets: includePaths: - airflow/dags/* - step: name: Apply textract-pipeline on DEV image: hugree/terraform-with-snowsql:latest oidc: true script: - *aws-context-dev - pip install -r requirements.txt - python terraform.py apply --environment=dev --module=textract-pipeline/terraform - step: name: Apply devops-pipeline on DEV image: hugree/bitbucket-aws-python38-tf154:latest oidc: true script: - *aws-context-dev - pip install -r requirements.txt - python terraform.py apply --environment=dev --module=devops-pipeline/other-resources - step: name: Apply streamlit-server on DEV image: hugree/bitbucket-aws-python38-tf154:latest oidc: true script: - *aws-context-dev - pip install -r requirements.txt - python terraform.py apply --environment=dev --module=streamlit-server # UAT and PROD pipelines will be updated with Streamlit steps once it is tested and ready UAT: - step: name: Apply textract-pipeline on UAT image: hugree/terraform-with-snowsql:latest oidc: true script: - *aws-context-uat - pip install -r requirements.txt - python terraform.py apply --environment=uat --module=textract-pipeline/terraform - step: name: Apply devops-pipeline on UAT image: hugree/bitbucket-aws-python38-tf154:latest oidc: true script: - *aws-context-uat - pip install -r requirements.txt - python terraform.py apply --environment=uat --module=devops-pipeline/other-resources - step: name: Apply streamlit-server on UAT image: hugree/bitbucket-aws-python38-tf154:latest oidc: true script: - *aws-context-uat - pip install -r requirements.txt - python terraform.py apply --environment=uat --module=streamlit-server - step: <<: *snowflake_deploy condition: changesets: includePaths: - snowflake/UAT/* - snowflake/UAT/**/* - snowflake/UAT/**/**/* - step: image: python:3.8 name: "Deploy streamlit to EC2" oidc: true trigger: automatic # Keeping it manual as the server will be created first and then referenced in this script: - python -m pip install --upgrade pip - apt-get update && apt-get install -y jq git - pip install awscli - *aws-context-uat - *ssm-send-command-uat condition: changesets: includePaths: - streamlit/* - streamlit/**/* - step: <<: *airflow_dags_deploy trigger: manual condition: changesets: includePaths: - airflow/dags/* PROD: - step: name: Apply devops-pipeline on PROD image: hugree/bitbucket-aws-python38-tf154:latest oidc: true script: - *aws-context-prod - aws sts get-caller-identity --output text - pip install -r requirements.txt - BB_PIPELINE_BRANCH="PROD" python terraform.py apply --environment=prod --module=devops-pipeline/other-resources - step: name: Apply streamlit-server on PROD image: hugree/bitbucket-aws-python38-tf154:latest oidc: true script: - *aws-context-prod - pip install -r requirements.txt - BB_PIPELINE_BRANCH="PROD" python terraform.py apply --environment=prod --module=streamlit-server - step: name: Apply textract-pipeline on PROD image: hugree/terraform-with-snowsql:latest oidc: true script: - *aws-context-prod - pip install -r requirements.txt - BB_PIPELINE_BRANCH="PROD" python terraform.py apply --environment=prod --module=textract-pipeline/terraform - step: <<: *snowflake_deploy condition: changesets: includePaths: - snowflake/PROD/* - snowflake/PROD/**/* - snowflake/PROD/**/**/* - step: image: python:3.8 name: "Deploy streamlit to EC2" oidc: true trigger: automatic # Keeping it manual as the server will be created first and then referenced in this script: - python -m pip install --upgrade pip - apt-get update && apt-get install -y jq git - pip install awscli - *aws-context-prod - *ssm-send-command-prod condition: changesets: includePaths: - streamlit/* - streamlit/**/* - step: <<: *airflow_dags_deploy trigger: manual condition: changesets: includePaths: - airflow/dags/* feature/DOC-595-cicd-for-prod: - parallel: # - step: # name: Plan devops-pipeline on PROD # image: hugree/bitbucket-aws-python38-tf154:latest # oidc: true # script: # - *aws-context-prod # - aws sts get-caller-identity --output text # - pip install -r requirements.txt # - BB_PIPELINE_BRANCH="DEV" python terraform.py plan --environment=prod --module=devops-pipeline/other-resources # - step: # name: Plan streamlit-server on PROD # image: hugree/bitbucket-aws-python38-tf154:latest # oidc: true # script: # - *aws-context-prod # - pip install -r requirements.txt # - BB_PIPELINE_BRANCH="DEV" python terraform.py plan --environment=prod --module=streamlit-server # - step: # name: Plan textract-pipeline on PROD # image: hugree/terraform-with-snowsql:latest # oidc: true # script: # - *aws-context-prod # - pip install -r requirements.txt # - BB_PIPELINE_BRANCH="DEV" python terraform.py plan --environment=prod --module=textract-pipeline/terraform - step: name: Apply textract-pipeline on UAT image: hugree/terraform-with-snowsql:latest oidc: true script: - *aws-context-uat - pip install -r requirements.txt - BB_PIPELINE_BRANCH="DEV" python terraform.py apply --environment=uat --module=textract-pipeline/terraform feature/DOC-536-smart-git-diff: - parallel: - step: name: Plan devops-pipeline on DEV image: hugree/bitbucket-aws-python38-tf154:latest oidc: true script: - *aws-context-dev - pip install -r requirements.txt - BB_PIPELINE_BRANCH="DEV" python terraform.py plan --environment=dev --module=devops-pipeline/other-resources - step: name: Plan streamlit-server on DEV image: hugree/bitbucket-aws-python38-tf154:latest oidc: true script: - *aws-context-dev - pip install -r requirements.txt - BB_PIPELINE_BRANCH="DEV" python terraform.py plan --environment=dev --module=streamlit-server - step: name: Plan textract-pipeline on DEV image: hugree/terraform-with-snowsql:latest oidc: true script: - *aws-context-dev - pip install -r requirements.txt - BB_PIPELINE_BRANCH="DEV" python terraform.py plan --environment=dev --module=textract-pipeline/terraform - step: name: Plan devops-pipeline on UAT image: hugree/bitbucket-aws-python38-tf154:latest oidc: true script: - *aws-context-uat - pip install -r requirements.txt - BB_PIPELINE_BRANCH="UAT" python terraform.py plan --environment=uat --module=devops-pipeline/other-resources - step: name: Plan streamlit-server on UAT image: hugree/bitbucket-aws-python38-tf154:latest oidc: true script: - *aws-context-uat - pip install -r requirements.txt - BB_PIPELINE_BRANCH="UAT" python terraform.py plan --environment=uat --module=streamlit-server - step: name: Plan textract-pipeline on UAT image: hugree/bitbucket-aws-python38-tf154:latest oidc: true script: - *aws-context-uat - pip install -r requirements.txt - BB_PIPELINE_BRANCH="UAT" python terraform.py plan --environment=uat --module=textract-pipeline/terraform feature/DOC-535-snowsql-in-cicd: - parallel: - step: image: hugree/terraform-with-snowsql:latest name: Run Snowsql on DEV oidc: true script: - *aws-context-dev - pip install -r requirements.txt - IS_DEPLOY_ALL=true python terraform.py apply --environment=dev --module=textract-pipeline/terraform --apply-extra-args="-target=null_resource.snowsql_client_create" - step: image: hugree/terraform-with-snowsql:latest name: Run Snowsql on UAT oidc: true script: - *aws-context-uat - pip install -r requirements.txt - IS_DEPLOY_ALL=true python terraform.py apply --environment=uat --module=textract-pipeline/terraform --apply-extra-args="-target=null_resource.snowsql_client_create" feature/UAT-pdf-layer-test: - step: name: Apply textract-pipeline on UAT (pdf layer) image: hugree/bitbucket-aws-python38-tf154:latest oidc: true script: - *aws-context-uat - pip install -r requirements.txt - BB_PIPELINE_BRANCH="UAT" python terraform.py apply --environment=uat --module=textract-pipeline/terraform --apply-extra-args="-target=module.pdf_layer"