refactor: 优化 gRPC 服务器启动逻辑 #259
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: Development Environment | |
| on: | |
| push: | |
| branches: | |
| - dev | |
| workflow_dispatch: | |
| jobs: | |
| build-binaries: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| #- name: Create dummy index.html | |
| # run: | | |
| # mkdir -p public/dist | |
| # echo "<html><body><h1>This is komari development server.</h1></body></html>" > public/dist/index.html | |
| - name: Clone and build frontend | |
| run: | | |
| git clone https://github.com/komari-monitor/komari-web web | |
| cd web | |
| npm install | |
| npm run build | |
| cd .. | |
| mkdir -p public/dist | |
| cp -r web/dist/* public/dist/ | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: "1.23" | |
| - name: Build application | |
| env: | |
| GOOS: linux | |
| GOARCH: amd64 | |
| run: | | |
| VERSION_SHA="${{ github.sha }}" | |
| go build -ldflags "-X github.com/komari-monitor/komari/internal/version.CurrentVersion=dev -X github.com/komari-monitor/komari/internal/version.VersionHash=${VERSION_SHA}" -o komari . | |
| - name: Upload binary as artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: komari | |
| path: komari | |
| deploy-to-production: | |
| needs: build-binaries | |
| runs-on: ubuntu-latest | |
| env: | |
| PRODUCTION_SERVER: ${{ vars.PRODUCTION_SERVER }} | |
| if: github.ref == 'refs/heads/dev' | |
| steps: | |
| - name: Download binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: komari | |
| - name: Setup SSH Key | |
| uses: webfactory/[email protected] | |
| with: | |
| ssh-private-key: ${{ secrets.PRODUCTION_SSH_KEY }} | |
| - name: Add host to known hosts | |
| run: | | |
| mkdir -p ~/.ssh | |
| ssh-keyscan -H ${{ env.PRODUCTION_SERVER }} >> ~/.ssh/known_hosts 2>/dev/null | |
| - name: Deploy to production | |
| run: | | |
| chmod +x komari | |
| ssh root@${{ env.PRODUCTION_SERVER }} 'mkdir -p /opt/komari/' | |
| ssh root@${{ env.PRODUCTION_SERVER }} 'systemctl stop komari.service || true' | |
| ssh root@${{ env.PRODUCTION_SERVER }} 'rm -f /opt/komari/komari.old' | |
| ssh root@${{ env.PRODUCTION_SERVER }} 'mv /opt/komari/komari /opt/komari/komari.old || true' | |
| scp komari root@${{ env.PRODUCTION_SERVER }}:/opt/komari/komari | |
| ssh root@${{ env.PRODUCTION_SERVER }} 'systemctl start komari.service' |