-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (72 loc) · 2.89 KB
/
ci-app.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: CI App PipeLine
on:
push:
branches: [ "prod" ]
pull_request:
branches: [ "prod" ]
jobs:
app:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Cache Maven dependencies
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Login to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: Login to Amazon ECR Private
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build Application JAR
run: mvn clean package
- name: List files
run: ls -R
- name: Docker Compose Build
run: docker compose build
- name: Tag and push docker image to Amazon ECR
run: |
docker tag ${{ secrets.DOCKER_USERNAME }}/blog-api-server:latest ${{ secrets.IMAGE_REPO_URL }}:${{ github.run_id }}
docker tag ${{ secrets.DOCKER_USERNAME }}/blog-api-server:latest ${{ secrets.IMAGE_REPO_URL }}:latest
docker push ${{ secrets.IMAGE_REPO_URL }}:${{ github.run_id }}
docker push ${{ secrets.IMAGE_REPO_URL }}:latest
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition ${{ secrets.TASK_DEFINITION_NAME }} --query taskDefinition > task-definition.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: ${{ secrets.CONTAINER_NAME }}
image: ${{ secrets.IMAGE_REPO_URL }}:latest
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ secrets.SERVICE_NAME }}
cluster: ${{ secrets.CLUSTER_NAME }}
wait-for-service-stability: true
- name: Push to Docker Hub Container Registry
run: |
docker tag ${{ secrets.DOCKER_USERNAME }}/blog-api-server:latest ${{ secrets.DOCKER_USERNAME }}/blog-api-server:${{ github.run_id }}
docker push ${{ secrets.DOCKER_USERNAME }}/blog-api-server:${{ github.run_id }}
docker push ${{ secrets.DOCKER_USERNAME }}/blog-api-server:latest