-
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
83 additions
and
62 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,73 +1,94 @@ | ||
name: Backend CI/CD using GitHub Actions & Docker | ||
name: Full Stack CI/CD using GitHub Actions & Docker | ||
|
||
# 워크플로우 실행 조건 설정 | ||
on: | ||
push: | ||
branches: [ "production" ] | ||
pull_request: | ||
branches: [ "production" ] | ||
push: | ||
branches: [ "production" ] | ||
pull_request: | ||
branches: [ "production" ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
build: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
steps: | ||
# 코드 체크아웃 | ||
- uses: actions/checkout@v4 | ||
|
||
steps: | ||
# 코드 체크아웃 | ||
- uses: actions/checkout@v4 | ||
# 백엔드 빌드 환경 설정 (JDK 21) | ||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '21' | ||
distribution: 'temurin' | ||
|
||
# 백엔드 빌드 환경 설정 (JDK 21) | ||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '21' | ||
distribution: 'temurin' | ||
# 백엔드 설정 파일 생성 | ||
- name: Create backend configuration files | ||
run: | | ||
mkdir -p ./backend/src/main/resources | ||
cd ./backend/src/main/resources | ||
echo "${{ secrets.APPLICATION_YML }}" > application.yml | ||
echo "${{ secrets.APPLICATION_AWS_YML }}" > application-aws.yml | ||
# 백엔드 설정 파일 생성 | ||
- name: Create backend configuration files | ||
run: | | ||
mkdir -p ./backend/src/main/resources | ||
cd ./backend/src/main/resources | ||
echo "${{ secrets.APPLICATION_YML }}" > application.yml | ||
echo "${{ secrets.APPLICATION_AWS_YML }}" > application-aws.yml | ||
# Gradle 설정 | ||
- name: Setup Gradle | ||
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 | ||
|
||
# 백엔드 빌드 실행 | ||
- name: Build Backend | ||
run: | | ||
cd backend | ||
chmod +x ./gradlew | ||
./gradlew build -x test | ||
# Gradle 설정 | ||
- name: Setup Gradle | ||
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 | ||
|
||
# 백엔드 빌드 실행 | ||
- name: Build Backend | ||
run: | | ||
cd backend | ||
chmod +x ./gradlew | ||
./gradlew build -x test | ||
# 프론트엔드 빌드 환경 설정 | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18' | ||
|
||
# 도커 이미지 빌드 및 푸시 | ||
- name: Docker build & push | ||
run: | | ||
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | ||
cd backend | ||
docker build -t ${{ secrets.DOCKER_USERNAME }}/backend:latest . | ||
docker push ${{ secrets.DOCKER_USERNAME }}/backend:latest | ||
# 프론트엔드 빌드 실행 | ||
- name: Build Frontend | ||
run: | | ||
cd frontend | ||
npm install | ||
npm run build | ||
# EC2 인스턴스에 배포 | ||
- name: Deploy to EC2 | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ubuntu | ||
key: ${{ secrets.EC2_PRIVATE_KEY }} | ||
script: | | ||
# 최신 도커 이미지 받아오기 | ||
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/backend:latest | ||
# 실행 중인 컨테이너 중지 및 제거 | ||
sudo docker stop $(sudo docker ps -a -q) || true | ||
sudo docker rm $(sudo docker ps -a -q) || true | ||
# 새 컨테이너 실행 | ||
sudo docker run -d -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/backend:latest | ||
# 사용하지 않는 이미지 정리 | ||
sudo docker image prune -a -f | ||
# 백엔드 도커 이미지 빌드 및 푸시 | ||
- name: Backend Docker build & push | ||
run: | | ||
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | ||
cd backend | ||
docker build -t ${{ secrets.DOCKER_USERNAME }}/backend:latest . | ||
docker push ${{ secrets.DOCKER_USERNAME }}/backend:latest | ||
# 프론트엔드 도커 이미지 빌드 및 푸시 | ||
- name: Frontend Docker build & push | ||
run: | | ||
cd frontend | ||
docker build -t ${{ secrets.DOCKER_USERNAME }}/frontend:latest . | ||
docker push ${{ secrets.DOCKER_USERNAME }}/frontend:latest | ||
# EC2 인스턴스에 배포 | ||
- name: Deploy to EC2 | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ubuntu | ||
key: ${{ secrets.EC2_PRIVATE_KEY }} | ||
script: | | ||
# 최신 도커 이미지 받아오기 | ||
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/backend:latest | ||
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/frontend:latest | ||
# 실행 중인 컨테이너 중지 및 제거 | ||
sudo docker stop $(sudo docker ps -a -q) || true | ||
sudo docker rm $(sudo docker ps -a -q) || true | ||
# 새 컨테이너 실행 | ||
sudo docker run -d -p 8080:8080 --name backend ${{ secrets.DOCKER_USERNAME }}/backend:latest | ||
sudo docker run -d -p 80:80 --name frontend ${{ secrets.DOCKER_USERNAME }}/frontend:latest | ||
# 사용하지 않는 이미지 정리 | ||
sudo docker image prune -a -f |