Skip to content

Commit e577691

Browse files
Update main.yml
1 parent 1cbce16 commit e577691

File tree

1 file changed

+72
-43
lines changed

1 file changed

+72
-43
lines changed

.github/workflows/main.yml

Lines changed: 72 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,94 @@
1-
name: Deploy MediaLake
1+
name: Validate and Deploy Python CDK
2+
3+
permissions:
4+
id-token: write
5+
contents: read
26

37
on:
4-
push:
5-
branches: [ main ]
68
pull_request:
7-
branches: [ main ]
8-
workflow_dispatch:
9-
10-
env:
11-
AWS_REGION: us-east-1
9+
types: [opened, synchronize, reopened]
1210

1311
jobs:
1412
deploy:
1513
runs-on: ubuntu-latest
16-
permissions:
17-
id-token: write
18-
contents: read
19-
14+
2015
steps:
21-
- name: Checkout code
16+
- name: Checkout PR branch
2217
uses: actions/checkout@v4
23-
24-
- name: Setup Python
25-
uses: actions/setup-python@v4
18+
with:
19+
ref: ${{ github.head_ref }}
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v5
2623
with:
2724
python-version: '3.11'
28-
29-
- name: Install dependencies
30-
run: |
31-
python -m pip install --upgrade pip
32-
pip install aws-cdk-lib constructs
33-
34-
- name: Configure AWS credentials
25+
26+
- name: Set up Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: '20'
30+
31+
- name: Install AWS CDK CLI
32+
run: npm install -g aws-cdk
33+
34+
- name: Configure AWS credentials (OIDC)
3535
uses: aws-actions/configure-aws-credentials@v4
3636
with:
37-
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/GitHubActionsRole
38-
aws-region: ${{ env.AWS_REGION }}
39-
40-
- name: Create config file if not exists
37+
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/Github
38+
aws-region: us-west-2
39+
40+
- name: Set up Python virtual environment
41+
run: python -m venv .venv
42+
43+
- name: Upgrade pip
44+
run: |
45+
source .venv/bin/activate
46+
pip install --upgrade pip
47+
48+
- name: Install jq and moreutils
49+
run: |
50+
sudo apt-get update
51+
sudo apt-get install -y jq moreutils
52+
53+
- name: Patch config.json with jq
54+
env:
55+
MediaLakeEnvironmentName: dev
56+
InitialUserEmail: 'medialake+test@amazon.com'
57+
InitialUserFirstName: 'Medialake'
58+
InitialUserLastName: 'User'
59+
OpenSearchDeploymentSize: 'large'
4160
run: |
4261
if [ -f guidance-for-medialake-on-aws/config.json ]; then
43-
echo "Config file already exists"
62+
echo "Using existing config file";
4463
else
45-
echo "Creating config file"
46-
cp .cicd/template/config.json-template guidance-for-medialake-on-aws/config.json
47-
# Update the config with environment-specific values
48-
sed -i 's/"region": "us-east-1"/"region": "${{ env.AWS_REGION }}"/' guidance-for-medialake-on-aws/config.json
49-
sed -i 's/"account": "123456789012"/"account": "${{ secrets.AWS_ACCOUNT_ID }}"/' guidance-for-medialake-on-aws/config.json
64+
echo "Creating config file";
65+
cp guidance-for-medialake-on-aws/.cicd/config.json-template guidance-for-medialake-on-aws/config.json;
5066
fi
51-
52-
- name: CDK Bootstrap (if needed)
67+
68+
AWS_ACCOUNT_ID="$(aws sts get-caller-identity --query Account --output text)"
69+
AWS_REGION="$(aws configure get region || echo 'us-west-2')"
70+
71+
jq --arg e "$MediaLakeEnvironmentName" '.environment = $e' guidance-for-medialake-on-aws/config.json | sponge guidance-for-medialake-on-aws/config.json
72+
jq --arg a "$AWS_ACCOUNT_ID" '.account_id = $a' guidance-for-medialake-on-aws/config.json | sponge guidance-for-medialake-on-aws/config.json
73+
jq --arg r "$AWS_REGION" '.primary_region = $r' guidance-for-medialake-on-aws/config.json | sponge guidance-for-medialake-on-aws/config.json
74+
jq --arg u "$InitialUserEmail" '.initial_user.email = $u' guidance-for-medialake-on-aws/config.json | sponge guidance-for-medialake-on-aws/config.json
75+
jq --arg f "$InitialUserFirstName" '.initial_user.first_name = $f' guidance-for-medialake-on-aws/config.json | sponge guidance-for-medialake-on-aws/config.json
76+
jq --arg l "$InitialUserLastName" '.initial_user.last_name = $l' guidance-for-medialake-on-aws/config.json | sponge guidance-for-medialake-on-aws/config.json
77+
jq --arg s "$OpenSearchDeploymentSize" '.opensearch_deployment_size = $s' guidance-for-medialake-on-aws/config.json | sponge guidance-for-medialake-on-aws/config.json
78+
79+
- name: Install CDK project dependencies
5380
run: |
54-
cd guidance-for-medialake-on-aws
55-
npx cdk bootstrap
56-
57-
- name: CDK Deploy
81+
source .venv/bin/activate
82+
pip install -r guidance-for-medialake-on-aws/requirements.txt
83+
84+
- name: Synthesize CDK stacks
5885
run: |
86+
source .venv/bin/activate
5987
cd guidance-for-medialake-on-aws
60-
npx cdk deploy --all --require-approval never
61-
62-
- name: Run tests
88+
cdk synth
89+
90+
- name: Deploy all CDK stacks
6391
run: |
92+
source .venv/bin/activate
6493
cd guidance-for-medialake-on-aws
65-
python -m pytest tests/ -v
94+
cdk deploy --all --require-approval=never

0 commit comments

Comments
 (0)