-
Notifications
You must be signed in to change notification settings - Fork 0
chore: Github Actions CI/CD 파이프라인 구축 #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
556c90e
chore: Github Actions CI/CD 파이프라인 구축
Woomin-Wang f31714c
fix: 테스트 코드 제거
Woomin-Wang be9c0fe
fix: JPA 설정 update로 변경
Woomin-Wang 8d9fc70
fix: JPA 설정 update로 변경
Woomin-Wang aaad966
fix: CI 테스트 프로파일용 application-test.yml 추가
Woomin-Wang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| name: CD | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: ['CI'] | ||
| types: [completed] | ||
|
|
||
| jobs: | ||
| # ============================================ | ||
| # 서버 배포 | ||
| # ============================================ | ||
| deploy: | ||
| name: Deploy to Wisoft Server | ||
| runs-on: ubuntu-latest | ||
| if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' }} | ||
|
|
||
| steps: | ||
| - name: SSH 키 설정 | ||
| uses: webfactory/ssh-agent@v0.9.0 | ||
| with: | ||
| ssh-private-key: ${{ secrets.RASPI_SSH_PRIVATE_KEY }} | ||
|
|
||
| - name: Known Hosts 등록 | ||
| env: | ||
| JUMP_PORT: ${{ secrets.RASPI_SSH_PORT }} | ||
| JUMP_HOST: ${{ secrets.RASPI_HOST }} | ||
| run: | | ||
| mkdir -p ~/.ssh | ||
| ssh-keyscan -p $JUMP_PORT -H $JUMP_HOST >> ~/.ssh/known_hosts | ||
|
|
||
| - name: 서버에 배포 | ||
| env: | ||
| JUMP_PORT: ${{ secrets.RASPI_SSH_PORT }} | ||
| JUMP_HOST: ${{ secrets.RASPI_HOST }} | ||
| JUMP_USER: ${{ secrets.RASPI_USER }} | ||
| TARGET_HOST: ${{ secrets.RASPI_TARGET_HOST }} | ||
| TARGET_USER: ${{ secrets.RASPI_TARGET_USER }} | ||
| DEPLOY_PATH: ${{ secrets.RASPI_DEPLOY_PATH_JAVA }} | ||
| GHCR_PAT: ${{ secrets.GHCR_PAT }} | ||
| GITHUB_ACTOR: ${{ github.actor }} | ||
| run: | | ||
| ssh -o StrictHostKeyChecking=no -o ProxyJump=$JUMP_USER@$JUMP_HOST:$JUMP_PORT $TARGET_USER@$TARGET_HOST /bin/bash << ENDSSH | ||
| set -e | ||
|
|
||
| echo "=== 배포 디렉토리 이동 ===" | ||
| cd $DEPLOY_PATH | ||
|
|
||
| echo "=== GHCR 로그인 ===" | ||
| echo "$GHCR_PAT" | docker login ghcr.io -u "$GITHUB_ACTOR" --password-stdin | ||
|
|
||
| echo "=== 최신 이미지 Pull ===" | ||
| docker compose -f docker/docker-compose.prod.yml --env-file .env pull app | ||
|
|
||
| echo "=== 앱 컨테이너 재시작 ===" | ||
| docker compose -f docker/docker-compose.prod.yml --env-file .env up -d app | ||
|
|
||
| echo "=== Health Check (최대 60초) ===" | ||
| for i in \$(seq 1 12); do | ||
| if curl -sf http://localhost:7300/health > /dev/null; then | ||
| echo "Health check 통과" | ||
| exit 0 | ||
| fi | ||
| echo "재시도 \$i/12" | ||
| sleep 5 | ||
| done | ||
|
|
||
| echo "Health check 실패" | ||
| docker compose -f docker/docker-compose.prod.yml logs --tail=50 app | ||
| exit 1 | ||
| ENDSSH | ||
|
|
||
| - name: 오래된 Docker 이미지 정리 | ||
| if: success() | ||
| env: | ||
| JUMP_PORT: ${{ secrets.RASPI_SSH_PORT }} | ||
| JUMP_HOST: ${{ secrets.RASPI_HOST }} | ||
| JUMP_USER: ${{ secrets.RASPI_USER }} | ||
| TARGET_HOST: ${{ secrets.RASPI_TARGET_HOST }} | ||
| TARGET_USER: ${{ secrets.RASPI_TARGET_USER }} | ||
| run: | | ||
| ssh -o StrictHostKeyChecking=no -o ProxyJump=$JUMP_USER@$JUMP_HOST:$JUMP_PORT $TARGET_USER@$TARGET_HOST /bin/bash << ENDSSH | ||
| docker image prune -af --filter "until=72h" || true | ||
| ENDSSH |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - "*/**" | ||
| - main | ||
| pull_request: | ||
| branches: | ||
| - "*/**" | ||
| - main | ||
|
|
||
| jobs: | ||
| # ============================================ | ||
| # Job 1: 테스트 | ||
| # ============================================ | ||
| test: | ||
| name: Test | ||
| runs-on: ubuntu-latest | ||
|
|
||
| services: | ||
| postgres: | ||
| image: postgres:17 | ||
| env: | ||
| POSTGRES_USER: test | ||
| POSTGRES_PASSWORD: test | ||
| POSTGRES_DB: interview_test | ||
| ports: | ||
| - 5432:5432 | ||
| options: >- | ||
| --health-cmd pg_isready | ||
| --health-interval 10s | ||
| --health-timeout 5s | ||
| --health-retries 5 | ||
|
|
||
| steps: | ||
| - name: 코드 체크아웃 | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: JDK 21 설정 | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| java-version: '21' | ||
| distribution: 'temurin' | ||
|
|
||
| - name: Gradle 캐싱 | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: | | ||
| ~/.gradle/caches | ||
| ~/.gradle/wrapper | ||
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-gradle- | ||
|
|
||
| - name: 테스트 실행 | ||
| env: | ||
| SPRING_PROFILES_ACTIVE: test | ||
| run: ./gradlew test --no-daemon | ||
|
|
||
| # ============================================ | ||
| # Job 2: Docker 이미지 빌드 + GHCR 푸시 | ||
| # ============================================ | ||
| build: | ||
| name: Build & Push Docker Image | ||
| runs-on: ubuntu-latest | ||
| needs: test | ||
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | ||
|
|
||
| permissions: | ||
| contents: read | ||
| packages: write | ||
|
|
||
| steps: | ||
| - name: 코드 체크아웃 | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Docker Buildx 설정 | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: GHCR 로그인 | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: 이미지 메타데이터 설정 | ||
| id: meta | ||
| uses: docker/metadata-action@v5 | ||
| with: | ||
| images: ghcr.io/${{ github.repository }} | ||
| tags: | | ||
| type=raw,value=latest | ||
| type=sha,prefix= | ||
|
|
||
| - name: Docker 이미지 빌드 & 푸시 | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| platforms: linux/arm64 | ||
| push: true | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ services: | |
| app: | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile | ||
| dockerfile: Dockerfile.prev | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| container_name: interview-api | ||
| ports: | ||
| - "7300:7300" | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| services: | ||
| fluent-bit: | ||
| image: fluent/fluent-bit:3.2 | ||
| container_name: interview-fluent-bit | ||
| volumes: | ||
| - ./fluentbit/fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf:ro | ||
| - ./fluentbit/parsers.conf:/fluent-bit/etc/parsers.conf:ro | ||
|
Comment on lines
+6
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ports: | ||
| - "24224:24224" | ||
| environment: | ||
| - ELASTIC_USERNAME=${ELASTIC_USERNAME} | ||
| - ELASTIC_PASSWORD=${ELASTIC_PASSWORD} | ||
| networks: | ||
| - interview-network | ||
| - logging-network | ||
| restart: unless-stopped | ||
|
|
||
| postgres: | ||
| image: postgres:17 | ||
| container_name: interview-postgres | ||
| ports: | ||
| - "${POSTGRES_PORT}:5432" | ||
| environment: | ||
| - POSTGRES_DB=${POSTGRES_DB} | ||
| - POSTGRES_USER=${POSTGRES_USER} | ||
| - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} | ||
| volumes: | ||
| - postgres-data:/var/lib/postgresql/data | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 5 | ||
| networks: | ||
| - interview-network | ||
| restart: unless-stopped | ||
|
|
||
| app: | ||
| image: ghcr.io/wisoft-prepair/backend-java:latest | ||
| container_name: interview-api | ||
| ports: | ||
| - "7300:7300" | ||
| env_file: | ||
| - .env | ||
| environment: | ||
| - SPRING_PROFILES_ACTIVE=prod | ||
| - TZ=Asia/Seoul | ||
| depends_on: | ||
| postgres: | ||
| condition: service_healthy | ||
| fluent-bit: | ||
| condition: service_started | ||
| logging: | ||
| driver: fluentd | ||
| options: | ||
| fluentd-address: localhost:24224 | ||
| tag: interview-service | ||
| fluentd-async: "true" | ||
| networks: | ||
| - interview-network | ||
| restart: unless-stopped | ||
|
|
||
| volumes: | ||
| postgres-data: | ||
|
|
||
| networks: | ||
| interview-network: | ||
| driver: bridge | ||
| logging-network: | ||
| external: true | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -7,6 +7,6 @@ spring: | |
|
|
||
| jpa: | ||
| hibernate: | ||
| ddl-auto: validate | ||
| ddl-auto: update | ||
| open-in-view: false | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HEALTHCHECK의
interval이 24시간(24h)으로 설정되어 있습니다. 이는 컨테이너의 상태 변화를 감지하기에 너무 긴 시간입니다. 일반적으로 30초(30s) 또는 1분(1m) 정도로 설정하는 것이 적절합니다. 또한, Spring Boot Actuator를 의존성에 추가하셨으므로 기본 헬스체크 경로인/actuator/health를 사용하는 것이 좋습니다.