-
Notifications
You must be signed in to change notification settings - Fork 0
115 lines (96 loc) · 2.95 KB
/
Copy pathdeploy-dev.yml
File metadata and controls
115 lines (96 loc) · 2.95 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
name: Dev Deploy
on:
push:
branches: [ "develop" ]
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
ci:
name: CI (maven test)
runs-on: ubuntu-latest
environment: dev
steps:
- name: Checkout (with submodules)
uses: actions/checkout@v4
with:
submodules: true
token: ${{ secrets.GH_PAT }}
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "17"
cache: maven
- name: Test
run: |
chmod +x mvnw
./mvnw test
build_and_push:
name: Build & Push (GHCR)
runs-on: ubuntu-latest
environment: dev
needs: ci
outputs:
image_tag: ${{ steps.vars.outputs.image_tag }}
steps:
- name: Checkout (with submodules)
uses: actions/checkout@v4
with:
submodules: true
token: ${{ secrets.GH_PAT }}
- name: Compute image tag
id: vars
run: |
SHORT_SHA="${GITHUB_SHA::7}"
echo "image_tag=sha-${SHORT_SHA}" >> $GITHUB_OUTPUT
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./deploy/app/Dockerfile
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:dev
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.image_tag }}
deploy:
name: Deploy to Dev Server
runs-on: ubuntu-latest
needs: build_and_push
environment: dev
steps:
- name: Deploy via SSH (update IMAGE_NAME, pull, up)
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.KT_HOST }}
username: ${{ secrets.KT_USER }}
key: ${{ secrets.KT_SSH_KEY }}
port: ${{ secrets.KT_SSH_PORT }}
script: |
set -e
cd /home/${{ secrets.KT_USER }}/trit-server
# (선택) compose/nginx 설정 변경을 같이 반영하고 싶으면 유지
git pull origin develop
# IMAGE_NAME을 이번 커밋 이미지로 업데이트 (서버 .env에 IMAGE_NAME이 있어야 함)
NEW_IMAGE="ghcr.io/${{ github.repository }}:${{ needs.build_and_push.outputs.image_tag }}"
if [ ! -f .env ]; then
echo ".env not found in $(pwd). Create it first." >&2
exit 1
fi
if grep -q '^IMAGE_NAME=' .env; then
sed -i "s|^IMAGE_NAME=.*|IMAGE_NAME=${NEW_IMAGE}|" .env
else
echo "IMAGE_NAME=${NEW_IMAGE}" >> .env
fi
docker compose pull app
docker compose up -d
docker image prune -f