forked from boostcampwm-2024/web15-OctoDocs
-
Notifications
You must be signed in to change notification settings - Fork 0
71 lines (61 loc) · 2.33 KB
/
cd-pipeline.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
name: auto Workflow
on:
push:
branches:
- refactor-be-#47
workflow_dispatch:
jobs:
image-build-and-push:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
# root에 .env.local, .env.client, .env.server 복사
- name: copy .env
run: |
echo "${{ secrets.LOCAL_ENV }}" > .env.local
echo "${{ secrets.CLIENT_ENV }}" > .env.client
echo "${{ secrets.SERVER_ENV }}" > .env.server
# Docker 로그인
- name: docker hub login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# 패키지 이미지부터 빌드 후 푸시
# 이 이미지를 base로 backend와 websocket 이미지를 만들기 때문
- name: package docker image build and push
run: |
docker build -f ./services/module/Dockerfile -t summersummerwhy/octodocs-modules .
# Docker 이미지 빌드
- name: docker image build
run: |
docker build -f ./services/backend/Dockerfile.prod -t summersummerwhy/octodocs-backend .
docker build -f ./services/nginx/Dockerfile.prod -t summersummerwhy/octodocs-nginx .
docker build -f ./services/websocket/Dockerfile.prod -t summersummerwhy/octodocs-websocket .
# Docker 이미지 푸시
- name: docker image push
run: |
docker push summersummerwhy/octodocs-modules
docker push summersummerwhy/octodocs-backend
docker push summersummerwhy/octodocs-nginx
docker push summersummerwhy/octodocs-websocket
deploy:
needs: image-build-and-push
runs-on: ubuntu-latest
steps:
- name: deploy
env:
REMOTE_HOST: ${{ secrets.REMOTE_SERVER_IP }}
REMOTE_USER: ${{ secrets.REMOTE_SERVER_USER }}
SSH_KEY: ${{ secrets.REMOTE_PRIVATE_KEY }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
run: |
mkdir ~/.ssh
echo "$SSH_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh -o StrictHostKeyChecking=no $REMOTE_USER@$REMOTE_HOST << 'EOF'
cd /root/octodocs
docker-compose -f compose.prod.yml down
docker-compose -f compose.prod.yml pull
docker-compose -f compose.prod.yml up -d