fix: use valid Python base image in Docker workflow #5
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: Docker Build & Deploy | |
| on: | |
| push: | |
| branches: | |
| - master | |
| tags: | |
| - v* | |
| env: | |
| IMAGE_NAME: nonebot-webui | |
| jobs: | |
| build: | |
| name: Build & Push Docker Image | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| outputs: | |
| version: ${{ steps.meta.outputs.version }} | |
| image_tag: ${{ steps.image_tag.outputs.TAG }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Setup Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Generate image tag | |
| id: image_tag | |
| run: | | |
| if [[ "$GITHUB_REF" == refs/tags/v* ]]; then | |
| TAG="${GITHUB_REF#refs/tags/v}" | |
| else | |
| TAG="${GITHUB_SHA::7}" | |
| fi | |
| echo "TAG=$TAG" >> $GITHUB_OUTPUT | |
| - name: Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: | | |
| ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=ref,event=branch | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=sha,prefix= | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| - name: Build and Push | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| platforms: linux/amd64 | |
| push: true | |
| build-args: | | |
| SOURCE_COMMIT=${{ steps.image_tag.outputs.TAG }} | |
| PYTHON_IMAGE=3.11-slim | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| deploy: | |
| name: Deploy to Test Server | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') | |
| steps: | |
| - name: Check deploy configuration | |
| id: deploy_config | |
| env: | |
| TEST_SERVER_HOST: ${{ secrets.TEST_SERVER_HOST }} | |
| TEST_SERVER_USER: ${{ secrets.TEST_SERVER_USER }} | |
| TEST_SERVER_PASSWORD: ${{ secrets.TEST_SERVER_PASSWORD }} | |
| run: | | |
| if [[ -n "$TEST_SERVER_HOST" && -n "$TEST_SERVER_USER" && -n "$TEST_SERVER_PASSWORD" ]]; then | |
| echo "enabled=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "enabled=false" >> "$GITHUB_OUTPUT" | |
| echo "Test server secrets are not configured; skipping deployment." | |
| fi | |
| - name: Deploy via SSH | |
| if: steps.deploy_config.outputs.enabled == 'true' | |
| uses: appleboy/ssh-action@v1 | |
| with: | |
| host: ${{ secrets.TEST_SERVER_HOST }} | |
| username: ${{ secrets.TEST_SERVER_USER }} | |
| password: ${{ secrets.TEST_SERVER_PASSWORD }} | |
| script: | | |
| set -e | |
| IMAGE="ghcr.io/${{ github.repository_owner }}/nonebot-webui:${{ needs.build.outputs.image_tag }}" | |
| # Pull the image built in this workflow run | |
| docker pull "$IMAGE" | |
| # Stop and remove old container | |
| docker rm -f nonebot-webui 2>/dev/null || true | |
| # Start new container | |
| docker run -d \ | |
| --name nonebot-webui \ | |
| --restart=always \ | |
| --network host \ | |
| -e HOST=0.0.0.0 \ | |
| -e PORT=18080 \ | |
| -v /home/xisoul/nonebot-webui-data/projects:/projects \ | |
| -v /home/xisoul/nonebot-webui-external-projects:/external-projects \ | |
| -v /home/xisoul/nonebot-webui-data/config.json:/app/config.json \ | |
| -v /home/xisoul/nonebot-webui-data/project.json:/app/project.json \ | |
| "$IMAGE" | |
| # Wait for healthy | |
| echo "Waiting for container to be healthy..." | |
| for i in $(seq 1 30); do | |
| STATUS=$(docker inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' nonebot-webui 2>/dev/null || echo "unknown") | |
| echo " [$i/30] status: $STATUS" | |
| if [ "$STATUS" = "healthy" ]; then | |
| echo "Container is healthy!" | |
| exit 0 | |
| fi | |
| sleep 2 | |
| done | |
| echo "Warning: Container did not become healthy within 60s" | |
| docker logs --tail 20 nonebot-webui | |
| exit 1 |