-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (121 loc) · 4.13 KB
/
Copy pathgithub-action-ci.yml
File metadata and controls
142 lines (121 loc) · 4.13 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: CI/CD Pipeline
on:
push:
branches:
- dev
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- main
jobs:
# -----------------------------------
# 1) CI
# -----------------------------------
ci_job:
runs-on: ubuntu-latest
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/dev') ||
(github.event_name == 'pull_request')
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
- run: chmod +x ./gradlew
- run: ./gradlew build
- run: ./gradlew test
- uses: actions/upload-artifact@v4
with:
name: packaged-jar
path: build/libs/*.jar
# -----------------------------------
# 2) DEV 배포
# -----------------------------------
deploy_dev_job:
needs: ci_job
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/dev'
concurrency:
group: deploy-dev
cancel-in-progress: true
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v4
with:
name: packaged-jar
path: build/libs
- uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set env
run: |
echo "TAG=${{ github.sha }}" >> $GITHUB_ENV
echo "BUILDTIME=$(TZ=Asia/Seoul date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV
- name: Build & Push Dev Image
run: |
docker build -t climingo/climingo-dev:${{ github.sha }} .
docker push climingo/climingo-dev:${{ github.sha }}
- uses: webfactory/ssh-agent@v0.5.3
with:
ssh-private-key: ${{ secrets.DEV_SSH_PRIVATE_KEY }}
- name: Deploy to Dev Server
run: |
ssh -o StrictHostKeyChecking=no singco@${{ secrets.DEV_HOST }} "
set -e
export PATH='/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin':\$PATH
cd '${{ secrets.DEV_DOCKER_COMPOSE_PATH }}'
export TAG='${{ github.sha }}'
export JASYPT_PASSWORD='${{ secrets.JASYPT_PASSWORD }}'
export BUILDTIME='$BUILDTIME'
docker pull climingo/climingo-dev:${{ github.sha }}
docker compose -f docker-compose-dev.yml up -d
"
# -----------------------------------
# 3) PROD 배포
# -----------------------------------
deploy_prod_job:
runs-on: ubuntu-latest
needs: ci_job
if: |
github.event_name == 'pull_request' &&
github.event.action == 'closed' &&
github.event.pull_request.merged == true &&
github.event.pull_request.base.ref == 'main'
concurrency:
group: deploy-prod
cancel-in-progress: false
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v4
with:
name: packaged-jar
path: build/libs
- uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set env
run: |
echo "TAG=${{ github.sha }}" >> $GITHUB_ENV
echo "BUILDTIME=$(TZ=Asia/Seoul date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV
- name: Build & Push Prod Image
run: |
docker build -t climingo/climingo:${{ github.sha }} .
docker push climingo/climingo:${{ github.sha }}
- uses: webfactory/ssh-agent@v0.5.3
with:
ssh-private-key: ${{ secrets.PROD_SSH_PRIVATE_KEY }}
- name: Deploy to Production Server
run: |
ssh -o StrictHostKeyChecking=no singco@${{ secrets.PROD_HOST }} "
set -e
export PATH='/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin':\$PATH
cd '${{ secrets.PROD_DOCKER_COMPOSE_PATH }}'
export TAG='${{ github.sha }}'
export JASYPT_PASSWORD='${{ secrets.JASYPT_PASSWORD }}'
export BUILDTIME='$BUILDTIME'
docker pull climingo/climingo:${{ github.sha }}
docker compose -f docker-compose.yml up -d
"