-
Notifications
You must be signed in to change notification settings - Fork 0
워크 플로 분리 Spring / FastAPI #125
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
6 commits
Select commit
Hold shift + click to select a range
ca638c4
refactor : 워크플로, docker-compose, promtail 분리
rll2641 fc6646c
refactor : logging_config 경로 변경 로컬 -> 도커 컨테이너
rll2641 2ccc778
Merge branch 'develop' into refactor/separate-environment
rll2641 67ae725
chore : 환경변수 이름 변경
rll2641 b1f9b25
FASTAPI_HOST 추가
rll2641 c2d61b4
포트 변경
rll2641 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
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,148 @@ | ||
| name: Deploy FastAPI | ||
| on: | ||
| push: | ||
| branches: | ||
| - fix/** | ||
| workflow_run: | ||
| workflows: ["CI (Python/FastAPI)"] | ||
| types: [completed] | ||
|
|
||
| jobs: | ||
| deploy: | ||
| name: Deploy to AWS FastAPI EC2 | ||
| runs-on: ubuntu-latest | ||
| if: | | ||
| github.event.workflow_run.conclusion == 'success' && | ||
| startsWith(github.event.workflow_run.head_branch, 'pre-processing-v') | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Create env file | ||
| run: | | ||
| echo "DB_HOST=${{ secrets.DB_HOST }}" > .env.prod | ||
| echo "DB_PORT=${{ secrets.DB_PORT }}" >> .env.prod | ||
| echo "DB_USER=${{ secrets.DB_USER }}" >> .env.prod | ||
| echo "DB_PASS=${{ secrets.DB_PASS }}" >> .env.prod | ||
| echo "DB_NAME=${{ secrets.DB_NAME }}" >> .env.prod | ||
| echo "LOKI_HOST=${{ secrets.LOKI_HOST }}" >> .env.prod | ||
| echo "LOKI_USERNAME=${{ secrets.LOKI_USERNAME }}" >> .env.prod | ||
| echo "LOKI_PASSWORD=${{ secrets.LOKI_PASSWORD }}" >> .env.prod | ||
| echo "ENV_NAME=${{ secrets.ENV_NAME }}" >> .env.prod | ||
| echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> .env.prod | ||
|
|
||
| - name: Set repo lowercase | ||
| run: echo "REPO_LC=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV | ||
|
|
||
| - name: Copy docker compose files to FastAPI EC2 | ||
| uses: appleboy/scp-action@v0.1.7 | ||
| with: | ||
| host: ${{ secrets.FASTAPI_SERVER_HOST }} | ||
| username: ubuntu | ||
| key: ${{ secrets.SERVER_SSH_KEY }} | ||
| source: "docker/production-fastapi/docker-compose.yml" | ||
| target: "~/app" | ||
|
|
||
| - name: Copy .env.prod file to FastAPI EC2 | ||
| uses: appleboy/scp-action@v0.1.7 | ||
| with: | ||
| host: ${{ secrets.FASTAPI_SERVER_HOST }} | ||
| username: ubuntu | ||
| key: ${{ secrets.SERVER_SSH_KEY }} | ||
| source: ".env.prod" | ||
| target: "~/app/docker/production/" | ||
| overwrite: true | ||
|
|
||
| - name: Copy promtail-config to FastAPI EC2 | ||
| uses: appleboy/scp-action@v0.1.7 | ||
| with: | ||
| host: ${{ secrets.FASTAPI_SERVER_HOST }} | ||
| username: ubuntu | ||
| key: ${{ secrets.SERVER_SSH_KEY }} | ||
| source: "docker/production-fastapi/promtail-config.yml" | ||
| target: "~/app/docker/production/" | ||
| overwrite: true | ||
|
|
||
| - name: Check ONNX model on FastAPI EC2 | ||
| id: check-onnx | ||
| uses: appleboy/ssh-action@v1.0.3 | ||
| with: | ||
| host: ${{ secrets.FASTAPI_SERVER_HOST }} | ||
| username: ubuntu | ||
| key: ${{ secrets.SERVER_SSH_KEY }} | ||
| script: | | ||
| if [ -f "~/app/models/klue_bert.onnx" ]; then | ||
| echo "exists=true" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "exists=false" >> $GITHUB_OUTPUT | ||
| fi | ||
|
|
||
| - name: Copy ONNX to FastAPI EC2 | ||
| if: steps.check-onnx.outputs.exists == 'false' | ||
| uses: appleboy/scp-action@v0.1.7 | ||
| with: | ||
| host: ${{ secrets.FASTAPI_SERVER_HOST }} | ||
| username: ubuntu | ||
| key: ${{ secrets.SERVER_SSH_KEY }} | ||
| source: "apps/pre-processing-service/klue_bert.onnx" | ||
| target: "~/app/models/" | ||
| overwrite: false | ||
|
|
||
| - name: Deploy on EC2 | ||
| uses: appleboy/ssh-action@v1.0.3 | ||
| with: | ||
| host: ${{secrets.FASTAPI_SERVER_HOST}} | ||
| username: ubuntu | ||
| key: ${{secrets.SERVER_SSH_KEY}} | ||
| script: | | ||
| cd ~/app/docker/production | ||
|
|
||
| echo "${{secrets.GITHUB_TOKEN}}" | docker login ghcr.io -u ${{github.actor}} --password-stdin | ||
|
|
||
| docker-compose pull | ||
|
|
||
| docker-compose down | ||
|
|
||
| docker-compose up -d | ||
|
|
||
| sleep 5 | ||
| docker-compose ps | ||
|
|
||
| echo "Waiting for containers to become healthy..." | ||
| for i in {1..30}; do | ||
| unhealthy=$(docker ps --filter "health=unhealthy" --format "{{.Names}}") | ||
| starting=$(docker ps --filter "health=starting" --format "{{.Names}}") | ||
| if [ -z "$unhealthy" ] && [ -z "$starting" ]; then | ||
| echo "All containers are healthy!" | ||
| break | ||
| fi | ||
| echo "Waiting... ($i/30)" | ||
| sleep 2 | ||
| done | ||
|
|
||
| docker image prune -f | ||
|
|
||
| - name: Send Discord notification - Success | ||
| if: success() | ||
| uses: Ilshidur/action-discord@master | ||
| env: | ||
| DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }} | ||
| with: | ||
| args: | | ||
| **배포 성공** | ||
| **Repository:** ${{ env.REPO_LC }} | ||
| **Tag:** ${{ github.ref_name }} | ||
| **Server:** ${{ secrets.FASTAPI_SERVER_HOST }} | ||
| **Status:** Success! | ||
|
|
||
| - name: Send Discord notification - Failure | ||
| if: failure() | ||
| uses: Ilshidur/action-discord@master | ||
| env: | ||
| DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }} | ||
| with: | ||
| args: | | ||
| **배포 실패** | ||
| **Repository:** ${{ env.REPO_LC }} | ||
| **Tag:** ${{ github.ref_name }} | ||
| **Error:** 배포 중 오류가 발생했습니다. | ||
| **Check:** ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
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 |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| .idea | ||
| logs | ||
| *.log | ||
| *.env* | ||
| *.env* | ||
|
|
||
| *.onnx |
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 |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| version: "3.9" | ||
|
Collaborator
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. 이렇게 했을 때 Spring에서 http 요청 시 8000으로 쏘는건가요? |
||
|
|
||
| services: | ||
| pre-processing-service: | ||
| image: ghcr.io/kernel180-be12/final-4team-icebang/pre-processing-service:latest | ||
| container_name: pre-processing-service | ||
| restart: on-failure:3 | ||
| ports: | ||
| - "80:8000" | ||
| volumes: | ||
| - ./models:/app/models | ||
| - logs_volume:/logs | ||
| depends_on: | ||
| - promtail | ||
| env_file: | ||
| - .env.prod | ||
|
|
||
| promtail: | ||
| image: grafana/promtail:2.9.0 | ||
| container_name: promtail | ||
| restart: unless-stopped | ||
| volumes: | ||
| - ./promtail-config.yml:/etc/promtail/config.yml:ro | ||
| - logs_volume:/logs | ||
| command: | ||
| - -config.file=/etc/promtail/config.yml | ||
| - -config.expand-env=true | ||
| ulimits: | ||
| nofile: | ||
| soft: 65535 | ||
| hard: 65535 | ||
| env_file: | ||
| - .env.prod | ||
|
|
||
| volumes: | ||
| logs_volume: | ||
| driver: local | ||
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.
java 쪽 fast api url을 넣어줘야 spring에서 호출 할 수 있을 것 같습니다