forked from kookmin-sw/cap-template
-
Notifications
You must be signed in to change notification settings - Fork 3
182 lines (156 loc) · 5.81 KB
/
develop.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
name: Build And Deploy for develop branch to test server
on:
push:
branches: [ "develop" ]
permissions:
contents: read
jobs:
server-build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: "adopt"
- name: Make folder resources
run: |
cd ./server/src/main
mkdir resources
cd resources
- name: Make application.properties
run: |
cd ./server/src/main/resources
touch ./application.properties
echo "${{ secrets.PROPERTIES_DEVELOP }}" > ./application.properties
- name: Build with gradle
run: |
cd server
chmod +x ./gradlew
./gradlew clean build -x test
- name: Docker build & push to docker repo
run: |
cd server
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }}:latest .
docker push ${{ secrets.DOCKER_REPO }}:latest
frontend-build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check node version
run: node -v
- name: Change frontend .env
run: |
rm -f ./frontend/.env
touch ./frontend/.env
echo "${{ secrets.ENV_DEVELOP }}" >> ./frontend/.env
- name: Yarn install dependencies
run: |
cd ./frontend
yarn install --frozen-lockfile
- name: Yarn build
run: |
cd ./frontend
yarn build
- name: Frontend docker build & push to docker repo
run: |
cd frontend
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_FRONTEND_REPO }}:latest .
docker push ${{ secrets.DOCKER_FRONTEND_REPO }}:latest
pull-and-deploy:
needs:
- server-build-and-push
- frontend-build-and-push
runs-on: ubuntu-latest
steps:
- name: Set LocalTime Asia/Seoul
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.TEST_EC2_PUBLIC_IP }}
username: ubuntu
key: ${{ secrets.TEST_SSH_PRIVATE_KEY }}
envs: GITHUB_SHA
script: |
sudo timedatectl set-timezone Asia/Seoul
- name: Install docker
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.TEST_EC2_PUBLIC_IP }}
username: ubuntu
key: ${{ secrets.TEST_SSH_PRIVATE_KEY }}
envs: GITHUB_SHA
script: |
if ! command -v docker &> /dev/null; then
sudo apt-get update
sudo apt-get install -y \
ca-certificates \
curl \
gnupg
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo docker run hello-world
fi
- name: Install docker-compose
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.TEST_EC2_PUBLIC_IP }}
username: ubuntu
key: ${{ secrets.TEST_SSH_PRIVATE_KEY }}
envs: GITHUB_SHA
script: |
if ! command -v docker-compose &> /dev/null; then
sudo curl -L "https://github.com/docker/compose/releases/download/v2.15.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
else
echo "Docker Compose already installed via curl."
fi
- name: Remove & Change docker-compose file
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.TEST_EC2_PUBLIC_IP }}
username: ubuntu
key: ${{ secrets.TEST_SSH_PRIVATE_KEY }}
envs: GITHUB_SHA
script: |
if [ -f docker-compose.yml ]; then
sudo rm docker-compose.yml
fi
curl -o docker-compose.yml -L https://raw.githubusercontent.com/kookmin-sw/capstone-2024-14/develop/server/docker-compose.yml
cat docker-compose.yml
- name: Remove & Change server docker image
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.TEST_EC2_PUBLIC_IP }}
username: ubuntu
key: ${{ secrets.TEST_SSH_PRIVATE_KEY }}
envs: GITHUB_SHA
script: |
if [ -n "$(docker ps -qa)" ]; then
echo "Removing running containers..."
sudo docker rm -f $(docker ps -qa)
while sudo docker image prune -f 2>&1 | grep -q "a prune operation is already running"; do
echo "Waiting for ongoing prune operation to complete..."
sleep 10
done
fi
sudo docker pull ${{ secrets.DOCKER_REPO }}:latest
sudo docker pull ${{ secrets.DOCKER_FRONTEND_REPO }}:latest
sudo docker image prune -f
- name: Execute docker-compose
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.TEST_EC2_PUBLIC_IP }}
username: ubuntu
key: ${{ secrets.TEST_SSH_PRIVATE_KEY }}
envs: GITHUB_SHA
script: |
sudo docker-compose up -d