-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (78 loc) · 2.29 KB
/
server_cd.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
94
95
96
97
98
99
name: Server CD
on:
push:
branches:
- main
paths:
- 'server/**'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/server
jobs:
build:
name: Build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
defaults:
run:
working-directory: server
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Build with Gradle
run: ./gradlew clean bootJar
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ./server
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
platforms: linux/amd64
deploy:
name: Deploy
runs-on: [self-hosted]
needs: build
defaults:
run:
working-directory: ./server
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Login to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create .env file
env:
SECRET_CONTEXT: ${{ toJson(secrets) }}
run: |
echo "$SECRET_CONTEXT" | tr -d '{}' | tr ',' '\n' | sed -n 's/"\(.*\)":\(.*\)/\1=\2/p' > .env
- name: View
run: cat .env
- name: Compose Docker image and Update Nginx configuration
env:
DOCKER_APP_IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
run: |
chmod +x ./scripts/deploy.sh # 실행 권한 부여
sudo -E ./scripts/deploy.sh # 환경 변수 유지 및 실행
- name: Docker remove unused images
run: docker image prune -af
- name: Check running containers
run: docker ps -a