-
Notifications
You must be signed in to change notification settings - Fork 0
백엔드 릴리즈 워크플로우 분리 및 자동화 #234
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
Open
Goder-0
wants to merge
1
commit into
main
Choose a base branch
from
feature/#233-backend-release-workflow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+430
−213
Open
Changes from all commits
Commits
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
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 |
|---|---|---|
| @@ -1,90 +1,74 @@ | ||
| name: ✨ Linkiving backend CD ✨ | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| pull_request: | ||
| types: [ closed ] | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| backend-docker-build-and-push: | ||
| if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request' }} | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: ✨ Checkout repository | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: ✨ JDK 17 설정 | ||
| uses: actions/setup-java@v3 | ||
| with: | ||
| java-version: '17' | ||
| distribution: 'temurin' | ||
|
|
||
| - name: ✨ Gradle Caching | ||
| uses: actions/cache@v3 | ||
| with: | ||
| path: | | ||
| ~/.gradle/caches | ||
| ~/.gradle/wrapper | ||
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-gradle- | ||
|
|
||
| - name: 🗂️ Make config | ||
| run: | | ||
| # src/main/resources 경로 이동 | ||
| mkdir -p ./src/main/resources | ||
| cd ./src/main/resources | ||
|
|
||
| # yml 파일 생성 | ||
|
|
||
| touch ./application.yml | ||
| echo "$APPLICATION" > ./application.yml | ||
|
|
||
| env: | ||
| APPLICATION: ${{ secrets.APPLICATION }} | ||
| shell: bash | ||
|
|
||
| - name: ✨ Gradlew 권한 설정 | ||
| run: chmod +x ./gradlew | ||
|
|
||
| - name: ✨ Jar 파일 빌드 | ||
| run: | | ||
| ./gradlew bootJar | ||
|
|
||
| - name: ✨ DockerHub에 로그인 | ||
| uses: docker/login-action@v2 | ||
| with: | ||
| username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
| password: ${{ secrets.DOCKER_HUB_PASSWORD }} | ||
|
|
||
| - name: ✨ Docker Image 빌드 후 DockerHub에 Push | ||
| uses: docker/build-push-action@v4 | ||
| with: | ||
| context: . | ||
| file: ./docker/Dockerfile | ||
| push: true | ||
| platforms: linux/amd64 | ||
| tags: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPOSITORY }}:latest | ||
|
|
||
| backend-docker-pull-and-run: | ||
| runs-on: [ self-hosted, prod ] | ||
| needs: [ backend-docker-build-and-push ] | ||
| if: ${{ needs.backend-docker-build-and-push.result == 'success' && (github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true) }} | ||
|
|
||
| steps: | ||
| - name: ✨ Checkout repository | ||
| uses: actions/checkout@v5 | ||
|
|
||
| - name: 🗂️ Grafana 환경변수 설정 | ||
| run: | | ||
| echo "GRAFANA_ADMIN_USER=admin" > ./docker/.env | ||
| echo "GRAFANA_ADMIN_PASSWORD=${{ secrets.GRAFANA_ADMIN_PASSWORD }}" >> ./docker/.env | ||
| shell: bash | ||
|
|
||
| - name: ✨ 배포 스크립트 실행 | ||
| run: | | ||
| chmod +x deploy.sh | ||
| ./deploy.sh | ||
| name: ✨ Linkiving backend local bundle CD ✨ | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
| branches: | ||
| - main | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: backend-local-bundle-${{ github.event.pull_request.number || github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| build-local-bundle: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: ✨ Checkout repository | ||
| uses: actions/checkout@v5 | ||
|
|
||
| - name: ✨ JDK 17 설정 | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| java-version: '17' | ||
| distribution: 'temurin' | ||
|
|
||
| - name: ✨ Gradle caching | ||
| 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: 🗂️ Create local application profile | ||
| shell: bash | ||
| env: | ||
| APPLICATION_LOCAL: ${{ secrets.APPLICATION_LOCAL }} | ||
| run: | | ||
| mkdir -p ./src/main/resources | ||
| printf '%s\n' "$APPLICATION_LOCAL" > ./src/main/resources/application-local.yml | ||
|
|
||
| grep -q '^spring:' ./src/main/resources/application-local.yml | ||
| grep -q '^security:' ./src/main/resources/application-local.yml | ||
| grep -q '^app:' ./src/main/resources/application-local.yml | ||
|
|
||
| - name: ✨ Executable permissions | ||
| run: chmod +x ./gradlew ./scripts/prepare-local-bundle.sh | ||
|
|
||
| - name: ✨ Jar 파일 빌드 | ||
| run: ./gradlew bootJar | ||
|
|
||
| - name: 🐳 Build local Docker bundle | ||
| env: | ||
| BUNDLE_VERSION: ${{ github.event_name == 'pull_request' && format('pr-{0}-{1}', github.event.pull_request.number, github.sha) || format('main-{0}', github.sha) }} | ||
| IMAGE_TAG: linkiving-local:${{ github.sha }} | ||
| run: ./scripts/prepare-local-bundle.sh | ||
|
|
||
| - name: 📦 Upload local bundle artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: linkiving-core-local-bundle-${{ github.run_number }} | ||
| path: | | ||
| dist/*.zip | ||
| dist/*.sha256 | ||
| retention-days: 14 |
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,95 @@ | ||
| name: 🚀 Linkiving backend release deploy 🚀 | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - 'v*' | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| concurrency: | ||
| group: backend-release-${{ github.ref }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| backend-docker-build-and-push: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: ✨ Checkout repository | ||
| uses: actions/checkout@v5 | ||
|
|
||
| - name: ✨ JDK 17 설정 | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| java-version: '17' | ||
| distribution: 'temurin' | ||
|
|
||
| - name: ✨ Gradle caching | ||
| 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: 🗂️ Make production config | ||
| shell: bash | ||
| env: | ||
| APPLICATION: ${{ secrets.APPLICATION }} | ||
| run: | | ||
| mkdir -p ./src/main/resources | ||
| printf '%s' "$APPLICATION" > ./src/main/resources/application.yml | ||
|
|
||
| - name: ✨ Gradlew 권한 설정 | ||
| run: chmod +x ./gradlew | ||
|
|
||
| - name: ✨ Jar 파일 빌드 | ||
| run: ./gradlew bootJar | ||
|
|
||
| - name: ✨ DockerHub에 로그인 | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
| password: ${{ secrets.DOCKER_HUB_PASSWORD }} | ||
|
|
||
| - name: ✨ Docker image 빌드 후 DockerHub에 push | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| file: ./docker/Dockerfile | ||
| push: true | ||
| platforms: linux/amd64 | ||
| tags: | | ||
| ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPOSITORY }}:${{ github.ref_name }} | ||
| ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPOSITORY }}:latest | ||
|
|
||
| backend-docker-pull-and-run: | ||
| runs-on: [ self-hosted, prod ] | ||
| needs: [ backend-docker-build-and-push ] | ||
| if: ${{ needs.backend-docker-build-and-push.result == 'success' }} | ||
|
|
||
| steps: | ||
| - name: ✨ Checkout repository | ||
| uses: actions/checkout@v5 | ||
|
|
||
| - name: ✨ 배포 스크립트 실행 | ||
| env: | ||
| IMAGE_TAG: ${{ github.ref_name }} | ||
| run: | | ||
| chmod +x deploy.sh | ||
| ./deploy.sh | ||
|
|
||
| create-release: | ||
| runs-on: ubuntu-latest | ||
| needs: [ backend-docker-pull-and-run ] | ||
| if: ${{ needs.backend-docker-pull-and-run.result == 'success' }} | ||
|
|
||
| steps: | ||
| - name: 📝 Create GitHub release | ||
| uses: softprops/action-gh-release@v2 | ||
| with: | ||
| generate_release_notes: 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,4 +37,5 @@ out/ | |
| *.yml | ||
| !docker/prometheus.yml | ||
| !docker/grafana/**/*.yml | ||
| !docker/local-bundle/*.yml | ||
| .editorconfig | ||
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
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.
release.yml이 이미지를 :${{ github.ref_name }}과 :latest 두 태그로 푸시하는 점은 좋은 것 같습니다.다만 실제 배포 경로를 보면,
deploy.sh가docker compose pull을 사용하고docker/docker-compose.yml의 blue/green이image: linkivingsofa/core:latest로 고정되어 있어서, 어떤 버전 태그로 릴리즈하든 운영에는 항상latest가 배포됩니다.이로 인해:
버전 태그 릴리즈의 의미를 살리려면, 배포 시 이미지 태그를 주입하는 방식이 더 좋을 것 같습니다.
예를 들어 compose의 image를
linkivingsofa/core:${IMAGE_TAG:-latest}로 두고,release.yml에서IMAGE_TAG=${{ github.ref_name }}를 deploy 단계에 전달하면, pull이 해당 버전을 받고 롤백도 태그 변경으로 가능해질 것 같습니다.