-
Notifications
You must be signed in to change notification settings - Fork 9
83 lines (68 loc) · 2.89 KB
/
deploy.yml
File metadata and controls
83 lines (68 loc) · 2.89 KB
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
name: Deploy Spring Boot App
on:
workflow_dispatch:
push:
branches:
- main
- develop
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up JDK 17
uses: actions/setup-java@v5
with:
java-version: '17'
distribution: 'corretto'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Compile and test with Gradle
run: ./gradlew test
- name: Build Docker image
run: docker build -t image-post:latest .
- name: Set environment variables for tagging
run: |
echo "ECR_REGISTRY=${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com" >> $GITHUB_ENV
echo "ECR_REPOSITORY=${{ secrets.AWS_ECR_REPOSITORY_NAME }}" >> $GITHUB_ENV
echo "IMAGE_TAG=$(date +'%Y%m%d%H%M%S')-${GITHUB_SHA::8}" >> $GITHUB_ENV
- name: Tag Docker image
run: |
docker tag image-post:latest ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
docker tag image-post:latest ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v5.1.0
with:
aws-access-key-id: ${{ secrets.AWS_DEPLOY_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_DEPLOY_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Push Docker image to ECR
run: |
docker push ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
docker push ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest
- name: Download task definition template
run: |
aws ecs describe-task-definition --task-definition image-post-app-td --query taskDefinition > task-definition.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: render-task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: image-post
image: ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: ${{ steps.render-task-def.outputs.task-definition }}
service: image-post-app-svc
cluster: MyServiceCluster
wait-for-service-stability: true
- name: Verify deployment status
run: |
echo "Verifying deployment..."
aws ecs describe-services --cluster MyServiceCluster --services image-post-app-svc
echo "Deployment seems stable."