feat: 다중 OS 테스트 도입으로 CI/CD 워크플로우 개선 #9
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
name: BlackFriday CI/CD | |
on: | |
push: | |
branches: | |
- 'feature/**' | |
- 'main' | |
paths-ignore: | |
- '**.md' | |
- 'docs/**' | |
- '.gitignore' | |
pull_request: | |
branches: [ main ] | |
paths-ignore: | |
- '**.md' | |
- 'docs/**' | |
- '.gitignore' | |
jobs: | |
test: | |
name: Test on ${{ matrix.os }} | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
include: | |
- os: windows-latest | |
gradle-command: "gradlew.bat clean test" | |
- os: ubuntu-latest | |
gradle-command: "./gradlew clean test" | |
- os: macos-latest | |
gradle-command: "./gradlew clean test" | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
cache: 'gradle' | |
- name: Grant execute permission for gradlew | |
if: runner.os != 'Windows' | |
run: chmod +x gradlew | |
- name: Clean and Test | |
env: | |
GRADLE_OPTS: "-Dorg.gradle.daemon=false" | |
run: ${{ matrix.gradle-command }} | |
build-and-push: | |
needs: test | |
if: github.ref == 'refs/heads/main' && needs.test.result == 'success' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
cache: 'gradle' | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_TOKEN }} | |
- name: Build and Push with Jib | |
run: | | |
./gradlew jib \ | |
-Djib.to.image=docker.io/${{ secrets.DOCKER_HUB_USERNAME }}/blackfriday-app \ | |
-Djib.to.tags=latest,${{ github.sha }} | |
deploy-blue: | |
needs: build-and-push | |
if: needs.build-and-push.result == 'success' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Copy docker-compose files | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.NCP_BLUE_HOST }} | |
username: deploy-user | |
key: ${{ secrets.NCP_SSH_PRIVATE_KEY }} | |
source: "docker-compose.yml" | |
target: "/app" | |
- name: Deploy to Blue Server | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.NCP_BLUE_HOST }} | |
username: deploy-user | |
key: ${{ secrets.NCP_SSH_PRIVATE_KEY }} | |
script: | | |
cd /app | |
docker compose down | |
docker pull docker.io/${{ secrets.DOCKER_HUB_USERNAME }}/blackfriday-app:${{ github.sha }} | |
DOCKER_IMAGE=${{ secrets.DOCKER_HUB_USERNAME }}/blackfriday-app:${{ github.sha }} \ | |
MYSQL_DATABASE=${{ secrets.MYSQL_DATABASE }} \ | |
MYSQL_USER=${{ secrets.MYSQL_USER }} \ | |
MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }} \ | |
docker compose up -d | |
- name: Health Check Blue | |
run: | | |
echo "Waiting for application to initialize..." | |
sleep 60 | |
for i in {1..10}; do | |
if curl -s -f http://${{ secrets.NCP_BLUE_HOST }}:8080/health/liveness; then | |
echo "Health check passed" | |
exit 0 | |
fi | |
echo "Attempt $i failed. Retrying..." | |
sleep 10 | |
done | |
exit 1 | |
deploy-green: | |
needs: [deploy-blue] | |
if: needs.deploy-blue.result == 'success' # Blue 배포 성공해야만 실행 | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Copy docker-compose files | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.NCP_GREEN_HOST }} | |
username: deploy-user | |
key: ${{ secrets.NCP_SSH_PRIVATE_KEY }} | |
source: "docker-compose.yml" | |
target: "/app" | |
- name: Deploy to Green Server | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.NCP_GREEN_HOST }} | |
username: deploy-user | |
key: ${{ secrets.NCP_SSH_PRIVATE_KEY }} | |
script: | | |
cd /app | |
docker compose down | |
docker pull docker.io/${{ secrets.DOCKER_HUB_USERNAME }}/blackfriday-app:${{ github.sha }} | |
DOCKER_IMAGE=${{ secrets.DOCKER_HUB_USERNAME }}/blackfriday-app:${{ github.sha }} \ | |
MYSQL_DATABASE=${{ secrets.MYSQL_DATABASE }} \ | |
MYSQL_USER=${{ secrets.MYSQL_USER }} \ | |
MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }} \ | |
docker compose up -d | |
- name: Health Check Green | |
run: | | |
echo "Waiting for application to initialize..." | |
sleep 60 | |
for i in {1..10}; do | |
if curl -s -f http://${{ secrets.NCP_GREEN_HOST }}:8080/health/liveness; then | |
echo "Health check passed" | |
exit 0 | |
fi | |
echo "Attempt $i failed. Retrying..." | |
sleep 10 | |
done | |
exit 1 |