fix(deps): pin Flask-Session version to resolve docker build collision #53
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
| name: Deploy to VPS | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| build_and_deploy: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Basic Syntax Check | |
| run: | | |
| python -m py_compile server.py | |
| python -m py_compile fetcher.py | |
| - name: Log in to the Container registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=latest | |
| type=sha,format=long | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| provenance: false | |
| - name: Deploy to VPS via SSH | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.VPS_HOST }} | |
| username: ${{ secrets.VPS_USERNAME }} | |
| key: ${{ secrets.VPS_SSH_KEY }} | |
| port: ${{ secrets.VPS_PORT }} | |
| script: | | |
| # 登入 GHCR | |
| echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
| # 確保 overlay 網路存在 | |
| docker network create -d overlay app_network || true | |
| # 使用明確 SHA tag 更新應用程式服務 (避免 latest 不觸發更新的問題) | |
| if docker service inspect school_grades_app > /dev/null 2>&1; then | |
| docker service update \ | |
| --with-registry-auth \ | |
| --image ghcr.io/${{ github.repository }}:sha-${{ github.sha }} \ | |
| school_grades_app | |
| else | |
| docker service create \ | |
| --with-registry-auth \ | |
| --name school_grades_app \ | |
| --network app_network \ | |
| ghcr.io/${{ github.repository }}:sha-${{ github.sha }} | |
| fi | |
| # 確保 Redis 服務啟動並加入網路 | |
| if docker service inspect redis > /dev/null 2>&1; then | |
| docker service update \ | |
| --image redis:7-alpine \ | |
| redis | |
| else | |
| docker service create \ | |
| --name redis \ | |
| --network app_network \ | |
| redis:7-alpine | |
| fi | |
| # 確保 Tunnel 也加入此網路 (如果您原本有啟動 tunnel) | |
| if docker service inspect school_grades_tunnel > /dev/null 2>&1; then | |
| docker service update --network-add app_network school_grades_tunnel > /dev/null 2>&1 || true | |
| fi | |
| # 等待更新完成並檢查狀態 | |
| docker service ps school_grades_app --no-trunc --format "{{.CurrentState}}" | head -1 |