Skip to content

Commit 85bdb7f

Browse files
authored
New: [AEA-4684] - VPC resources (#9)
1 parent 16b2fc5 commit 85bdb7f

24 files changed

+1396
-223
lines changed

.devcontainer/devcontainer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@
5757
"editor.formatOnSave": true, // optional
5858
"editor.formatOnSaveMode": "file",
5959
"cSpell.words": ["fhir", "Formik", "pino", "serialisation"],
60-
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
61-
60+
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
61+
"[typescript]": {
62+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
63+
},
64+
"editor.codeActionsOnSave": {
65+
"source.fixAll.eslint": "always"
66+
}
6267
}
6368
}
6469
},
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
echo "calling mark jira released"
4+
5+
cat <<EOF > payload.json
6+
{
7+
"releaseVersion": "EPS-VPC-Resources-$RELEASE_TAG"
8+
}
9+
EOF
10+
cat payload.json
11+
12+
function_arn=$(aws cloudformation list-exports --query "Exports[?Name=='release-notes:MarkJiraReleasedLambdaArn'].Value" --output text)
13+
aws lambda invoke --function-name "${function_arn}" --cli-binary-format raw-in-base64-out --payload file://payload.json out.txt
14+
cat out.txt
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
cat <<EOF > payload.json
4+
{
5+
"currentTag": "$CURRENT_DEPLOYED_TAG",
6+
"targetTag": "$DEV_TAG",
7+
"repoName": "eps-vpc-resources",
8+
"targetEnvironment": "$ENV",
9+
"productName": "EPS VPC Resources",
10+
"releaseNotesPageId": "$PAGE_ID",
11+
"releaseNotesPageTitle": "Current EPS VPC Resources release notes - $ENV"
12+
}
13+
EOF
14+
cat payload.json
15+
16+
function_arn=$(aws cloudformation list-exports --query "Exports[?Name=='release-notes:CreateReleaseNotesLambdaArn'].Value" --output text)
17+
aws lambda invoke --function-name "${function_arn}" --cli-binary-format raw-in-base64-out --payload file://payload.json out.txt
18+
cat out.txt
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
cat <<EOF > payload.json
4+
{
5+
"currentTag": "$CURRENT_DEPLOYED_TAG",
6+
"targetTag": "$RELEASE_TAG",
7+
"repoName": "eps-vpc-resources",
8+
"targetEnvironment": "INT",
9+
"productName": "EPS VPC Resources",
10+
"releaseNotesPageId": "$PAGE_ID",
11+
"releaseNotesPageTitle": "EPS-VPC-Resources-$RELEASE_TAG - Deployed to [INT] on $(date +'%d-%m-%y')",
12+
"createReleaseCandidate": "true",
13+
"releasePrefix": "EPS-VPC-Resources-"
14+
}
15+
EOF
16+
cat payload.json
17+
18+
function_arn=$(aws cloudformation list-exports --query "Exports[?Name=='release-notes:CreateReleaseNotesLambdaArn'].Value" --output text)
19+
aws lambda invoke --function-name "${function_arn}" --cli-binary-format raw-in-base64-out --payload file://payload.json out.txt
20+
cat out.txt
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
dev_tag=$(aws cloudformation describe-stacks --stack-name vpc-resources --query "Stacks[0].Tags[?Key=='version'].Value" --output text)
4+
5+
echo "DEV_TAG=${dev_tag}" >> "$GITHUB_ENV"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
current_deployed_tag=$(aws cloudformation describe-stacks --stack-name vpc-resources --query "Stacks[0].Tags[?Key=='version'].Value" --output text)
4+
5+
if [ -z "$current_deployed_tag" ]
6+
then
7+
current_deployed_tag=v1.0.0-beta
8+
fi
9+
10+
echo "CURRENT_DEPLOYED_TAG=${current_deployed_tag}" >> "$GITHUB_ENV"
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: cdk package code
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
VERSION_NUMBER:
7+
required: true
8+
type: string
9+
COMMIT_ID:
10+
required: true
11+
type: string
12+
13+
14+
jobs:
15+
package_code:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
id-token: write
19+
contents: read
20+
packages: read
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
with:
25+
ref: ${{ env.BRANCH_NAME }}
26+
27+
# using git commit sha for version of action to ensure we have stable version
28+
- name: Install asdf
29+
uses: asdf-vm/actions/setup@05e0d2ed97b598bfce82fd30daf324ae0c4570e6
30+
with:
31+
asdf_branch: v0.14.1
32+
33+
- name: Cache asdf
34+
uses: actions/cache@v4
35+
with:
36+
path: |
37+
~/.asdf
38+
key: ${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }}
39+
restore-keys: |
40+
${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }}
41+
42+
- name: Install asdf dependencies in .tool-versions
43+
uses: asdf-vm/actions/install@05e0d2ed97b598bfce82fd30daf324ae0c4570e6
44+
with:
45+
asdf_branch: v0.14.1
46+
env:
47+
PYTHON_CONFIGURE_OPTS: --enable-shared
48+
49+
- name: make install
50+
run: |
51+
make install
52+
make compile-node
53+
54+
- name: 'Tar files'
55+
run: |
56+
tar -rf artifact.tar \
57+
.tool-versions \
58+
packages \
59+
node_modules \
60+
package.json \
61+
package-lock.json \
62+
tsconfig.defaults.json \
63+
Makefile \
64+
cdk.json
65+
66+
- uses: actions/upload-artifact@v4
67+
name: upload build artifact
68+
with:
69+
name: build_artifact
70+
path: artifact.tar
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
name: cdk release code
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
TARGET_ENVIRONMENT:
7+
required: true
8+
type: string
9+
VERSION_NUMBER:
10+
required: true
11+
type: string
12+
COMMIT_ID:
13+
required: true
14+
type: string
15+
LOG_RETENTION_IN_DAYS:
16+
required: true
17+
type: string
18+
secrets:
19+
CLOUD_FORMATION_DEPLOY_ROLE:
20+
required: true
21+
CDK_PULL_IMAGE_ROLE:
22+
required: true
23+
jobs:
24+
release_code:
25+
runs-on: ubuntu-latest
26+
environment: ${{ inputs.TARGET_ENVIRONMENT }}
27+
name: deploy cdk app
28+
permissions:
29+
id-token: write
30+
contents: write
31+
32+
steps:
33+
- name: Checkout local github actions
34+
uses: actions/checkout@v4
35+
with:
36+
ref: ${{ env.BRANCH_NAME }}
37+
fetch-depth: 0
38+
sparse-checkout: |
39+
.github
40+
41+
- name: Configure AWS Credentials
42+
id: connect-aws-pull-image
43+
uses: aws-actions/configure-aws-credentials@v4
44+
with:
45+
aws-region: eu-west-2
46+
role-to-assume: ${{ secrets.CDK_PULL_IMAGE_ROLE }}
47+
role-session-name: eps-vpc-resources-pull-image
48+
49+
- name: build_artifact download
50+
uses: actions/download-artifact@v4
51+
with:
52+
name: build_artifact
53+
54+
- name: extract build_artifact
55+
run: |
56+
mkdir -p .build
57+
tar -xf artifact.tar -C .build
58+
59+
- name: Retrieve AWS Account ID
60+
id: retrieve-account-id
61+
run: echo "ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)" >> "$GITHUB_ENV"
62+
63+
- name: Login to Amazon ECR
64+
id: login-ecr
65+
run: |
66+
aws ecr get-login-password --region eu-west-2 | docker login --username AWS --password-stdin ${{ env.ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com
67+
68+
- name: Pull cdk-utils-build from Amazon ECR
69+
run: |
70+
docker pull "${{ env.ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com/cdk-utils-build-repo:latest"
71+
docker tag "${{ env.ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com/cdk-utils-build-repo:latest" cdk-utils-build-repo:latest
72+
73+
- name: Configure AWS Credentials
74+
id: connect-aws
75+
uses: aws-actions/configure-aws-credentials@v4
76+
with:
77+
aws-region: eu-west-2
78+
role-to-assume: ${{ secrets.CLOUD_FORMATION_DEPLOY_ROLE }}
79+
role-session-name: eps-vpc-resources-deployment
80+
output-credentials: true
81+
82+
- name: fix cdk.json for deployment
83+
run: |
84+
jq \
85+
--arg VERSION_NUMBER "${{ inputs.VERSION_NUMBER }}" \
86+
--arg COMMIT_ID "${{ inputs.COMMIT_ID }}" \
87+
--arg logRetentionInDays "${{ inputs.LOG_RETENTION_IN_DAYS }}" \
88+
'.context += {
89+
"VERSION_NUMBER": $VERSION_NUMBER,
90+
"COMMIT_ID": $COMMIT_ID,
91+
"logRetentionInDays": $logRetentionInDays}' \
92+
.build/cdk.json > .build/cdk.new.json
93+
mv .build/cdk.new.json .build/cdk.json
94+
95+
- name: Show diff
96+
run: |
97+
docker run \
98+
-v "$(pwd)/.build":/home/cdkuser/workspace/ \
99+
-e AWS_ACCESS_KEY_ID=${{ steps.connect-aws.outputs.aws-access-key-id }} \
100+
-e AWS_SECRET_ACCESS_KEY=${{ steps.connect-aws.outputs.aws-secret-access-key }} \
101+
-e AWS_SESSION_TOKEN=${{ steps.connect-aws.outputs.aws-session-token }} \
102+
-e AWS_REGION="eu-west-2" \
103+
-e SHOW_DIFF="true" \
104+
-e DEPLOY_CODE="false" \
105+
-e CDK_APP_PATH="packages/cdk/bin/VpcResourcesApp.ts" \
106+
cdk-utils-build-repo:latest
107+
shell: bash
108+
109+
- name: Deploy code
110+
run: |
111+
docker run \
112+
-v "$(pwd)/.build":/home/cdkuser/workspace/ \
113+
-e AWS_ACCESS_KEY_ID=${{ steps.connect-aws.outputs.aws-access-key-id }} \
114+
-e AWS_SECRET_ACCESS_KEY=${{ steps.connect-aws.outputs.aws-secret-access-key }} \
115+
-e AWS_SESSION_TOKEN=${{ steps.connect-aws.outputs.aws-session-token }} \
116+
-e AWS_REGION="eu-west-2" \
117+
-e SHOW_DIFF="false" \
118+
-e DEPLOY_CODE="true" \
119+
-e CDK_APP_PATH="packages/cdk/bin/VpcResourcesApp.ts" \
120+
cdk-utils-build-repo:latest
121+
shell: bash
122+
123+
update_github_pages:
124+
runs-on: ubuntu-latest
125+
environment: ${{ inputs.TARGET_ENVIRONMENT }}
126+
if: ${{ always() && !failure() && !cancelled() }}
127+
needs: [release_code]
128+
permissions:
129+
id-token: write
130+
contents: write
131+
steps:
132+
- name: Checkout gh-pages
133+
uses: actions/checkout@v4
134+
with:
135+
ref: gh-pages
136+
path: gh-pages
137+
138+
- name: update release tag in github pages
139+
run: |
140+
cd gh-pages
141+
NOW=$(date +'%Y-%m-%dT%H:%M:%S')
142+
echo "tag,release_datetime" > _data/${{ inputs.TARGET_ENVIRONMENT }}_latest.csv
143+
echo "${{ inputs.VERSION_NUMBER }},${NOW}" >> _data/${{ inputs.TARGET_ENVIRONMENT }}_latest.csv
144+
echo "${{ inputs.VERSION_NUMBER }},${NOW}" >> _data/${{ inputs.TARGET_ENVIRONMENT }}_deployments.csv
145+
git config user.name github-actions
146+
git config user.email [email protected]
147+
git add _data/${{ inputs.TARGET_ENVIRONMENT }}_latest.csv
148+
git add _data/${{ inputs.TARGET_ENVIRONMENT }}_deployments.csv
149+
git commit -m 'update releases for ${{ inputs.TARGET_ENVIRONMENT }}'
150+
parallel --retries 10 --delay 3 ::: "git pull --rebase && git push"

0 commit comments

Comments
 (0)