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
97 changes: 97 additions & 0 deletions .github/workflows/cd-api-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: CD API DEV

on:
push:
branches: [ develop ]

jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
api_changed: ${{ steps.filter.outputs.api }}
Comment on lines +10 to +11
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이게 변수처럼 사용돼서 아래 build-api를 돌릴지 말지 결정하게 됩니다.

steps:
- uses: actions/checkout@v4
- id: filter
uses: dorny/paths-filter@v3
with:
filters: |
api:
- 'api/**'
Comment on lines +7 to +19
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal, api용 브랜치를 나누지 않기로 했으니, 이전에 논의했던 대로 파일 변경이 생긴 경우에만 trigger되도록 cd 파일을 분리했습니다.

찾아보니까 특정 폴더에 파일 변경이 생겼는지 알아보기 위해 dorny/paths-filter라는 액션을 많이 사용하길래 적용해봤습니다!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 확정이었을까요??

전에 말씀드린 것처럼 dev -> prod 로 merge 될때 각 모듈이 따로 배포 될 수 있도록 조절이 가능한 것일까요?

Copy link
Contributor Author

@kargowild kargowild Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 그 부분을 놓치고 구현했네요 😅
예를 들어 develop에는 api, internal 변경사항이 모두 생겼는데 api만 배포하고 싶은 상황 말씀하시는 거 맞을까요?
저번에 질문 드리다가 정리가 안됐었는데, 이 부분을 멘토님께 정리해서 질문드려봐야 할 것 같네요!!

이거 혹시 좀 더 구체적인 상황을 예시들어주실 수 있나요? 제가 좀 헷갈려서요 ㅠ


build-api:
needs: detect-changes
if: needs.detect-changes.outputs.api_changed == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '17'

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Grant execute permission for run-test-mysql-redis.sh
run: chmod +x run-test-mysql-redis.sh
working-directory: ./domain

- name: Run test mysql redis script
run: ./run-test-mysql-redis.sh
working-directory: ./domain

- name: Test & Build api only
run: ./gradlew :api:build

- name: Sign in Dockerhub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
Comment on lines +50 to +51
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 시크릿변수들 너무 공용으로 사용하니까 레포지토리마다 선언하는게 아니고 Organization secrets로 설정했습니다!
아직 기존 kokomen-backend에서는 Repository secrets를 사용하고 있는데, 겹치는 변수들은 삭제해도 될 것 같아요.

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네네 좋습니다!! 이슈, PR 템플릿도 organization 기준으로 설정 가능하던데, 고것도 한번 참고해서 적용하면 좋을 거 같네요!


- name: Build the Docker image
run: docker build -f ./Dockerfile --platform linux/amd64 --no-cache -t samhap/kokomen-notification-api:dev .
working-directory: ./api

- name: Push the Docker Image to Dockerhub
run: docker push samhap/kokomen-notification-api:dev
working-directory: ./api

deploy-api:
needs: build-api
runs-on: [ self-hosted, dev-notification ]
steps:
- name: Stop existing container
run: sudo docker rm -f kokomen-notification-dev-api || true

- name: Remove old API Docker image
run: |
if sudo docker images samhap/kokomen-notification-api:dev -q | grep -q .; then
sudo docker rmi -f samhap/kokomen-notification-api:dev || true
fi

- name: pull docker compose yaml files
working-directory: /home/ubuntu
run: |
[ -d kokomen-notification ] || git clone --filter=blob:none --no-checkout https://github.com/samhap-soft/kokomen-notification.git
cd kokomen-notification
git sparse-checkout init --cone
git fetch origin develop
git checkout develop
git sparse-checkout set docker/dev
git pull origin develop

- name: Docker Image pull
run: sudo docker pull samhap/kokomen-notification-api:dev

- name: Docker run
working-directory: /home/ubuntu
env:
MYSQL_ROOT_PASSWORD_DEV: ${{ secrets.MYSQL_ROOT_PASSWORD_DEV }}
SPRING_DATASOURCE_USERNAME_DEV: ${{ secrets.SPRING_DATASOURCE_USERNAME_DEV }}
SPRING_DATASOURCE_PASSWORD_DEV: ${{ secrets.SPRING_DATASOURCE_PASSWORD_DEV }}
run: |
export HOSTNAME=$(hostname)
cd kokomen-notification/docker/dev
sudo -E docker compose -f docker-compose-dev.yml up -d kokomen-notification-dev-api
97 changes: 97 additions & 0 deletions .github/workflows/cd-internal-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: CD INTERNAL DEV

on:
push:
branches: [ develop ]

jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
internal_changed: ${{ steps.filter.outputs.internal }}
steps:
- uses: actions/checkout@v4
- id: filter
uses: dorny/paths-filter@v3
with:
filters: |
internal:
- 'internal/**'

