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
85 changes: 85 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: SCOI CD
on:
push:
branches: [ "develop" ]

env:
# 도커 허브 저장소 이름 (예: myusername/scoi-backend)
DOCKER_IMAGE_NAME: ${{ secrets.DOCKER_USERNAME }}/scoi-backend

jobs:
# 📦 1단계: 빌드 및 도커 이미지 푸시
build-and-push:
runs-on: ubuntu-latest
steps:
- name: 체크아웃
uses: actions/checkout@v4

- name: 자바 설정 Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: 'gradle'

- name: application.yml 주입
shell: bash
run: |
mkdir -p src/main/resources
cat > src/main/resources/application.yml <<'EOF'
${{ secrets.DEV_APPLICATION_YML }}
EOF

- name: firebase json 주입
shell: bash
run: |
mkdir -p src/main/resources
cat > src/main/resources/firebase-scoi.json <<'EOF'
${{ secrets.FIREBASE_JSON }}
EOF

- name: gradlew 실행 권한 부여
run: chmod +x gradlew

- name: gradle 빌드 (테스트 제외)
run: ./gradlew clean build -x test

- name: Docker Hub 로그인
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Docker 이미지 빌드 및 푸시
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.DOCKER_IMAGE_NAME }}:latest


deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: EC2에 배포 (SSH 접속)
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_SSH_USER }}
key: ${{ secrets.EC2_SSH_KEY }}

script: |
cd ~/scoi-Backend

echo "${{ secrets.DEV_ENV_FILE }}" > .env
echo "DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}" >> .env

# Docker Hub에서 방금 만든 최신 이미지 가져오기
sudo docker-compose pull

# 컨테이너 재실행
sudo docker-compose up -d

# 불필요한 이미지 삭제
sudo docker image prune -f
76 changes: 76 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: SCOI CI

on:
push:
branches: [ "main", "develop" ]
pull_request:
branches: [ "main", "develop" ]

jobs:
build:
runs-on: ubuntu-latest

# CI 서버 내부에서 테스트용 DB/Redis 컨테이너 실행
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: scoi
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

redis:
image: redis:latest
ports:
- 6379:6379
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- name: 체크아웃
uses: actions/checkout@v4

- name: 자바 설정 Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: 'gradle'

- name: application.yml 주입
shell: bash
run: |
mkdir -p src/main/resources
cat > src/main/resources/application.yml <<'EOF'
${{ secrets.DEV_APPLICATION_YML }}
EOF

# firebase 파일 생성
- name: firebase json 주입
shell: bash
run: |
mkdir -p src/main/resources
cat > src/main/resources/firebase-scoi.json <<'EOF'
${{ secrets.FIREBASE_JSON }}
EOF

- name: gradlew 실행 권한 부여
run: chmod +x gradlew

- name: gradle 빌드
run: ./gradlew build

# CI용
env:
DB_URL: jdbc:mysql://localhost:3306/scoi?serverTimezone=Asia/Seoul
DB_USERNAME: root
DB_PASSWORD: root
REDIS_HOST: localhost
REDIS_PORT: 6379
JWT_KEY: scoi-test-key
JWT_SECRET: scoi-test-secret-keysdsdsdsdsdsdssdsdsdsdsdsdsdsdsdsdsdsdsdsdsds
COOLSMS_API_URL: test_coolsms_api_key
COOLSMS_API_SECRET: test_coolsms_secret_key
COOLSMS_API_KEY: test_coolsms_key
COOLSMS_FROM_NUMBER: 01000000000
92 changes: 0 additions & 92 deletions .github/workflows/deploy.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*.yml
*.properties
# GitHub Actions workflow는 예외로 추적
!.github/workflows/deploy.yml
!.github/workflows/
### workflow.yml 제외 ###
!workflow.yml

Expand Down
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM openjdk:21-jdk

WORKDIR /app

COPY build/libs/*SNAPSHOT.jar app.jar

ENTRYPOINT ["java", "-jar", "-Duser.timezone=Asia/Seoul", "app.jar"]
32 changes: 32 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '3.8'

services:
scoi-backend:
image: ${DOCKER_USERNAME}/scoi-backend:latest
container_name: scoi-backend
ports:
- "8080:8080"

env_file:
- .env

depends_on:
- redis

networks:
- scoi-network

restart: always

redis:
image: redis:latest
container_name: scoi-redis
ports:
- "6379:6379"
networks:
- scoi-network
restart: always

networks:
scoi-network:
driver: bridge