Skip to content

feat: docker-compose 설정 및 배포 스크립트 추가 #1

feat: docker-compose 설정 및 배포 스크립트 추가

feat: docker-compose 설정 및 배포 스크립트 추가 #1

Workflow file for this run

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:
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: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Test with Gradle
run: ./gradlew test
build-and-push:
needs: test
if: github.ref == 'refs/heads/main'
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
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: root
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: root
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: |
for i in {1..10}; do
if curl -s -f http://${{ secrets.NCP_BLUE_HOST }}:8080/actuator/health; then
echo "Health check passed"
exit 0
fi
echo "Attempt $i failed. Retrying..."
sleep 30
done
echo "Health check failed after 10 attempts"
exit 1
deploy-green:
needs: deploy-blue
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Copy docker-compose files
uses: appleboy/scp-action@master
with:
username: root
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: root
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