-
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.
- Loading branch information
Showing
1 changed file
with
38 additions
and
30 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 |
---|---|---|
@@ -1,14 +1,19 @@ | ||
name: Deploy to EC2 on develop | ||
name: CI/CD Workflow for Develop | ||
|
||
on: | ||
push: | ||
branches: [ "develop" ] | ||
# PR 작성 및 업데이트 시 CI 실행 | ||
pull_request: | ||
branches: [ "develop" ] | ||
|
||
# develop 브랜치로의 푸시 시 CD 실행 | ||
push: | ||
branches: [ "develop" ] | ||
|
||
jobs: | ||
build-and-push-image: | ||
# Gradle 빌드만 수행하는 CI 작업 (PR에서만 실행) | ||
ci-gradle-build: | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'pull_request' | ||
permissions: | ||
contents: read | ||
|
||
|
@@ -37,9 +42,37 @@ jobs: | |
- name: Build with Gradle Wrapper | ||
run: ./gradlew build | ||
|
||
# CD 작업 - Gradle 빌드, Docker 이미지 빌드 및 배포 (develop 브랜치로의 push 시에만 실행) | ||
build-push-deploy: | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'push' | ||
permissions: | ||
contents: read | ||
|
||
steps: | ||
# 소스 코드 체크아웃 | ||
- uses: actions/checkout@v4 | ||
|
||
# JDK 설정 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
# Gradle 설정 | ||
- name: Setup Gradle | ||
uses: gradle/actions/setup-gradle@v4 | ||
with: | ||
gradle-version: '7.3' | ||
|
||
# Gradle 빌드 | ||
- name: Build with Gradle Wrapper | ||
run: ./gradlew build | ||
|
||
# Docker 이미지 빌드 | ||
- name: Build Docker image | ||
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }} . | ||
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }} . | ||
|
||
# Docker Hub에 로그인 | ||
- name: Log in to Docker Hub | ||
|
@@ -52,11 +85,6 @@ jobs: | |
- name: Push Docker image to Docker Hub | ||
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }} | ||
|
||
deploy-to-ec2: | ||
needs: build-and-push-image | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# SSH 비밀 키 설정 | ||
- name: Install SSH Key | ||
uses: webfactory/[email protected] | ||
|
@@ -70,7 +98,6 @@ jobs: | |
EC2_USER: ${{ secrets.EC2_USER }} | ||
run: | | ||
ssh -o StrictHostKeyChecking=no $EC2_USER@$EC2_HOST << EOF | ||
cd /home/ubuntu # docker-compose.yml 파일 위치로 이동 | ||
# 기존 컨테이너 중지 | ||
|
@@ -85,22 +112,3 @@ jobs: | |
# 모든 서비스 다시 실행 | ||
docker-compose up -d | ||
EOF | ||
dependency-submission: | ||
|
||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies. | ||
# See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md | ||
- name: Generate and submit dependency graph | ||
uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 |