-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
CI/CD 구축 완료
- Loading branch information
Showing
16 changed files
with
253 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
name: Develop Branch CI | ||
|
||
on: | ||
push: | ||
branches: [ "develop" ] | ||
|
||
jobs: | ||
deploy: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# JDK 설정 | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '21' | ||
distribution: 'temurin' | ||
|
||
# 환경 변수 파일 생성 | ||
- name: Set environment values for main application | ||
run: | | ||
cd ./src/main/resources | ||
touch ./env.properties | ||
echo "${{ secrets.ENV }}" > ./env.properties | ||
shell: bash | ||
|
||
- name: Set environment values for test | ||
run: | | ||
cd ./src/test/resources | ||
touch ./env.properties | ||
echo "${{ secrets.TEST_ENV }}" > ./env.properties | ||
shell: bash | ||
|
||
# Gradle에 권한 부여 | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
|
||
# Gradle test | ||
- name: Test with Gradle | ||
run: ./gradlew test | ||
|
||
# Gradle build | ||
- name: Build Gradle | ||
run: ./gradlew build | ||
|
||
# 압축 파일 만들기 | ||
- name: Make zip file | ||
run: | | ||
mkdir develop-deploy | ||
cp ./src/main/resources/env.properties ./develop-deploy/.env | ||
cp ./docker-compose.blue.yml ./develop-deploy/ | ||
cp ./docker-compose.green.yml ./develop-deploy/ | ||
cp ./appspec.yml ./develop-deploy/ | ||
cp ./Dockerfile ./develop-deploy/ | ||
cp ./scripts/*.sh ./develop-deploy/ | ||
cp ./build/libs/*.jar ./develop-deploy/ | ||
zip -r -qq -j ./munecting.zip ./develop-deploy | ||
# AWS 접속 | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ap-northeast-2 | ||
|
||
# S3에 저장 | ||
- name: Upload to S3 | ||
run: aws s3 cp --region ap-northeast-2 ./munecting.zip s3://code-deploy-munecting | ||
|
||
# Code Deploy 실행 | ||
- name: Code Deploy | ||
run: aws deploy create-deployment --application-name munecting-deploy | ||
--deployment-config-name CodeDeployDefault.OneAtATime | ||
--deployment-group-name munecting-deploy-group | ||
--s3-location bucket=code-deploy-munecting,bundleType=zip,key=munecting.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
HELP.md | ||
env.properties | ||
.gradle | ||
build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM openjdk:21 | ||
WORKDIR /munecting | ||
COPY Munecting-server-0.0.1-SNAPSHOT.jar app.jar | ||
ENTRYPOINT ["java", "-jar", "app.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
version: 0.0 | ||
os: linux | ||
files: | ||
- source: / | ||
destination: /home/ubuntu/app | ||
overwrite: yes | ||
|
||
permissions: | ||
- object: / | ||
pattern: "**" | ||
owner: ubuntu | ||
group: ubuntu | ||
mode: 777 | ||
|
||
hooks: | ||
ApplicationStart: | ||
- location: develop-deploy.sh | ||
timeout: 300 | ||
runas: ubuntu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#blue | ||
version: '3' | ||
services: | ||
munecting-develop-api: | ||
build: . | ||
ports: | ||
- "8081:8080" | ||
container_name: spring-blue | ||
networks: | ||
- munecting-network | ||
|
||
networks: | ||
munecting-network: | ||
external: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#green | ||
version: '3' | ||
services: | ||
munecting-develop-api: | ||
build: . | ||
ports: | ||
- "8082:8080" | ||
container_name: spring-green | ||
networks: | ||
- munecting-network | ||
|
||
networks: | ||
munecting-network: | ||
external: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
services: | ||
redis: | ||
image: redis:latest | ||
container_name: redis | ||
networks: | ||
- munecting-server | ||
ports: | ||
- "6379:6379" | ||
|
||
networks: | ||
munecting-network: | ||
external: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/bin/bash | ||
|
||
cd /home/ubuntu/app | ||
|
||
# Redis 컨테이너 실행 여부 확인 | ||
REDIS_CONTAINER_STATUS=$(docker ps | grep redis) | ||
if [ -z "$REDIS_CONTAINER_STATUS" ]; then | ||
echo "Redis 컨테이너가 실행 중이지 않습니다" | ||
echo ">>> Pulling Redis image" | ||
docker compose -f docker-compose.redis.yml pull redis | ||
echo ">>> Starting Redis container" | ||
docker compose -f docker-compose.redis.yml up -d redis | ||
else | ||
echo "Redis 컨테이너가 이미 실행 중입니다." | ||
fi | ||
|
||
|
||
DOCKER_APP_NAME=spring | ||
|
||
# blue 컨테이너 실행 여부 확인 | ||
BLUE_CONTAINER_RUNNING=$(docker-compose -p ${DOCKER_APP_NAME}-blue -f docker-compose.blue.yml ps -q | xargs docker inspect -f '{{.State.Running}}') | ||
|
||
# 컨테이너 스위칭 | ||
if [ "$BLUE_CONTAINER_RUNNING" != "true" ]; then | ||
echo "[blue up]" | ||
docker-compose -p ${DOCKER_APP_NAME}-blue -f docker-compose.blue.yml up -d --build | ||
|
||
ACTIVE_ENV="blue" | ||
STANDBY_ENV="green" | ||
ACTIVE_PORT="8081" | ||
|
||
else | ||
echo "[green up]" | ||
docker-compose -p ${DOCKER_APP_NAME}-green -f docker-compose.green.yml up -d --build | ||
|
||
ACTIVE_ENV="green" | ||
STANDBY_ENV="blue" | ||
ACTIVE_PORT="8082" | ||
|
||
fi | ||
|
||
|
||
# 헬스체크 | ||
MAX_RETRIES=30 | ||
RETRY_INTERVAL=2 | ||
HEALTH_CHECK_URL="http://localhost:$ACTIVE_PORT/actuator/health" | ||
ACTIVE_HEALTH_CHECK_PASSED=false | ||
|
||
echo "Waiting for application to be ready..." | ||
for i in $(seq 1 $MAX_RETRIES); do | ||
if curl -s "$HEALTH_CHECK_URL" | grep -q "UP"; then | ||
echo "[Application is ready]" | ||
ACTIVE_HEALTH_CHECK_PASSED=true | ||
break | ||
|
||
fi | ||
echo "Waiting... ($i/$MAX_RETRIES)" | ||
sleep $RETRY_INTERVAL | ||
|
||
done | ||
|
||
# 새로운 컨테이너가 제대로 떴는지 확인 | ||
if [ "$ACTIVE_HEALTH_CHECK_PASSED" = "true" ]; then | ||
# 이전 컨테이너 종료 | ||
docker-compose -p ${DOCKER_APP_NAME}-${STANDBY_ENV} -f docker-compose.${STANDBY_ENV}.yml down | ||
docker image prune -af | ||
echo "[Down] $STANDBY_ENV Down" | ||
|
||
else | ||
echo "Health check failed after $MAX_RETRIES attempts" | ||
# 새 컨테이너 종료 | ||
docker-compose -p ${DOCKER_APP_NAME}-${ACTIVE_ENV} -f docker-compose.${ACTIVE_ENV}.yml down | ||
# 디스코드 알림 | ||
sudo ./discord_${ACTIVE_ENV}.sh | ||
|
||
fi | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/munecting/api/global/config/PropertyConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.munecting.api.global.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.PropertySource; | ||
import org.springframework.context.annotation.PropertySources; | ||
|
||
@Configuration | ||
@PropertySources({ | ||
@PropertySource("classpath:env.properties") | ||
}) | ||
public class PropertyConfig { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/* | ||
package com.munecting.api; | ||
import org.junit.jupiter.api.Test; | ||
|
@@ -13,3 +14,4 @@ void contextLoads() { | |
} | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters