-
Notifications
You must be signed in to change notification settings - Fork 2
72 lines (64 loc) · 2.59 KB
/
backend-cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
name: Backend CD
on:
workflow_run:
workflows: [ "Backend CI" ]
branches:
- main
- staging
- production
types:
- completed
jobs:
build_and_push_docker_image:
name: Build and push docker image to AWS ECR
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
environment: ${{ github.event.workflow_run.head_branch == 'main' && 'develop' || github.event.workflow_run.head_branch }}
concurrency:
group: ${{ github.event.workflow_run.head_branch }}
cancel-in-progress: true
permissions:
id-token: write
contents: read
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_branch }}
- name: Download jar file
uses: actions/download-artifact@v4
with:
name: marketplace-api.jar
run-id: ${{ github.event.workflow_run.id }}
path: bootstrap/target/marketplace-api.jar
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ vars.AWS_REGION }}
role-to-assume: ${{ vars.AWS_ROLE }}
- name: Retrieve parameters
env:
REPO_NAME: ${{ github.event.workflow_run.head_repository.name }}
run: |
echo SHA_SHORT=$(git rev-parse --short HEAD) >> "$GITHUB_ENV"
echo ECR_REPOSITORY_URI=$(aws ecr describe-repositories --query "repositories[?contains(@.repositoryName, 'marketplacerepository') == \`true\`].repositoryUri" --output text) >> "$GITHUB_ENV"
echo CLUSTER_ARN=$(aws ecs list-clusters --query 'clusterArns[0]' --output text) >> "$GITHUB_ENV"
echo SERVICES=$(aws resourcegroupstaggingapi get-resources --tag-filters Key=repo,Values="$REPO_NAME" --resource-type-filters ecs:service --query 'ResourceTagMappingList[*].ResourceARN' --output text ) >> "$GITHUB_ENV"
- name: Login to ECR
uses: docker/login-action@v3
with:
registry: ${{ env.ECR_REPOSITORY_URI }}
- name: Build, tag, and push image to Amazon ECR
uses: docker/build-push-action@v6
with:
push: true
context: .
tags: |
${{ env.ECR_REPOSITORY_URI }}:latest
${{ env.ECR_REPOSITORY_URI }}:${{ env.SHA_SHORT }}
- name: Deploy ECR services
run: |
for service in ${{ env.SERVICES }}; do
aws ecs update-service --cluster ${{ env.CLUSTER_ARN }} --service $service --force-new-deployment
done