build-internal:
needs: detect-changes
if: needs.detect-changes.outputs.internal_changed == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '17'

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Grant execute permission for run-test-mysql-redis.sh
run: chmod +x run-test-mysql-redis.sh
working-directory: ./domain

- name: Run test mysql redis script
run: ./run-test-mysql-redis.sh
working-directory: ./domain

- name: Test & Build internal only
run: ./gradlew :internal:build

- name: Sign in Dockerhub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build the Docker image
run: docker build -f ./Dockerfile --platform linux/amd64 --no-cache -t samhap/kokomen-notification-internal:dev .
working-directory: ./internal

- name: Push the Docker Image to Dockerhub
run: docker push samhap/kokomen-notification-internal:dev
working-directory: ./internal

deploy-internal:
needs: build-internal
runs-on: [ self-hosted, dev-notification ]
steps:
- name: Stop existing container
run: sudo docker rm -f kokomen-notification-dev-internal || true

- name: Remove old INTERNAL Docker image
run: |
if sudo docker images samhap/kokomen-notification-internal:dev -q | grep -q .; then
sudo docker rmi -f samhap/kokomen-notification-internal:dev || true
fi

- name: pull docker compose yaml files
working-directory: /home/ubuntu
run: |
[ -d kokomen-notification ] || git clone --filter=blob:none --no-checkout https://github.com/samhap-soft/kokomen-notification.git
cd kokomen-notification
git sparse-checkout init --cone
git fetch origin develop
git checkout develop
git sparse-checkout set docker/dev
git pull origin develop

- name: Docker Image pull
run: sudo docker pull samhap/kokomen-notification-internal:dev

- name: Docker run
working-directory: /home/ubuntu
env:
MYSQL_ROOT_PASSWORD_DEV: ${{ secrets.MYSQL_ROOT_PASSWORD_DEV }}
SPRING_DATASOURCE_USERNAME_DEV: ${{ secrets.SPRING_DATASOURCE_USERNAME_DEV }}
SPRING_DATASOURCE_PASSWORD_DEV: ${{ secrets.SPRING_DATASOURCE_PASSWORD_DEV }}
run: |
export HOSTNAME=$(hostname)
cd kokomen-notification/docker/dev
sudo -E docker compose -f docker-compose-dev.yml up -d kokomen-notification-dev-internal
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-d 뒤에 애플리케이션 컨테이너만 실행하도록 구체적으로 명시했습니다

65 changes: 65 additions & 0 deletions .github/workflows/ci-api-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: CI API TEST

on:
pull_request:
branches: [ main, develop ]

jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
api_changed: ${{ steps.filter.outputs.api }}
steps:
- uses: actions/checkout@v4
- id: filter
uses: dorny/paths-filter@v3
with:
filters: |
api:
- 'api/**'

build:
needs: detect-changes
if: needs.detect-changes.outputs.api_changed == 'true'
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '17'

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Grant execute permission for run-test-mysql-redis.sh
run: chmod +x run-test-mysql-redis.sh
working-directory: ./domain

- name: Run test mysql redis script
run: ./run-test-mysql-redis.sh
working-directory: ./domain

- name: Test & Build api only
run: ./gradlew :api:build

- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: ${{ always() }}
with:
files: ${{ github.workspace }}/api/build/test-results/**/*.xml
seconds_between_github_reads: 1.0
seconds_between_github_writes: 3.0
secondary_rate_limit_wait_seconds: 90.0

- name: When test fail, comment on that code
uses: mikepenz/action-junit-report@v3
if: always()
with:
report_paths: ${{ github.workspace }}/api/build/test-results/**/*.xml
token: ${{ github.token }}
65 changes: 65 additions & 0 deletions .github/workflows/ci-internal-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: CI INTERNAL TEST

on:
pull_request:
branches: [ main, develop ]

jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
internal_changed: ${{ steps.filter.outputs.internal }}
steps:
- uses: actions/checkout@v4
- id: filter
uses: dorny/paths-filter@v3
with:
filters: |
internal:
- 'internal/**'

build:
needs: detect-changes
if: needs.detect-changes.outputs.internal_changed == 'true'
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '17'

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Grant execute permission for run-test-mysql-redis.sh
run: chmod +x run-test-mysql-redis.sh
working-directory: ./domain

- name: Run test mysql redis script
run: ./run-test-mysql-redis.sh
working-directory: ./domain

- name: Test & Build internal only
run: ./gradlew :internal:build

- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: ${{ always() }}
with:
files: ${{ github.workspace }}/internal/build/test-results/**/*.xml
seconds_between_github_reads: 1.0
seconds_between_github_writes: 3.0
secondary_rate_limit_wait_seconds: 90.0

- name: When test fail, comment on that code
uses: mikepenz/action-junit-report@v3
if: always()
with:
report_paths: ${{ github.workspace }}/internal/build/test-results/**/*.xml
token: ${{ github.token }}
Loading