Files
doczyai-pipelines/bitbucket-pipelines.yml
T

285 lines
13 KiB
YAML
Raw Normal View History

2024-02-06 16:29:58 -06:00
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;
2024-06-06 10:07:22 +02:00
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';
2024-05-29 16:21:58 -05:00
- script: &ssm-send-command-dev
2024-05-23 15:33:19 -05:00
aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids $DEV_INSTANCE_ID_TF --region $AWS_DEFAULT_REGION --parameters commands='[
"sudo -u ubuntu -i <<EOF",
"export HOME=/home/ubuntu",
"git config --global --add safe.directory /home/ubuntu/doczy.ai",
"if [ -d /home/ubuntu/doczy.ai ]; then cd /home/ubuntu/doczy.ai && git fetch && git pull; else cd /home/ubuntu && git clone git@bitbucket.org:aarete/doczy.ai.git; fi",
"EOF"
]'
2024-05-29 16:21:58 -05:00
- script: &ssm-send-command-uat
aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids $UAT_INSTANCE_ID_TF --region $AWS_DEFAULT_REGION --parameters commands='[
"sudo -u ubuntu -i <<EOF",
"export HOME=/home/ubuntu",
"git config --global --add safe.directory /home/ubuntu/doczy.ai",
"if [ -d /home/ubuntu/doczy.ai ]; then cd /home/ubuntu/doczy.ai && git fetch && git pull; else cd /home/ubuntu && git clone git@bitbucket.org:aarete/doczy.ai.git; fi",
"EOF"
]'
2024-05-23 15:33:19 -05:00
2024-04-22 12:09:15 -05:00
- step: &snowflake_deploy
name: "Deploy Snowflake Changes"
image: python:3.7
size: 2x
script:
- python -m pip install --upgrade pip
- pip install snowflake-connector-python
- pip install schemachange --upgrade
# Setting the database name dynamically based on the branch name
- if [ "$BITBUCKET_BRANCH" == "DEV" ]; then export SNOWFLAKE_DATABASE=$DEV_SNOWFLAKE_DATABASE; export SNOWFLAKE_ROLE=$DEV_SNOWFLAKE_ROLE; fi
- if [ "$BITBUCKET_BRANCH" == "UAT" ]; then export SNOWFLAKE_DATABASE=$UAT_SNOWFLAKE_DATABASE; export SNOWFLAKE_ROLE=$UAT_SNOWFLAKE_ROLE; fi
- if [ "$BITBUCKET_BRANCH" == "PROD" ]; then export SNOWFLAKE_DATABASE=$PROD_SNOWFLAKE_DATABASE; export SNOWFLAKE_ROLE=$PROD_SNOWFLAKE_ROLE; fi
- schemachange -a $SNOWFLAKE_ACCOUNT -u $SNOWFLAKE_USER -r $SNOWFLAKE_ROLE -w $SNOWFLAKE_WAREHOUSE -d $SNOWFLAKE_DATABASE -c $SNOWFLAKE_DATABASE.SCHEMACHANGE.CHANGE_HISTORY --create-change-history-table -v
trigger: automatic
# trigger: manual
caches:
- pip
- step: &streamlit_deploy
name: "Deploy streamlit to EC2"
2024-03-06 16:24:13 -06:00
oidc: true
image: python:3.8
script:
2024-06-06 10:07:22 +02:00
- 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
2024-06-06 10:07:22 +02:00
- 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
2024-04-22 12:05:56 -05:00
- 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
2024-03-06 16:24:13 -06:00
oidc: true
script:
2024-06-06 10:07:22 +02:00
- 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
2024-06-06 10:07:22 +02:00
- 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
2024-06-06 10:07:22 +02:00
- aws s3 sync ./airflow/dags s3://doczy-dev-infra-mwaa-resources/dags
trigger: automatic # uncomment after testing
2024-02-06 16:29:58 -06:00
pipelines:
branches:
2024-06-06 10:07:22 +02:00
DEV:
2024-02-06 16:29:58 -06:00
- step:
<<: *snowflake_deploy
condition:
2024-02-12 12:18:38 -06:00
changesets:
includePaths:
- snowflake/DEV/*
- snowflake/DEV/**/*
- snowflake/DEV/**/**/*
- step:
2024-05-23 15:33:19 -05:00
image: python:3.8
name: "Deploy streamlit to EC2"
oidc: true
script:
2024-06-06 10:07:22 +02:00
- python -m pip install --upgrade pip
2024-05-23 15:33:19 -05:00
- apt-get update && apt-get install -y jq git
- pip install awscli
2024-05-23 15:34:16 -05:00
- *aws-context-dev
2024-05-29 16:21:58 -05:00
- *ssm-send-command-dev
condition:
changesets:
includePaths:
2024-05-23 15:33:19 -05:00
- streamlit/*
- streamlit/**/*
- step:
<<: *airflow_dags_deploy
condition:
changesets:
includePaths:
- airflow/dags/*
2024-04-25 15:33:42 -05:00
- step:
name: Apply textract-pipeline on DEV
2024-06-26 11:37:05 +02:00
image: hugree/terraform-with-snowsql:latest
oidc: true
script:
- *aws-context-dev
2024-06-26 11:25:27 +02:00
- 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
2024-06-26 11:25:27 +02:00
- 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
2024-06-26 11:25:27 +02:00
- pip install -r requirements.txt
- python terraform.py apply --environment=dev --module=streamlit-server
2024-06-06 10:07:22 +02:00
2024-03-11 17:36:57 -05:00
# UAT and PROD pipelines will be updated with Streamlit steps once it is tested and ready
UAT:
2024-02-06 16:29:58 -06:00
- step:
name: Apply textract-pipeline on UAT
2024-06-26 11:37:05 +02:00
image: hugree/terraform-with-snowsql:latest
oidc: true
script:
- *aws-context-uat
2024-06-26 11:25:27 +02:00
- 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
2024-06-26 11:25:27 +02:00
- 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
2024-06-26 11:25:27 +02:00
- 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:
2024-05-29 16:21:58 -05:00
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
2024-05-29 16:21:58 -05:00
script:
2024-06-06 10:07:22 +02:00
- python -m pip install --upgrade pip
2024-05-29 16:21:58 -05:00
- apt-get update && apt-get install -y jq git
- pip install awscli
2024-06-03 16:25:37 -05:00
- *aws-context-uat
2024-05-29 16:21:58 -05:00
- *ssm-send-command-uat
condition:
changesets:
includePaths:
2024-05-29 16:21:58 -05:00
- streamlit/*
- streamlit/**/*
- step:
<<: *airflow_dags_deploy
trigger: manual
condition:
changesets:
includePaths:
- airflow/dags/*
PROD:
2024-02-06 16:29:58 -06:00
- step:
<<: *snowflake_deploy
condition:
paths:
- snowflake/**/*.sql
2024-06-06 09:54:14 +02:00
feature/DOC-536-smart-git-diff:
2024-06-06 09:54:14 +02:00
- 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
2024-06-06 09:54:14 +02:00
- step:
name: Plan streamlit-server on DEV
2024-06-06 09:56:19 +02:00
image: hugree/bitbucket-aws-python38-tf154:latest
2024-06-06 09:54:14 +02:00
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
2024-06-26 11:37:05 +02:00
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
2024-06-06 17:18:40 +02:00
- 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
2024-06-06 09:54:14 +02:00
- step:
name: Plan streamlit-server on UAT
2024-06-06 09:56:19 +02:00
image: hugree/bitbucket-aws-python38-tf154:latest
2024-06-06 09:54:14 +02:00
oidc: true
script:
- *aws-context-uat
- pip install -r requirements.txt
- BB_PIPELINE_BRANCH="UAT" python terraform.py plan --environment=uat --module=streamlit-server
2024-06-06 17:18:40 +02:00
- 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:
2024-06-25 16:11:07 +02:00
- parallel:
2024-06-25 17:58:33 +02:00
- step:
image: hugree/terraform-with-snowsql:latest
name: Run Snowsql on DEV
oidc: true
script:
- *aws-context-dev
2024-06-26 11:25:59 +02:00
- pip install -r requirements.txt
2024-06-25 17:58:33 +02:00
- IS_DEPLOY_ALL=true python terraform.py apply --environment=dev --module=textract-pipeline/terraform --apply-extra-args="-target=null_resource.snowsql_client_create"
2024-06-25 16:11:07 +02:00
2024-06-25 17:58:33 +02:00
- step:
image: hugree/terraform-with-snowsql:latest
name: Run Snowsql on UAT
oidc: true
script:
- *aws-context-uat
2024-06-26 11:25:59 +02:00
- pip install -r requirements.txt
2024-06-25 17:58:33 +02:00
- IS_DEPLOY_ALL=true python terraform.py apply --environment=uat --module=textract-pipeline/terraform --apply-extra-args="-target=null_resource.snowsql_client_create"