From 518c2c79539ee7ee82c5da93675ac50986b993e1 Mon Sep 17 00:00:00 2001 From: engigu Date: Thu, 25 Dec 2025 21:49:50 +0800 Subject: [PATCH] feat: add demo site config --- .github/workflows/deploy.yml | 72 ++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..794eb9a --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,72 @@ +name: Build-Deploy + +on: + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: baihu + +jobs: + build: + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern={{version}}-amd64 + type=raw,value=latest-amd64,enable={{is_default_branch}} + + - name: Get build time + id: build_time + run: echo "time=$(TZ='Asia/Shanghai' date '+%Y-%m-%d %H:%M:%S')" >> $GITHUB_OUTPUT + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + VERSION=${{ github.ref_name }} + BUILD_TIME=${{ steps.build_time.outputs.time }} + cache-from: type=gha,scope=linux-amd64 + cache-to: type=gha,scope=linux-amd64,mode=max + provenance: false + + - name: Deploy to server + uses: appleboy/ssh-action@v1.2.0 + with: + host: ${{ secrets.DEPLOY_HOST }} + username: ${{ secrets.DEPLOY_USER }} + key: ${{ secrets.DEPLOY_KEY }} + port: ${{ secrets.DEPLOY_PORT }} + script: | + cd ${{ secrets.DEPLOY_PATH }} + docker-compose pull + docker-compose up -d + docker image prune -y