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

Feature/1 global #4

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: meetup Server CI/CD with Docker
name: meetup Server CI/CD with Docker.

on:
push:
Expand All @@ -16,10 +16,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: 🍃 JDK 17로 설정합니다.
- name: 🍃 JDK 11로 설정합니다.
uses: actions/setup-java@v3
with:
java-version: '17'
java-version: '11'
distribution: 'temurin'


Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FROM openjdk:17-alpine
#ci/cd
FROM openjdk:11-jdk
COPY ./build/libs/server-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]
28 changes: 14 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.1.4'
id 'io.spring.dependency-management' version '1.1.3'
id 'org.springframework.boot' version '2.7.16'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}

group = 'meetup'
group = 'com.groupD'
version = '0.0.1-SNAPSHOT'

java {
sourceCompatibility = '17'
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
sourceCompatibility = '11'
}

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

// lombok
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

// jpa
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

//db
runtimeOnly 'com.mysql:mysql-connector-j'
implementation 'mysql:mysql-connector-java:8.0.33'
}

Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ci/cd
version: '3'
services:
blue:
Expand Down
64 changes: 38 additions & 26 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,47 +1,59 @@
#!/bin/bash
IS_GREEN_EXIST=$(docker ps | grep green)

IS_GREEN=$(docker ps | grep green) # 현재 실행중인 App이 blue인지 확인합니다.
DEFAULT_CONF=" /etc/nginx/nginx.conf"
if [ -z $IS_GREEN_EXIST ];then

if [ -z $IS_GREEN ];then # blue라면

echo "### BLUE => GREEN ####"
echo ">>> green image를 pull합니다."
docker-compose pull green
echo ">>> green container를 up합니다."
docker-compose up -d green

echo "1. get green image"
docker-compose pull green # green으로 이미지를 내려받습니다.

echo "2. green container up"
docker-compose up -d green # green 컨테이너 실행

while [ 1 = 1 ]; do
echo ">>> green health check..."
echo "3. green health check..."
sleep 3
REQUEST=$(curl http://127.0.0.1:8082)
if [ -n "$REQUEST" ]; then
echo ">>> 🍃 health check success !"
break;
fi

REQUEST=$(curl http://127.0.0.1:8082) # green으로 request
if [ -n "$REQUEST" ]; then # 서비스 가능하면 health check 중지
echo "health check success"
break ;
fi
done;
sleep 3
echo ">>> nginx를 다시 실행 합니다."

echo "4. reload nginx"
sudo cp /etc/nginx/nginx.green.conf /etc/nginx/nginx.conf
sudo nginx -s reload
echo ">>> blue container를 down합니다."

echo "5. blue container down"
docker-compose stop blue
# green이 실행 중이면 blue를 up합니다.
else
echo "### GREEN => BLUE ###"
echo ">>> blue image를 pull합니다."

echo "1. get blue image"
docker-compose pull blue
echo ">>> blue container up합니다."

echo "2. blue container up"
docker-compose up -d blue

while [ 1 = 1 ]; do
echo ">>> blue health check..."
echo "3. blue health check..."
sleep 3
REQUEST=$(curl http://127.0.0.1:8081)
if [ -n "$REQUEST" ]; then
echo ">>> 🍃 health check success !"
break;
REQUEST=$(curl http://127.0.0.1:8081) # blue로 request

if [ -n "$REQUEST" ]; then # 서비스 가능하면 health check 중지
echo "health check success"
break ;
fi
done;
sleep 3
echo ">>> nginx를 다시 실행 합니다."

echo "4. reload nginx"
sudo cp /etc/nginx/nginx.blue.conf /etc/nginx/nginx.conf
sudo nginx -s reload
echo ">>> green container를 down합니다."

echo "5. green container down"
docker-compose stop green
fi
2 changes: 1 addition & 1 deletion src/main/java/meetup/server/ServerApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@SpringBootApplication
public class ServerApplication {
//q
//qq
public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
server:

port: 8080

spring:
Expand Down
Loading