-
Notifications
You must be signed in to change notification settings - Fork 3
120 lines (102 loc) · 3.44 KB
/
server_cd_release.yml
File metadata and controls
120 lines (102 loc) · 3.44 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: "2. Backend Deploy"
on:
push:
tags:
- "backend/v*"
workflow_dispatch:
inputs:
version:
description: "배포할 버전 (예: 1.2.3)"
required: true
permissions:
contents: read
packages: write
concurrency:
group: backend-deploy
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
outputs:
image_tag: v${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Extract version from tag
id: version
run: |
# backend/v1.2.3 → 1.2.3
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
version="${{ github.event.inputs.version }}"
else
version="${GITHUB_REF_NAME#backend/v}"
fi
echo "version=$version" >> $GITHUB_OUTPUT
echo "Building version: $version"
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: "17"
distribution: "temurin"
cache: gradle
- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582
- name: Cache Gradle dependencies
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Create application.properties
run: |
cd ./backend/src/main/resources
echo "${{ secrets.APPLICATION_PROD_RELEASE }}" > ./application.properties
- name: Grant execute permission for gradlew
run: chmod +x ./backend/gradlew
- name: Build with Gradle
run: |
cd backend
./gradlew clean build -x test
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.SERVER_DOCKER_USERNAME }}
password: ${{ secrets.SERVER_DOCKER_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: ./backend
file: ./backend/Dockerfile
platforms: linux/arm64,linux/amd64
push: true
tags: |
${{ secrets.DOCKER_IMAGE_RELEASE }}:latest
${{ secrets.DOCKER_IMAGE_RELEASE }}:v${{ steps.version.outputs.version }}
update-deployment-file:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout deploy-manifests repository
uses: actions/checkout@v4
with:
repository: Moadong/gitops-moadong
token: ${{ secrets.PAT }}
ref: main
path: gitops-moadong
- name: Update image tag in kustomize
run: |
cd gitops-moadong/backend/prod
kustomize edit set image ${{ secrets.DOCKER_IMAGE_RELEASE }}=${{ secrets.DOCKER_IMAGE_RELEASE }}:${{ needs.build.outputs.image_tag }}
- name: Commit and Push changes
run: |
cd gitops-moadong
git config --global user.email "${{ secrets.EMAIL }}"
git config --global user.name "${{ secrets.USERNAME }}"
git add .
git diff --cached --quiet && echo "No changes" && exit 0
git commit -m "chore(prod): backend image tag update ${{ needs.build.outputs.image_tag }}"
git push