Skip to content
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
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/ci.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: "CI/CD"
about: 배포 작업 템플릿입니다.
title: "ci/cd: "
labels: ci
assignees: ''

---

# Title

- title

# TODO

- [ ] write what to do

# etc

- nothing
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: "DOCS"
about: 문서 작업 템플릿입니다.
title: "docs: "
labels: docs
assignees: ''

---

# Title

- title

# TODO

- [ ] write what to do

# etc

- nothing
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: "FEAT"
about: 기능 개발 템플릿입니다.
title: "feat: "
labels: feat
assignees: ''

---

# Title

- title

# TODO

- [ ] write what to do

# etc

- nothing
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: "FIX"
about: 버그 수정 템플릿입니다.
title: "fix: "
labels: fix
assignees: ''

---

# Title

- title

# TODO

- [ ] write what to do

# etc

- nothing
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/refactor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: "REFACTOR"
about: 리팩토링 템플릿입니다.
title: "️refactor: "
labels: refactor
assignees: ''

---

# Title

- title

# TODO

- [ ] write what to do

# etc

- nothing
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: "TEST"
about: 테스트 작업 템플릿입니다.
title: "test: "
labels: test
assignees: ''

---

# Title

- title

# TODO

- [ ] write what to do

# etc

- nothing
97 changes: 97 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: CI/CD with Git Actions & Docker Hub test

on:
pull_request:
branches:
- master
- develop

jobs:
build:
runs-on: ubuntu-latest

env:
SPRING_PROFILE: ${{ github.base_ref == 'master' && 'prod' || 'dev' }}
PRIVATE_IP: ${{ github.base_ref == 'master' && secrets.PRIVATE_IP || secrets.DEV_PRIVATE_IP }}
REPOSITORY: ${{ github.base_ref == 'master' && secrets.DOCKERHUB_REPOSITORY || secrets.DEV_DOCKERHUB_REPOSITORY }}
APPLICATION_YML: ${{ github.base_ref == 'master' && secrets.APPLICATION_YML_PROD || secrets.APPLICATION_YML_DEV }}

steps:
- name: Checkout source code
uses: actions/checkout@v3

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

- name: Grant execute permission to gradlew
run: chmod +x ./gradlew

- name: Create application-{profile}.yml
run: |
mkdir -p src/main/resources
echo "${{ env.APPLICATION_YML }}" > src/main/resources/application-${{ env.SPRING_PROFILE }}.yml

- name: Build with Gradle
run: ./gradlew clean :bootJar

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Docker image
run: |
docker build \
--build-arg SPRING_PROFILE=${{ env.SPRING_PROFILE }} \
-t ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPOSITORY }}:${{ secrets.DOCKERHUB_TAG }} \
--platform linux/amd64 .

docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPOSITORY }}:${{ secrets.DOCKERHUB_TAG }}

- name: Deploy at EC2 instance through Bastion Host
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.BASTION_SSH_HOST }} # Bastion Host 퍼블릭 IP
username: ubuntu
key: ${{ secrets.BASTION_SSH_KEY }}
port: ${{ secrets.BASTION_SSH_PORT }}
script: |
echo "✅ Bastion Host 접속 완료"

# Private EC2에 SSH 접속 후 배포 수행
ssh -i "${{secrets.DIRECTORY_PEM}}" ubuntu@${{ env.PRIVATE_IP }} << 'EOF'
echo "✅ Private EC2 접속 완료"

IMAGE_NAME="${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPOSITORY }}:${{ secrets.DOCKERHUB_TAG }}"
CONTAINER_NAME="${{ secrets.DOCKERHUB_TAG }}"

echo "🔹 Docker 로그인"
docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" -p "${{ secrets.DOCKERHUB_TOKEN }}"

echo "🔹 기존 컨테이너($CONTAINER_NAME) 중지 및 삭제"
if [ "$(sudo docker ps -q -f name=$CONTAINER_NAME)" ]; then
sudo docker stop "$CONTAINER_NAME"
sudo docker rm "$CONTAINER_NAME"
else
echo "ℹ️ $CONTAINER_NAME 컨테이너가 실행 중이지 않음"
fi

echo "🔹 기존 이미지($IMAGE_NAME) 삭제"
if [ "$(sudo docker images -q $IMAGE_NAME)" ]; then
sudo docker rmi "$IMAGE_NAME"
else
echo "ℹ️ 삭제할 이미지 없음: $IMAGE_NAME"
fi

echo "🔹 새로운 Docker 이미지 Pull"
sudo docker pull "$IMAGE_NAME"

echo "🔹 컨테이너 실행"
sudo docker run -d --name "$CONTAINER_NAME" --network=drinkly -p 8888:8888 --restart unless-stopped "$IMAGE_NAME"

echo "🚀 배포 완료"
EOF
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ out/
.vscode/

application.yml
/src/main/resources/application-*.yml
12 changes: 5 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
FROM openjdk:21

# JAR 복사
COPY ./build/libs/config-server.jar config-server.jar

# 기본 ENV 설정 (선택)
ENV SPRING_PROFILE=prod
ARG SPRING_PROFILE=prod
ENV SPRING_PROFILE=$SPRING_PROFILE
ENV TZ=Asia/Seoul

# ENTRYPOINT에서 외부 환경 변수를 기반으로 실행
ENTRYPOINT ["sh", "-c", "java -Dspring.profiles.active=${SPRING_PROFILE} -Duser.timezone=${TZ} -jar config-server.jar"]
COPY ./build/libs/config-server.jar config-server.jar

ENTRYPOINT ["sh", "-c", "java -Dspring.profiles.active=${SPRING_PROFILE} -Duser.timezone=${TZ} -jar config-server.jar"]
49 changes: 0 additions & 49 deletions src/main/resources/application-dev.yml

This file was deleted.

49 changes: 0 additions & 49 deletions src/main/resources/application-local.yml

This file was deleted.

49 changes: 0 additions & 49 deletions src/main/resources/application-prod.yml

This file was deleted.