191 lines
6.5 KiB
YAML
191 lines
6.5 KiB
YAML
definitions:
|
|
scripts:
|
|
- script: &aws-context
|
|
apt-get update;
|
|
apt-get install -y jq;
|
|
pip install awscli;
|
|
export AWS_ROLE_ARN=arn:aws:iam::$AWS_ACCOUNT_NO:role/$OIDC_ROLE;
|
|
export AWS_ROLE_SESSION_NAME=$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';
|
|
aws sts get-caller-identity;
|
|
export IS_DEPLOY_ALL=true;
|
|
steps: &deployment-plan-steps
|
|
- step:
|
|
name: Plan devops-pipeline
|
|
image: hugree/bitbucket-aws-python38-tf154:latest
|
|
oidc: true
|
|
script:
|
|
- *aws-context
|
|
- pip install -r requirements.txt
|
|
- python terraform.py plan --environment=$ENVIRONMENT --module=devops-pipeline/other-resources
|
|
caches:
|
|
- pip
|
|
- step:
|
|
name: Plan textract-pipeline
|
|
image: hugree/terraform-with-snowsql:latest
|
|
oidc: true
|
|
script:
|
|
- *aws-context
|
|
- pip install -r requirements.txt
|
|
- python terraform.py plan --environment=$ENVIRONMENT --module=textract-pipeline/terraform
|
|
caches:
|
|
- pip
|
|
- step:
|
|
name: Plan streamlit-server
|
|
image: hugree/bitbucket-aws-python38-tf154:latest
|
|
oidc: true
|
|
script:
|
|
- *aws-context
|
|
- pip install -r requirements.txt
|
|
- python terraform.py plan --environment=$ENVIRONMENT --module=streamlit-server
|
|
caches:
|
|
- pip
|
|
- step:
|
|
image: hugree/terraform-with-snowsql:latest
|
|
name: Plan Snowsql
|
|
oidc: true
|
|
script:
|
|
- *aws-context
|
|
- pip install -r requirements.txt
|
|
- python terraform.py plan --environment=$ENVIRONMENT --module=textract-pipeline/terraform --apply-extra-args="-target=null_resource.snowsql_client_create"
|
|
caches:
|
|
- pip
|
|
steps: &deployment-steps
|
|
- step:
|
|
name: Apply devops-pipeline
|
|
image: hugree/bitbucket-aws-python38-tf154:latest
|
|
oidc: true
|
|
script:
|
|
- *aws-context
|
|
- pip install -r requirements.txt
|
|
- python terraform.py apply --environment=$ENVIRONMENT --module=devops-pipeline/other-resources
|
|
caches:
|
|
- pip
|
|
- step:
|
|
name: Apply textract-pipeline
|
|
image: hugree/terraform-with-snowsql:latest
|
|
oidc: true
|
|
script:
|
|
- *aws-context
|
|
- pip install -r requirements.txt
|
|
- python terraform.py apply --environment=$ENVIRONMENT --module=textract-pipeline/terraform
|
|
caches:
|
|
- pip
|
|
- step:
|
|
name: Apply streamlit-server
|
|
image: hugree/bitbucket-aws-python38-tf154:latest
|
|
oidc: true
|
|
script:
|
|
- *aws-context
|
|
- pip install -r requirements.txt
|
|
- python terraform.py apply --environment=$ENVIRONMENT --module=streamlit-server
|
|
caches:
|
|
- pip
|
|
- step:
|
|
name: "Deploy Snowflake Changes"
|
|
image: python:3.7
|
|
size: 2x
|
|
script:
|
|
- pip install snowflake-connector-python
|
|
- pip install schemachange --upgrade
|
|
- 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
|
|
caches:
|
|
- pip
|
|
- step:
|
|
image: hugree/terraform-with-snowsql:latest
|
|
name: Apply Snowsql
|
|
oidc: true
|
|
script:
|
|
- *aws-context
|
|
- pip install -r requirements.txt
|
|
- python terraform.py apply --environment=$ENVIRONMENT --module=textract-pipeline/terraform --apply-extra-args="-target=null_resource.snowsql_client_create"
|
|
caches:
|
|
- pip
|
|
- step:
|
|
image: python:3.8
|
|
name: "Deploy streamlit to EC2"
|
|
oidc: true
|
|
script:
|
|
- *aws-context
|
|
- apt-get install -y git
|
|
- >-
|
|
aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids $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"
|
|
]'
|
|
caches:
|
|
- pip
|
|
|
|
pipelines:
|
|
default:
|
|
- step:
|
|
image: python:3.8
|
|
name: Install Pip
|
|
script:
|
|
- python -m pip install --upgrade pip
|
|
caches:
|
|
- pip
|
|
- step:
|
|
name: Lint the code
|
|
image: hugree/bitbucket-aws-python38-tf154:latest
|
|
script:
|
|
- pip install -r dev-requirements.txt
|
|
- python -m black --check .
|
|
caches:
|
|
- pip
|
|
- stage:
|
|
name: deployment-dev
|
|
deployment: development
|
|
steps: *deployment-steps
|
|
branches:
|
|
main:
|
|
- step:
|
|
name: Build and Test
|
|
script:
|
|
- echo Build and test pipeline will go here
|
|
- stage:
|
|
name: deployment-dev-plan
|
|
deployment: development-plan
|
|
steps: *deployment-plan-steps
|
|
- stage:
|
|
name: deployment-dev
|
|
deployment: development
|
|
steps: *deployment-steps
|
|
- stage:
|
|
name: deployment-plan-prod
|
|
deployment: test-production-plan
|
|
trigger: manual
|
|
steps: *deployment-plan-steps
|
|
- stage:
|
|
name: deployment-prod
|
|
deployment: test-production
|
|
trigger: manual
|
|
steps: *deployment-steps
|
|
- stage:
|
|
name: deployment-plan-uat
|
|
deployment: uat-plan
|
|
trigger: manual
|
|
steps: *deployment-plan-steps
|
|
- stage:
|
|
name: deployment-uat
|
|
deployment: uat
|
|
trigger: manual
|
|
steps: *deployment-steps
|
|
- stage:
|
|
name: deployment-plan-prod
|
|
deployment: production-plan
|
|
trigger: manual
|
|
steps: *deployment-plan-steps
|
|
- stage:
|
|
name: deployment-prod
|
|
deployment: production
|
|
trigger: manual
|
|
steps: *deployment-steps |