From 8cf1b4b4d6c169f51118c39be15b08686c6ccde9 Mon Sep 17 00:00:00 2001 From: Michael McGuinness Date: Mon, 23 Sep 2024 16:28:03 +0100 Subject: [PATCH] fullrambo --- bitbucket-pipelines.yml | 185 +++++++++++++++++++++++++++++++--------- pipelines/example.yml | 12 --- 2 files changed, 146 insertions(+), 51 deletions(-) delete mode 100644 pipelines/example.yml diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index b37213c..0c93cc6 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -1,49 +1,156 @@ -export: true - definitions: - stage: &example + scripts: + - script: &aws-context + export AWS_ROLE_ARN=arn:aws:iam::$AWS_ACCOUNT_NO:role/$AWS_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'; + stage: &deployment name: deployment + deployment: development + trigger: manual + environment: + SNOWFLAKE_DATABASE: $DEV_SNOWFLAKE_DATABASE + SNOWFLAKE_ROLE: $DEV_SNOWFLAKE_ROLE + AWS_IODC_ROLE: $IODC_ROLE + INSTANCE_ID_TF: $DEV_INSTANCE_ID_TF + IS_DEPLOY_ALL: true + BB_PIPELINE_BRANCH: $BITBUCKET_BRANCH + ENVIRONMENT: dev + steps: + - step: + 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 + - 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 + condition: + changesets: + includePaths: + - snowflake/**/* + - snowflake/**/**/* + - snowflake/**/**/**/* + - 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 + - aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids $INSTANCE_ID_TF --region $AWS_DEFAULT_REGION --parameters commands='[ + "sudo -u ubuntu -i <