-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (65 loc) · 2.44 KB
/
CI.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
name: Continuous Integration
on:
push:
branches: ["main"]
permissions:
id-token: write
contents: read
env:
REPOSITORY: ${{ secrets.REPOSITORY }}
IMAGE_TAG: :${{ github.ref_name }}-${{ github.sha }}
REGISTRY_USERNAME: ${{ github.actor }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ROLE: ${{ secrets.AWS_ROLE }}
jobs:
Build:
name: Build & Delivery
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
token: ${{secrets.TOKEN_GITHUB}}
submodules: true
- name: Git Submodule Update
run: |
git submodule update --remote --recursive
- name: Set up Java JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- name: Build with Gradle
id: buildWithGradle
run: ./gradlew clean build -x test
shell: bash
- name: lowercase the image tag & repository
run: |
echo "REPOSITORY=$(echo $REPOSITORY | tr '[:upper:]' '[:lower:]')" >> ${GITHUB_ENV}
echo "IMAGE_TAG=$(echo $IMAGE_TAG | tr '[:upper:]' '[:lower:]')" >> ${GITHUB_ENV}
- name: Set Spring Image Environment Variable
run: |
echo "SPRING_IMAGE=${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.REPOSITORY }}${{ env.IMAGE_TAG }}" >> ${GITHUB_ENV}
echo "LATEST_IMAGE=${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.REPOSITORY }}:latest" >> ${GITHUB_ENV}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{env.AWS_REGION}}
role-to-assume: ${{ env.AWS_ROLE }}
role-session-name: GitHubActionsSession
- name: Login to AWS ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build Image
run: docker build --no-cache -t ${{ env.SPRING_IMAGE }} -f ./xinfra/docker/Dockerfile .
- name: Push to ECR
run: |
docker push ${{ env.SPRING_IMAGE }}
docker tag ${{ env.SPRING_IMAGE }} ${{ env.LATEST_IMAGE }}
docker push ${{ env.LATEST_IMAGE }}