-
Notifications
You must be signed in to change notification settings - Fork 0
116 lines (111 loc) · 3.79 KB
/
main.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: CI/CD Docker
on:
pull_request:
types: [closed]
branches:
- 'server/release/*'
env:
DOCKER_IMAGE: ghcr.io/${{ github.actor }}/nest-openlist-deploy
VERSION: ${{ github.sha }}
NAME: go_cicd
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v2
# .env 파일 생성
- name: Generate .env file
run: |
cat << EOF > ./server/.env
JWT_SECRET=${{ secrets.JWT_SECRET }}
ACCESS_TOKEN_EXPIRES=${{ secrets.ACCESS_TOKEN_EXPIRES }}
REFRESH_TOKEN_EXPIRES=${{ secrets.REFRESH_TOKEN_EXPIRES }}
HASH_ROUNDS=${{ secrets.HASH_ROUNDS }}
PROTOCOL=${{ secrets.PROTOCOL }}
HOST=${{ secrets.HOST }}
DB_HOST=${{ secrets.DB_HOST }}
DB_PORT=${{ secrets.DB_PORT }}
DB_USERNAME=${{ secrets.DB_USERNAME }}
DB_PASSWORD=${{ secrets.DB_PASSWORD }}
DB_DATABASE=${{ secrets.DB_DATABASE }}
SUB=${{ secrets.SUB }}
ALG=${{ secrets.ALG }}
KID=${{ secrets.KID }}
ISS=${{ secrets.ISS }}
AUTHKEY=${{ secrets.AUTHKEY }}
X_NCP_CLOVASTUDIO_API_KEY=${{ secrets.X_NCP_CLOVASTUDIO_API_KEY }}
X_NCP_APIGW_API_KEY=${{ secrets.X_NCP_APIGW_API_KEY }}
X_NCP_CLOVASTUDIO_REQUEST_ID=${{ secrets.X_NCP_CLOVASTUDIO_REQUEST_ID }}
REDIS_URL=${{ secrets.REDIS_URL }}
REDIS_USERNAME=${{ secrets.REDIS_USERNAME }}
REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }}
ADMIN_EMAIL=${{ secrets.ADMIN_EMAIL }}
ADMIN_PASSWORD=${{ secrets.ADMIN_PASSWORD }}
EOF
- name: Generate .p8 file
run: |
cat << EOF > ./server/.p8
${{ secrets.P8 }}
EOF
- name: Set up docker buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Cache docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ env.VERSION }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to ghcr
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
context: ./server
file: ./server/Dockerfile
push: true
tags: ${{ env.DOCKER_IMAGE }}:latest
# 배포 Job - 서버 1
deploy-server1:
needs: build
name: Deploy to Server 1
runs-on: [ self-hosted, label-server1 ]
steps:
- name: Login to ghcr
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Docker run (Server 1)
run: |
docker stop go_cicd1 || true
docker rm go_cicd1 || true
docker pull ${{ env.DOCKER_IMAGE }}:latest
docker run -d -p 3000:3000 --name go_cicd1 --restart always ${{ env.DOCKER_IMAGE }}:latest
# # 배포 Job - 서버 2
# deploy-server2:
# needs: build
# name: Deploy to Server 2
# runs-on: [ self-hosted, label-server2 ]
# steps:
# - name: Login to ghcr
# uses: docker/login-action@v1
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GHCR_TOKEN }}
# - name: Docker run (Server 2)
# run: |
# docker stop go_cicd2 || true
# docker rm go_cicd2 || true
# docker pull ${{ env.DOCKER_IMAGE }}:latest
# docker run -d -p 3000:3000 --name go_cicd2 --restart always ${{ env.DOCKER_IMAGE }}:latest