-
Notifications
You must be signed in to change notification settings - Fork 0
76 lines (62 loc) · 2.36 KB
/
main.yml
File metadata and controls
76 lines (62 loc) · 2.36 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
name: Auto Deploy Spring Boot to Dev
on:
push:
branches: [main]
permissions:
contents: read
jobs:
deploy-backend:
runs-on: ubuntu-latest
env:
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_REGION: ${{ secrets.AWS_REGION }}
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up Java
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Build Spring Boot App (JAR)
run: mvn clean verify
- name: Upload coverage to Codecov
if: ${{ always() }}
uses: codecov/codecov-action@v4
with:
files: target/site/jacoco/jacoco.xml
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Set image tag from SHA or fallback
run: |
IMAGE_TAG=${GITHUB_SHA::8}
if [ -z "$IMAGE_TAG" ]; then
IMAGE_TAG="manual-$(date +%s)"
fi
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
- name: Docker Login to ECR
run: |
aws ecr get-login-password --region $AWS_REGION | \
docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
- name: Build and Push Docker Image
run: |
IMAGE_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/${{ secrets.ECR_REPO_BACKEND }}:$IMAGE_TAG
docker build -t $IMAGE_URI .
docker push $IMAGE_URI
- name: Render ECS task definition
run: |
envsubst < task-def-template.json > task-def-backend.json
- name: Register New Task Definition and Deploy to ECS
run: |
NEW_REVISION=$(aws ecs register-task-definition \
--cli-input-json file://task-def-backend.json \
--query 'taskDefinition.revision' --output text)
aws ecs update-service \
--cluster bills-dev-fargate-cluster \
--service webbills-dev-fargate \
--task-definition webbills-task-fargate:$NEW_REVISION \
--force-new-deployment