Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] ci/cd 연동 #4

Merged
merged 7 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Baggle Server CI/CD with Docker
name: Kusithm HDmedi Server CI/CD with Docker

on:
push:
Expand All @@ -21,19 +21,16 @@ jobs:
with:
java-version: '17'
distribution: 'temurin'

- name: 🍃 application.yml 파일을 생성합니다.
run: |
cd ./src/main
mkdir resources
cd ./resources
touch ./application.yml
echo "$APPLICATION" > ./application.yml
mkdir firebase
cd ./firebase
echo "$FIREBASE_SDK" > ./ssang-1a9ab-firebase-adminsdk-7nen2-2c1210a093.json
env:
APPLICATION: ${{ secrets.APPLICATION }}
FIREBASE_SDK: ${{ secrets.FIREBASE_SDK }}

- name: 🍃 gradle build를 위한 권한을 부여합니다.
run: chmod +x gradlew
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM openjdk:17-alpine
COPY ./build/libs/*.jar app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]
COPY ./build/libs/HDmedi_Server-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3'
services:
blue:
container_name: blue
image: --/blue-green
image: ryukwankon/blue-green
expose:
- 8080
ports:
Expand All @@ -11,7 +11,7 @@ services:
- TZ=Asia/Seoul
green:
container_name: green
image: --/blue-green
image: ryukwankon/blue-green
expose:
- 8080
ports:
Expand Down
51 changes: 51 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

IS_GREEN_EXIST=$(docker ps | grep green)
DEFAULT_CONF=" /etc/nginx/nginx.conf"

# blue가 실행 중이면 green을 up합니다.
if [ -z $IS_GREEN_EXIST ];then
echo "### BLUE => GREEN ####"
echo ">>> green image를 pull합니다."
docker-compose pull green
echo ">>> green container를 up합니다."
docker-compose up -d green
while [ 1 = 1 ]; do
echo ">>> green health check 중..."
sleep 3
REQUEST=$(curl http://127.0.0.1:8082)
if [ -n "$REQUEST" ]; then
echo ">>> 🍃 health check success !"
break;
fi
done;
sleep 3
echo ">>> nginx를 다시 실행 합니다."
sudo cp /etc/nginx/nginx.green.conf /etc/nginx/nginx.conf
sudo nginx -s reload
echo ">>> blue container를 down합니다."
docker-compose stop blue

# green이 실행 중이면 blue를 up합니다.
else
echo "### GREEN => BLUE ###"
echo ">>> blue image를 pull합니다."
docker-compose pull blue
echo ">>> blue container up합니다."
docker-compose up -d blue
while [ 1 = 1 ]; do
echo ">>> blue health check 중..."
sleep 3
REQUEST=$(curl http://127.0.0.1:8081)
if [ -n "$REQUEST" ]; then
echo ">>> 🍃 health check success !"
break;
fi
done;
sleep 3
echo ">>> nginx를 다시 실행 합니다."
sudo cp /etc/nginx/nginx.blue.conf /etc/nginx/nginx.conf
sudo nginx -s reload
echo ">>> green container를 down합니다."
docker-compose stop green
fi
Loading