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
48 changes: 0 additions & 48 deletions .github/workflows/ci.yml

This file was deleted.

63 changes: 41 additions & 22 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
name: Deploy with Docker Hub
name: CI/CD Pipeline

on:
pull_request:
push:
branches: [ develop, main ]
types: [opened, synchronize, reopened, ready_for_review]

env:
DOCKER_IMAGE: leeeunda/blockcloud-server

jobs:
test:
build-and-test:
runs-on: ubuntu-latest
continue-on-error: true

steps:
- uses: actions/checkout@v4
# ์ฝ”๋“œ ์ฒดํฌ์•„์›ƒ
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

# JDK 21 ์„ค์ •
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
distribution: temurin

# Gradle ์บ์‹œ ์„ค์ •
- name: Cache Gradle
uses: actions/cache@v3
with:
Expand All @@ -32,26 +35,35 @@ jobs:
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: ${{ runner.os }}-gradle-

- name: Run tests (non-blocking)
run: ./gradlew test || true
# application.yml ์ƒ์„ฑ
- name: Create application.yml files
run: |
mkdir -p src/main/resources
echo "${{ secrets.APPLICATION_YML }}" > ./src/main/resources/application.yml
echo "${{ secrets.APPLICATION_YML_DEV }}" > ./src/main/resources/application-dev.yml
echo "${{ secrets.APPLICATION_YML_PROD }}" > ./src/main/resources/application-prod.yml
echo "${{ secrets.APPLICATION_YML_SECRET }}" > ./src/main/resources/application-secret.yml

build-and-push:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
# gradlew ์‹คํ–‰ ๊ถŒํ•œ ๋ถ€์—ฌ
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew

# Gradle ๋นŒ๋“œ ์‹คํ–‰
- name: Build with Gradle
run: ./gradlew clean build -x test

# Docker Hub ๋กœ๊ทธ์ธ
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

# Docker Buildx ์„ค์ •
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# Docker ์ด๋ฏธ์ง€ ๋นŒ๋“œ ๋ฐ ํ‘ธ์‹œ
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
Expand All @@ -60,13 +72,13 @@ jobs:
tags: |
${{ env.DOCKER_IMAGE }}:latest
${{ env.DOCKER_IMAGE }}:${{ github.sha }}
${{ env.DOCKER_IMAGE }}:${{ github.ref_name }}
${{ env.DOCKER_IMAGE }}:${{ github.event.pull_request.head.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
# platforms: linux/amd64 # Graviton์ด๋ฉด linux/arm64
platforms: linux/amd64

deploy-to-ec2:
needs: build-and-push
deploy:
needs: build-and-test
runs-on: ubuntu-latest
steps:
- name: Deploy to EC2 (pull & replace container)
Expand All @@ -80,22 +92,29 @@ jobs:
IMAGE="${{ env.DOCKER_IMAGE }}:${{ github.event.pull_request.head.sha }}"
docker pull "$IMAGE"

# ๊ธฐ์กด ์ปจํ…Œ์ด๋„ˆ ์ •๋ฆฌ
docker stop blockcloud-app || true
docker rm blockcloud-app || true

# ์ƒˆ ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰
docker run -d \
--name blockcloud-app \
--restart unless-stopped \
--env-file /srv/app/.env \
-e SPRING_PROFILES_ACTIVE=prod \
-p 127.0.0.1:8080:8080 \
"$IMAGE"

# ํ—ฌ์Šค์ฒดํฌ
for i in {1..30}; do
if curl -fsS http://127.0.0.1:8080/actuator/health >/dev/null 2>&1; then
echo "UP"
echo "โœ… Application is UP and healthy!"
exit 0
fi
echo "โณ Waiting for application to start... ($i/30)"
sleep 3
done

echo "โŒ Application failed to start properly"
docker logs --tail=200 blockcloud-app || true
exit 1
exit 1