name: Build and Deploy on: push: branches: - main env: REGISTRY: gitea.fse-media.group IMAGE_NAME: henry_du/bywcloudreve SERVER_HOST: 192.140.163.199 SERVER_USER: ubuntu COMPOSE_PATH: /home/ubuntu/cloudreve jobs: build-and-deploy: runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Checkout repository uses: actions/checkout@v4 - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to Gitea Container Registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ gitea.actor }} password: ${{ secrets.GITEA_TOKEN }} - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=ref,event=branch type=sha,format=long,prefix= type=raw,value=latest,enable={{is_default_branch}} - name: Build and push Docker image uses: docker/build-push-action@v6 with: context: . file: ./Dockerfile.ci push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} platforms: linux/amd64 cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest cache-to: type=inline build-args: | BUILD_DATE=${{ gitea.sha }} - name: Deploy to server via SSH uses: appleboy/ssh-action@v1.2.0 with: host: ${{ env.SERVER_HOST }} username: ${{ env.SERVER_USER }} key: ${{ secrets.SSH_PRIVATE_KEY }} port: 22 script: | set -e cd ${{ env.COMPOSE_PATH }} echo "${{ secrets.GITEA_TOKEN }}" | docker login ${{ env.REGISTRY }} -u "${{ gitea.actor }}" --password-stdin echo "Pulling latest image..." docker compose pull cloudreve echo "Recreating cloudreve container (preserving volumes)..." docker compose up -d --remove-orphans cloudreve echo "Cleaning up old images..." docker image prune -f echo "Deployment completed at $(date)"