Skip to content

Commit 0916b4f

Browse files
authored
PLT-228 Add build and deploy workflows (#1393)
1 parent d0d053b commit 0916b4f

File tree

5 files changed

+203
-10
lines changed

5 files changed

+203
-10
lines changed

.github/workflows/build.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: build
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
environment:
7+
required: true
8+
type: string
9+
module:
10+
required: true
11+
type: string
12+
workflow_dispatch:
13+
inputs:
14+
environment:
15+
required: true
16+
type: choice
17+
options:
18+
- dev
19+
- test
20+
module:
21+
required: true
22+
type: choice
23+
options:
24+
- api
25+
- worker
26+
27+
jobs:
28+
build:
29+
runs-on: self-hosted
30+
31+
env:
32+
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
33+
AWS_REGION: ${{ vars.AWS_REGION }}
34+
DEPLOYMENT_ENV: ${{ vars[format('{0}_DEPLOYMENT_ENV', inputs.environment)] }}
35+
36+
steps:
37+
- name: Checkout Code
38+
uses: actions/checkout@v3
39+
40+
- name: Setup Java
41+
uses: actions/setup-java@v3
42+
with:
43+
distribution: 'temurin'
44+
java-version: '17'
45+
46+
- name: Install Maven 3.6.3
47+
run: |
48+
export PATH="$PATH:/opt/maven/bin"
49+
echo "PATH=$PATH" >> $GITHUB_ENV
50+
if mvn -v; then echo "Maven already installed" && exit 0; else echo "Installing Maven"; fi
51+
tmpdir="$(mktemp -d)"
52+
curl -LsS https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz | tar xzf - -C "$tmpdir"
53+
sudo rm -rf /opt/maven
54+
sudo mv "$tmpdir/apache-maven-3.6.3" /opt/maven
55+
56+
- name: Set env vars from AWS params in BCDA management account
57+
uses: cmsgov/ab2d-bcda-dpc-platform/actions/aws-params-env-action@main
58+
with:
59+
params: |
60+
ARTIFACTORY_URL=/artifactory/url
61+
ARTIFACTORY_USER=/artifactory/user
62+
ARTIFACTORY_PASSWORD=/artifactory/password
63+
64+
- name: Build package
65+
run: mvn -U clean package -s settings.xml -DskipTests -Dusername="${ARTIFACTORY_USER}" -Dpassword="${ARTIFACTORY_PASSWORD}" -Drepository_url="${ARTIFACTORY_URL}"
66+
67+
- name: Assume role in AB2D Management account
68+
uses: aws-actions/configure-aws-credentials@v3
69+
with:
70+
aws-region: ${{ vars.AWS_REGION }}
71+
role-to-assume: arn:aws:iam::${{ secrets.MGMT_ACCOUNT_ID }}:role/delegatedadmin/developer/ab2d-mgmt-github-actions
72+
73+
- name: Build image and push to ECR
74+
working-directory: ./${{ inputs.module }}
75+
run: |
76+
ECR_REPO_DOMAIN="${{ secrets.MGMT_ACCOUNT_ID }}.dkr.ecr.$AWS_REGION.amazonaws.com"
77+
aws ecr get-login-password | docker login --username AWS --password-stdin "$ECR_REPO_DOMAIN"
78+
ECR_REPO_URI="$ECR_REPO_DOMAIN/ab2d_${{ inputs.module }}"
79+
SHA_SHORT=$(git rev-parse --short HEAD)
80+
echo "Building image for commit sha $SHA_SHORT"
81+
docker build \
82+
-t "${ECR_REPO_URI}:ab2d-${DEPLOYMENT_ENV}-$SHA_SHORT" \
83+
-t "${ECR_REPO_URI}:ab2d-${DEPLOYMENT_ENV}-latest" .
84+
echo "Pushing image"
85+
docker push "${ECR_REPO_URI}" --all-tags

.github/workflows/deploy.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: deploy
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
environment:
7+
required: true
8+
type: string
9+
module:
10+
required: true
11+
type: string
12+
workflow_dispatch:
13+
inputs:
14+
environment:
15+
required: true
16+
type: choice
17+
options:
18+
- dev
19+
- test
20+
- sbx
21+
- prod
22+
- prod-test
23+
module:
24+
required: true
25+
type: choice
26+
options:
27+
- api
28+
- worker
29+
30+
jobs:
31+
deploy:
32+
runs-on: ubuntu-latest
33+
permissions:
34+
contents: read
35+
id-token: write
36+
env:
37+
DEPLOYMENT_ENV: ${{ vars[format('{0}_DEPLOYMENT_ENV', inputs.environment)] }}
38+
ACCOUNT: ${{ inputs.environment == 'prod-test' && 'prod' || inputs.environment }}
39+
40+
steps:
41+
- name: Assume role in AB2D ${{ env.ACCOUNT }} account
42+
uses: aws-actions/configure-aws-credentials@v3
43+
with:
44+
aws-region: ${{ vars.AWS_REGION }}
45+
role-to-assume: arn:aws:iam::${{ secrets[format('{0}_ACCOUNT_ID', env.ACCOUNT)] }}:role/delegatedadmin/developer/ab2d-${{ env.ACCOUNT }}-github-actions
46+
47+
- name: Deploy latest image in ECR to ECS
48+
run: aws ecs update-service --cluster ab2d-${DEPLOYMENT_ENV}-${{ inputs.module }} --service ab2d-${DEPLOYMENT_ENV}-${{ inputs.module }} --force-new-deployment

.github/workflows/e2e-test.yml

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
name: end-to-end tests
22

33
on:
4-
pull_request:
54
workflow_call:
5+
inputs:
6+
environment:
7+
required: true
8+
type: string
69
workflow_dispatch: # Allow manual trigger
10+
inputs:
11+
environment:
12+
required: true
13+
type: choice
14+
options:
15+
- dev
16+
- test
17+
- sbx
18+
default: test
719

8-
# Ensure we have only one e2e test running at a time
20+
# Ensure we have only one e2e test running at a time in each environment
921
concurrency:
10-
group: e2e-test
22+
group: ${{ inputs.environment }}-e2e-test
1123

1224
jobs:
1325
test:
@@ -39,7 +51,7 @@ jobs:
3951
sudo rm -rf /opt/maven
4052
sudo mv "$tmpdir/apache-maven-3.6.3" /opt/maven
4153
42-
- name: Set env vars from AWS params in management account
54+
- name: Set env vars from AWS params in BCDA management account
4355
uses: cmsgov/ab2d-bcda-dpc-platform/actions/aws-params-env-action@main
4456
env:
4557
AWS_REGION: ${{ vars.AWS_REGION }}
@@ -49,13 +61,13 @@ jobs:
4961
ARTIFACTORY_USER=/artifactory/user
5062
ARTIFACTORY_PASSWORD=/artifactory/password
5163
52-
- name: Assume role in AB2D impl account
64+
- name: Assume role in AB2D account for this environment
5365
uses: aws-actions/configure-aws-credentials@v3
5466
with:
5567
aws-region: ${{ vars.AWS_REGION }}
56-
role-to-assume: arn:aws:iam::${{ secrets.IMPL_ACCOUNT_ID }}:role/delegatedadmin/developer/ab2d-test-github-actions
68+
role-to-assume: arn:aws:iam::${{ secrets[format('{0}_ACCOUNT_ID', inputs.environment)] }}:role/delegatedadmin/developer/ab2d-${{ inputs.environment }}-github-actions
5769

58-
- name: Set env vars from AWS params in impl account
70+
- name: Set env vars from AWS params in AB2D account
5971
uses: cmsgov/ab2d-bcda-dpc-platform/actions/aws-params-env-action@main
6072
env:
6173
AWS_REGION: ${{ vars.AWS_REGION }}
@@ -70,7 +82,8 @@ jobs:
7082
- name: Create opt/ab2d directory and download keystore
7183
run: |
7284
mkdir -p opt/ab2d
73-
aws s3 cp s3://ab2d-east-impl-main/ab2d_imp_keystore $AB2D_BFD_KEYSTORE_LOCATION
85+
KEYSTORE_FILE_NAME="ab2d_${{ inputs.environment == 'test' && 'imp' || inputs.environment }}_keystore"
86+
aws s3 cp s3://ab2d-${{ vars[format('{0}_DEPLOYMENT_ENV', inputs.environment)] }}-main/$KEYSTORE_FILE_NAME $AB2D_BFD_KEYSTORE_LOCATION
7487
test -f $AB2D_BFD_KEYSTORE_LOCATION && echo "created keystore file"
7588
7689
- name: Run e2e-bfd-test
@@ -79,6 +92,6 @@ jobs:
7992
8093
- name: Run e2e-test
8194
env:
82-
E2E_ENVIRONMENT: 'IMPL'
95+
E2E_ENVIRONMENT: ${{ inputs.environment == 'dev' && 'DEV' || inputs.environment == 'test' && 'IMPL' || inputs.environment == 'sbx' && 'SANDBOX' }}
8396
run: |
8497
mvn test -s settings.xml -pl e2e-test -am -Dtest=TestRunner -DfailIfNoTests=false -Dusername=$ARTIFACTORY_USER -Dpassword=$ARTIFACTORY_PASSWORD -Drepository_url=$ARTIFACTORY_URL --no-transfer-progress

.github/workflows/pull-request.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: pull request jobs
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
unit-integration-test:
8+
uses: ./.github/workflows/unit-integration-test.yml
9+
secrets: inherit
10+
build-api:
11+
uses: ./.github/workflows/build.yml
12+
with:
13+
environment: test
14+
module: api
15+
secrets: inherit
16+
build-worker:
17+
uses: ./.github/workflows/build.yml
18+
with:
19+
environment: test
20+
module: worker
21+
secrets: inherit
22+
deploy-api:
23+
needs: build-api
24+
permissions:
25+
contents: read
26+
id-token: write
27+
uses: ./.github/workflows/deploy.yml
28+
with:
29+
environment: test
30+
module: api
31+
secrets: inherit
32+
deploy-worker:
33+
needs: build-worker
34+
permissions:
35+
contents: read
36+
id-token: write
37+
uses: ./.github/workflows/deploy.yml
38+
with:
39+
environment: test
40+
module: worker
41+
secrets: inherit
42+
e2e-test:
43+
needs: [deploy-api, deploy-worker]
44+
uses: ./.github/workflows/e2e-test.yml
45+
with:
46+
environment: test
47+
secrets: inherit

.github/workflows/unit-integration-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Run unit and integration tests
22

33
on:
4-
pull_request:
4+
workflow_call:
55
workflow_dispatch: # Allow manual trigger
66

77
jobs:

0 commit comments

Comments
 (0)