ci: 新增 Gitea Actions 构建部署工作流和多阶段构建 Dockerfile
Build and Deploy / build-and-deploy (push) Canceled after 0s

This commit is contained in:
2026-09-13 11:48:10 +08:00
parent 2a7b03ab1d
commit 6fecb708fd
3 changed files with 222 additions and 0 deletions
+84
View File
@@ -0,0 +1,84 @@
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)"