-
Notifications
You must be signed in to change notification settings - Fork 2
70 lines (61 loc) · 2.37 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
name: Backend CD
on:
push:
branches:
- "main"
- "staging"
- "production"
- "perf"
jobs:
build_and_push_docker_image:
name: Build and push docker image to AWS ECR
runs-on: ubuntu-latest
environment: ${{ github.ref_name == 'main' && 'develop' || github.ref_name }}
concurrency:
group: ${{ github.ref_name }}
cancel-in-progress: true
permissions:
id-token: write
contents: read
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: Java setup
uses: ./.github/actions/java-setup
with:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Maven build
run: ./mvnw clean install -T 4 -DskipTests -DskipITs -DskipUTs
- 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.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