Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ff0ff39
[chore] ISSUE_TEMPLATE.md 위치 변경 (#491)
kseysh Mar 10, 2025
7aad0e2
[deploy] ci 과정 변경 (#491)
kseysh Mar 10, 2025
05970fc
[deploy] dev cd 과정 변경 (#491)
kseysh Mar 10, 2025
c32ce3f
[deploy] start.sh이 prod 환경에서만 작동하도록 변경 (#491)
kseysh Mar 11, 2025
9ce00ae
[deploy] stop.sh이 prod 환경에서만 작동하도록 변경 (#491)
kseysh Mar 11, 2025
f95de29
[deploy] job name을 명확하게 변경 (#491)
kseysh Mar 11, 2025
a1aa4a0
[chore] 오타 수정 (#491)
kseysh Mar 11, 2025
b708597
[feat] docker-compose를 github secret에서 가져오도록 변경 (#491)
kseysh Mar 12, 2025
d7a95f5
[feat] Dockerfile 생성 (#491)
kseysh Mar 12, 2025
a44d36d
[feat] Docker build시 spring profile 값이 들어가도록 cd script 수정 (#491)
kseysh Mar 12, 2025
ca9e583
[modify] docker-compose를 github secret에서 가져오도록 변경 (#491)
kseysh Mar 12, 2025
10b9d02
[feat] docker-compose gitignore 처리 (#491)
kseysh Mar 12, 2025
e199a0f
[feat] deploy shell script 추가 (#491)
kseysh Mar 12, 2025
9add645
[feat] docker compose 실행 script 추가 (#491)
kseysh Mar 12, 2025
60ddc6f
[feat] health check script 추가 (#491)
kseysh Mar 12, 2025
5fa90c5
[feat] nginx reload shell script 추가 (#491)
kseysh Mar 12, 2025
625a5dc
[feat] container 중지 shell script 추가 (#491)
kseysh Mar 12, 2025
ba2d637
[feat] 중복된 docker pull 제거 (#491)
kseysh Mar 12, 2025
81d3789
[modify] docker 실행시 redis와 함께 실행하도록 변경 (#491)
kseysh Mar 14, 2025
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
File renamed without changes.
95 changes: 95 additions & 0 deletions .github/workflows/app-cd-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: ⚙️ MAKERS-DEV-APP-DEPLOY

on:
push:
branches: [ dev ]

env:
SPRING_PROFILES_ACTIVE: dev
ECR_APP_NAME: ${{ secrets.ECR_APP_NAME }}-dev
APP_ECR_REPO: ${{ secrets.ECR_HOST }}/${{ secrets.ECR_APP_NAME }}-dev
ECR_HOST: ${{ secrets.ECR_HOST }}

jobs:
build:
name: CD Pipeline
runs-on: ubuntu-latest

steps:
- name: checkout
uses: actions/checkout@v3

- name: set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '21'

- name: touch yml files
run: |
touch ./src/main/resources/application-dev.yml
touch ./src/test/resources/application-test.yml

shell: bash

- name: copy application.yml files
run: |
echo "${{ secrets.APPLICATION_DEV_YML }}" > ./src/main/resources/application-dev.yml
echo "${{ secrets.APPLICATION_TEST_YML }}" > ./src/test/resources/application-test.yml

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.DEV_AWS_ACCESS_ID }}
aws-secret-access-key: ${{ secrets.DEV_AWS_SECRET_KEY }}
aws-region: ap-northeast-2

- name: 🐘Gradle Build
run: |
chmod +x ./gradlew
./gradlew clean build -x test

- name: Login to ECR
run: |
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin $ECR_HOST

- name: 🐳Docker Image Build & Push
run: |
docker build \
--build-arg SPRING_PROFILES_ACTIVE=$SPRING_PROFILES_ACTIVE \
-t $ECR_APP_NAME .
docker tag $ECR_APP_NAME:latest $APP_ECR_REPO
docker push $APP_ECR_REPO

- name: Copy docker-compose.yml
run: echo "${{ secrets.DOCKER_COMPOSE_DEV_YML }}" > ./docker-compose.yml

- name: Send docker-compose.yml to EC2 Instance
uses: appleboy/scp-action@master
with:
username: ec2-user
host: ${{ secrets.DEV_SERVER_IP }}
key: ${{ secrets.DEV_PEM_KEY }}
source: "./docker-compose.yml"
target: "/home/ec2-user/app/"

- name: Send deploy script to EC2 Instance
uses: appleboy/scp-action@master
with:
username: ec2-user
host: ${{ secrets.DEV_SERVER_IP }}
key: ${{ secrets.DEV_PEM_KEY }}
source: "./scripts/"
target: "/home/ec2-user/app/"

- name: Docker Container Run
uses: appleboy/ssh-action@master
with:
username: ec2-user
host: ${{ secrets.DEV_SERVER_IP }}
key: ${{ secrets.DEV_PEM_KEY }}
script: |
cd ~
sudo chmod +x ./app/scripts/*.sh
./app/scripts/deploy.sh
docker image prune -f
35 changes: 35 additions & 0 deletions .github/workflows/app-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: 🏭 Makers Dev App CI

on:
pull_request:
branches: [ "dev" ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: checkout
uses: actions/checkout@v3

- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'corretto'

- name: Copy yml
run: |
touch ./src/main/resources/application-dev.yml
touch ./src/test/resources/application-test.yml

echo "${{ secrets.APPLICATION_DEV_YML }}" >> ./src/main/resources/application-dev.yml
echo "${{ secrets.APPLICATION_TEST_YML }}" >> ./src/test/resources/application-test.yml

shell: bash

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build
56 changes: 0 additions & 56 deletions .github/workflows/build-dev.yml

This file was deleted.

68 changes: 0 additions & 68 deletions .github/workflows/release-dev-code_deploy.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/release-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ jobs:
- name: 📂 Make zip file
run: zip -r ./$GITHUB_SHA.zip .

- name: 🪣 S3 upload
uses: aws-actions/configure-aws-credentials@v1
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ out/
### macOS ###
.DS_Store

### application.yml 파일들에 대한 gitignore 처리
### yml 파일 관련
application-local.yml
application-prod.yml
application-dev.yml
application-test.yml
docker-compose.yml

### HTTP 관련
http-client.private.env.json
http-client.env.json
**/resources/http/**/env/
**/resources/http/**/data/
**/resources/http
*.http
*.http
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM amazoncorretto:21
WORKDIR /app
COPY ./build/libs/app-server-0.0.1-SNAPSHOT.jar /app/app-application.jar

ARG SPRING_PROFILES_ACTIVE
ENV SPRING_PROFILES_ACTIVE=$SPRING_PROFILES_ACTIVE

CMD ["java", "-jar", "-Dspring.profiles.active=${SPRING_PROFILES_ACTIVE}", "app-application.jar"]
87 changes: 87 additions & 0 deletions script/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash
cd /home/ec2-user/app

source /home/ec2-user/app/scripts/health_check.sh
source /home/ec2-user/app/scripts/deploy_container.sh
source /home/ec2-user/app/scripts/nginx_reload.sh
source /home/ec2-user/app/scripts/stop_container.sh

BLUE_CONTAINER_NAME="app-blue"
BLUE_PORT=9090
GREEN_CONTAINER_NAME="app-green"
GREEN_PORT=9091

DOCKER_PS_OUTPUT=$(docker ps --format "{{.Names}}" | grep -E "(${BLUE_CONTAINER_NAME}|${GREEN_CONTAINER_NAME})")
RUNNING_CONTAINER_NAME="${DOCKER_PS_OUTPUT:-}"

ALL_PORTS=("${BLUE_PORT}" "${GREEN_PORT}")
AVAILABLE_PORT=()
RUNNING_SERVER_PORT=""

check_running_container() {
if [[ "$RUNNING_CONTAINER_NAME" == "$BLUE_CONTAINER_NAME" ]]; then
echo "Running Port: $BLUE_CONTAINER_NAME (:$BLUE_PORT)"
RUNNING_SERVER_PORT=$BLUE_PORT
elif [[ "$RUNNING_CONTAINER_NAME" == "$GREEN_CONTAINER_NAME" ]]; then
echo "Running Port: $GREEN_CONTAINER_NAME (:$GREEN_PORT)"
RUNNING_SERVER_PORT=$GREEN_PORT
else
echo "Running Port: None"
fi
}

check_available_ports() {
for item in "${ALL_PORTS[@]}"; do
if [ "$item" != "$RUNNING_SERVER_PORT" ]; then
AVAILABLE_PORT+=("$item")
fi
done

if [[ ${#AVAILABLE_PORT[@]} -eq 0 ]]; then
echo "❌ No available ports."
exit 1
fi
}

### --

check_running_container
check_available_ports

DEPLOY_TARGET_CONTAINER_NAME=""
DEPLOY_TARGET_PORT=""

if [ "$RUNNING_SERVER_PORT" == "$BLUE_PORT" ]; then # Green Up
DEPLOY_TARGET_CONTAINER_NAME=${GREEN_CONTAINER_NAME}
DEPLOY_TARGET_PORT=${GREEN_PORT}
elif [ "$RUNNING_SERVER_PORT" == "$GREEN_PORT" ]; then # Blue Up
DEPLOY_TARGET_CONTAINER_NAME=${BLUE_CONTAINER_NAME}
DEPLOY_TARGET_PORT=${BLUE_PORT}
else
echo "❌ No running container found. Defaulting to $BLUE_CONTAINER_NAME."
DEPLOY_TARGET_CONTAINER_NAME=${BLUE_CONTAINER_NAME}
DEPLOY_TARGET_PORT=${BLUE_PORT}
fi

deploy_container "${DEPLOY_TARGET_CONTAINER_NAME}" ${DEPLOY_TARGET_PORT}

if ! health_check ${DEPLOY_TARGET_PORT}; then
echo "❌ Health Check failed ..."
stop_container "${DEPLOY_TARGET_CONTAINER_NAME}"
exit 1
fi

reload_nginx ${DEPLOY_TARGET_PORT}

if [[ -n "$RUNNING_CONTAINER_NAME" ]]; then
stop_container ${RUNNING_CONTAINER_NAME}
fi

echo "▶️ Final health check applied nginx port switching ..."
if ! health_check ${DEPLOY_TARGET_PORT}; then
echo "❌ Server change failed ..."
stop_container "${DEPLOY_TARGET_CONTAINER_NAME}"
exit 1
fi

echo "✅ Server change successful 👍"
Loading