-
Notifications
You must be signed in to change notification settings - Fork 0
136 lines (118 loc) · 5.42 KB
/
CD-All.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: CD using github action & docker
on:
push:
branches: ["main", "dev", "HotFix/**"]
workflow_dispatch:
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest # 실행 환경 지정
steps:
- uses: actions/checkout@v3
- name: backend Docker build & push
run: |
docker login -u ${{ secrets.DOCKER_BACK_REPO }} -p ${{ secrets.DOCKER_BACK_PASSWORD }}
cd ./backend
docker build -f Dockerfile -t ${{ secrets.DOCKER_BACK_REPO }}/${{secrets.DOCKER_BACK_TAG}} .
docker push ${{ secrets.DOCKER_BACK_REPO }}/${{secrets.DOCKER_BACK_TAG}}
cd ..
echo "DATABASE_HOST=${{ secrets.DATABASE_HOST }}" > .env
echo "DATABASE_DATABASE=${{ secrets.DATABASE_DATABASE }}" >> .env
echo "DATABASE_PASSWORD=${{ secrets.DATABASE_PASSWORD }}" >> .env
echo "DATABASE_PORT=${{ secrets.DATABASE_PORT }}" >> .env
echo "DATABASE_USER=${{ secrets.DATABASE_USER }}" >> .env
echo "MONGODB_URL=${{ secrets.MONGODB_URL }}" >> .env
echo "MONGODB_DBNAME=${{ secrets.MONGODB_DBNAME }}" >> .env
echo "JWT_ACCESS_TOKEN_SECRET=${{ secrets.JWT_ACCESS_TOKEN_SECRET }}" >> .env
echo "JWT_ACCESS_TOKEN_TIME=${{ secrets.JWT_ACCESS_TOKEN_TIME }}" >> .env
echo "NAVER_CLIENT_ID=${{ secrets.NAVER_CLIENT_ID }}" >> .env
echo "NAVER_CLIENT_SECRET=${{ secrets.NAVER_CLIENT_SECRET }}" >> .env
echo "REDIS_URL=${{ secrets.REDIS_URL }}" >> .env
echo "NODE_ENV=${{ secrets.NODE_ENV }}" >> .env
echo "PORT=${{ secrets.BACK_PORT }}" >> .env
echo "FRONTEND_BASE_URL=${{ secrets.FRONTEND_BASE_URL }}" >> .env
echo "X_NCP_APIGW_API_KEY=${{ secrets.X_NCP_APIGW_API_KEY }}" >> .env
echo "X_NCP_CLOVASTUDIO_API_KEY=${{ secrets.X_NCP_CLOVASTUDIO_API_KEY }}" >> .env
echo "X_NCP_CLOVASTUDIO_REQUEST_ID=${{ secrets.X_NCP_CLOVASTUDIO_REQUEST_ID }}" >> .env
- name: Login to DockerHub for Frontend
uses: docker/login-action@v1
with:
username: ${{secrets.DOCKERHUB_USERNAME}} # 도커 허브 이름
password: ${{secrets.DOCKERHUB_TOKEN}} # 도커 허브 TOKEN
- name: build and release to DockerHub for Frontend
env:
NAME: wjdtjr8649 # 계정명
REPO: boostcamp-lockfestival # 레파지토리 이름(소문자만 가능)
run: |
cd frontend && docker build -t $REPO .
docker tag $REPO:latest $NAME/$REPO:latest
docker push $NAME/$REPO:latest
cd ..
- name: Copy .env to Remote Server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
source: "./.env"
target: "~"
overwrite: true
- name: Copy docker-compose.yaml to Remote Server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
source: "./docker-compose.yaml"
target: "~"
overwrite: true
- name: Copy nginx.conf to Remote Server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
source: "./nginx.conf"
target: "~/conf"
overwrite: true
- name: Remove copied file
run: |
rm ./docker-compose.yaml
rm ./.env
rm ./nginx.conf
- name: Depoly to Server
uses: appleboy/ssh-action@master
with:
host: ${{secrets.HOST}}
username: ${{secrets.USERNAME}}
key: ${{secrets.KEY}}
envs: GITHUB_SHA
script: |
sudo docker pull ${{ secrets.DOCKER_REPO }}:latest
export DOCKER_BACK_REPO=${{secrets.DOCKER_BACK_REPO}}
export DOCKER_BACK_TAG=${{secrets.DOCKER_BACK_TAG}}
export DATABASE_HOST=${{ secrets.DATABASE_HOST }}
export DATABASE_DATABASE=${{ secrets.DATABASE_DATABASE }}
export DATABASE_PASSWORD=${{ secrets.DATABASE_PASSWORD }}
export DATABASE_PORT=${{ secrets.DATABASE_PORT }}
export DATABASE_USER=${{ secrets.DATABASE_USER }}
export MONGODB_URL=${{ secrets.MONGODB_URL }}
export MONGODB_DBNAME=${{ secrets.MONGODB_DBNAME }}
export JWT_ACCESS_TOKEN_SECRET=${{ secrets.JWT_ACCESS_TOKEN_SECRET }}
export JWT_ACCESS_TOKEN_TIME=${{ secrets.JWT_ACCESS_TOKEN_TIME }}
export NAVER_CLIENT_ID=${{ secrets.NAVER_CLIENT_ID }}
export NAVER_CLIENT_SECRET=${{ secrets.NAVER_CLIENT_SECRET }}
export REDIS_URL=${{ secrets.REDIS_URL }}
export NODE_ENV=${{ env.NODE_ENV }}
export PORT=${{ secrets.BACK_PORT }}
export FRONTEND_BASE_URL=${{ secrets.FRONTEND_BASE_URL }}
export X_NCP_APIGW_API_KEY=${{ secrets.X_NCP_APIGW_API_KEY }}
export X_NCP_CLOVASTUDIO_API_KEY=${{ secrets.X_NCP_CLOVASTUDIO_API_KEY }}
export X_NCP_CLOVASTUDIO_REQUEST_ID=${{ secrets.X_NCP_CLOVASTUDIO_REQUEST_ID }}
export DOCKER_REPO=${{ secrets.DOCKER_REPO }}
sudo docker pull ${{ secrets.DOCKER_BACK_REPO }}/${{secrets.DOCKER_BACK_TAG}}
docker-compose down
docker-compose up -d
rm -rf ~/.env
docker image prune -f