-
Notifications
You must be signed in to change notification settings - Fork 0
[26.03.25 / TASK-267] Chore - CD workflow 추가 #52
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
Changes from all commits
4794629
b4a9225
6916361
752e39b
80d14f3
1b74cc6
462540b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,109 @@ | ||
| name: API CD | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - 'v*' | ||
| workflow_dispatch: | ||
| inputs: | ||
| version: | ||
| description: '롤백할 버전 (ex: v1.6.0)' | ||
| required: true | ||
|
|
||
| jobs: | ||
| docker-deploy: | ||
| build-and-push: | ||
| runs-on: ubuntu-latest | ||
| if: github.event_name == 'push' | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Log in to Docker Hub | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| username: ${{ secrets.DOCKER_USERNAME }} | ||
| password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
|
||
| - name: Build and Push Docker Image | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| push: true | ||
| tags: | | ||
| ${{ secrets.DOCKER_USERNAME }}/velog-dashboard-v2-api:latest | ||
| ${{ secrets.DOCKER_USERNAME }}/velog-dashboard-v2-api:${{ github.ref_name }} | ||
| platforms: linux/amd64 | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
|
|
||
| deploy: | ||
| runs-on: ubuntu-latest | ||
| needs: [build-and-push] | ||
| if: always() && (needs.build-and-push.result == 'success' || needs.build-and-push.result == 'skipped') | ||
|
|
||
| steps: | ||
| - name: Validate deploy version | ||
| id: version | ||
| run: | | ||
| RAW="${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version || github.ref_name }}" | ||
| if [[ ! "$RAW" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
| echo "Invalid version format: $RAW" | ||
| exit 1 | ||
| fi | ||
| echo "value=$RAW" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Deploy to Server 1 | ||
| uses: appleboy/ssh-action@v1 | ||
| with: | ||
| host: ${{ secrets.DEPLOY_HOST_1 }} | ||
| username: ${{ secrets.DEPLOY_USER }} | ||
| key: ${{ secrets.DEPLOY_SSH_KEY_1 }} | ||
| command_timeout: 15m | ||
| script: | | ||
| export GIT_SSH_COMMAND='ssh -i ~/.ssh/velog-dashboard-v2-api' | ||
| export API_VERSION="${{ steps.version.outputs.value }}" | ||
| cd ${{ secrets.DEPLOY_PATH }} | ||
| git fetch --tags | ||
| git checkout "$API_VERSION" | ||
| bash run.sh | ||
|
|
||
| - name: Deploy to Server 2 | ||
| uses: appleboy/ssh-action@v1 | ||
| with: | ||
| host: ${{ secrets.DEPLOY_HOST_2 }} | ||
| username: ${{ secrets.DEPLOY_USER }} | ||
| key: ${{ secrets.DEPLOY_SSH_KEY_2 }} | ||
| command_timeout: 15m | ||
| script: | | ||
| export GIT_SSH_COMMAND='ssh -i ~/.ssh/velog-dashboard-v2-api' | ||
| export API_VERSION="${{ steps.version.outputs.value }}" | ||
| cd ${{ secrets.DEPLOY_PATH }} | ||
| git fetch --tags | ||
| git checkout "$API_VERSION" | ||
| bash run.sh | ||
ooheunda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - name: Notify Slack on Success | ||
| if: success() | ||
| uses: slackapi/slack-github-action@v1.24.0 | ||
| with: | ||
| payload: | | ||
| { | ||
| "text": "✅ API 배포 성공\n• 버전: ${{ steps.version.outputs.value }}\n• 트리거: ${{ github.actor }}\n• <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|액션 로그>" | ||
| } | ||
| env: | ||
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
|
|
||
| - name: Notify Slack on Failure | ||
| if: failure() | ||
| uses: slackapi/slack-github-action@v1.24.0 | ||
ooheunda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| with: | ||
| payload: | | ||
| { | ||
| "text": "❌ API 배포 실패\n• 버전: ${{ steps.version.outputs.value }}\n• 트리거: ${{ github.actor }}\n• <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|액션 로그>" | ||
| } | ||
| env: | ||
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ services: | |
| # context: . | ||
| # dockerfile: Dockerfile | ||
| # image: velog-dashboard-v2-api | ||
| image: nuung/velog-dashboard-v2-api:latest | ||
| image: nuung/velog-dashboard-v2-api:${API_VERSION:-latest} | ||
|
Member
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. 제가 가물가물해서 그런데 이 환경변수 깃헙에서 자동으로 tag 버전 가져오는거 맞나요? 저는
Member
Author
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. 여기서 지정한 임의 환경변수입니다!
Member
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. 아 오케이 전역 변수 중 있는 줄 |
||
| hostname: velog-dashboard-v2-api | ||
| container_name: velog-dashboard-v2-api | ||
| ports: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.