-
Notifications
You must be signed in to change notification settings - Fork 1
189 lines (175 loc) · 5.57 KB
/
deploy_prod.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
name: Deploy to EC2
on:
push:
branches:
- main
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
# 기본 체크아웃
- name: Checkout
uses: actions/checkout@v3
- name: Make application-secret.yml without env
run: |
touch ./src/main/resources/application-secret.yml
echo "${{ secrets.APPLICATION_SECRET }}" > ./src/main/resources/application-secret.yml
# JDK version 설정
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
## gradle build
- name: Build with Gradle
run: ./gradlew bootJar
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Docker app build & push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/ceos-backend
- name: Docker nginx build & push
uses: docker/build-push-action@v5
with:
context: .
file: ./config/nginx/Dockerfile
platforms: linux/amd64
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/ceos-nginx
# ssh 접근 후 docker 이미지 pull 및 컨테이너 재시작
- name: executing remote ssh commands using password
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST_PROD }}
username: ec2-user # ubuntu 에서 변경
key: ${{ secrets.EC2_KEY_PROD }}
script: |
cd /home/ec2-user/ceos
sudo touch .env
echo "${{ secrets.ENV_PROD }}" | sudo tee .env > /dev/null
sudo curl -o docker-compose.yml https://raw.githubusercontent.com/CEOS-Developers/CEOS-BE/main/docker-compose.yml
sudo chmod 666 /var/run/docker.sock
sudo docker rm -f $(docker ps -qa)
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/ceos-backend
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/ceos-nginx
docker-compose -f docker-compose.yml --env-file ./.env up -d
docker image prune -f
#name: Deploy to EC2
#
#on:
# push:
# branches:
# - main
#
#permissions:
# contents: read
#
#jobs:
# build:
# runs-on: ubuntu-latest
# steps:
# # 기본 체크아웃
# - name: Checkout
# uses: actions/checkout@v3
#
# # JDK version 설정
# - name: Set up JDK 17
# uses: actions/setup-java@v3
# with:
# java-version: '17'
# distribution: 'temurin'
#
# # 그래들 캐싱
# - name: Gradle Caching
# uses: actions/cache@v3
# with:
# path: |
# ~/.gradle/caches
# ~/.gradle/wrapper
# key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
# restore-keys: |
# ${{ runner.os }}-gradle-
#
# - name: Make application-secret.yml without env
# run: |
# touch ./src/main/resources/application-secret.yml
# echo "${{ secrets.APPLICATION_SECRET }}" > ./src/main/resources/application-secret.yml
# env:
# PROPERTIES_DEV: ${{ secrets.APPLICATION_SECRET }}
#
# - name: Make env
# run: |
# touch .env
# echo "${{ secrets.ENV_PROD }}" > .env
# env:
# PROPERTIES_DEV: ${{ secrets.ENV_PROD }}
#
# # Gradle build
# - name: Build with Gradle
# run: ./gradlew build -x test :spotlessApply
#
# - name: Docker meta
# id: docker_meta
# uses: crazy-max/ghaction-docker-meta@v1
# with:
# images: ceos/ceos-server-dev
#
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v1
#
# - name: Login to DockerHub
# uses: docker/login-action@v1
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}
#
# - name: Docker build & push
# uses: docker/build-push-action@v2
# with:
# context: .
# file: ./Dockerfile
# platforms: linux/amd64
# push: true
# tags: ${{ secrets.DOCKER_USERNAME }}/ceos-backend
#
# - name: create remote directory
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.EC2_HOST_PROD }}
# username: ubuntu
# key: ${{ secrets.EC2_KEY_PROD }}
# script: mkdir -p ~/srv/ubuntu/ceos_web_dev
#
# - name: copy source via ssh key
# uses: burnett01/[email protected]
# with:
# switches: -avzr --delete
# remote_path: ~/srv/ubuntu/
# remote_host: ${{ secrets.EC2_HOST_PROD }}
# remote_user: ubuntu
# remote_key: ${{ secrets.EC2_KEY_PROD }}
#
# - name: executing remote ssh commands using password
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.EC2_HOST_PROD }}
# username: ubuntu
# key: ${{ secrets.EC2_KEY_PROD }}
# script: |
# sh ~/srv/ubuntu/config/scripts/deploy.sh
# sudo docker stop $(sudo docker ps -a -q)
# sudo docker rm $(sudo docker ps -a -q)
# sudo docker rmi $(sudo docker images -q)
# sudo docker-compose -f ~/srv/ubuntu/docker-compose.yml pull
# sudo docker-compose -f ~/srv/ubuntu/docker-compose.yml up --build -d
#