diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..40dae2c --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,47 @@ +name: 全局K3s部署 +on: + push: + branches: [master] + +jobs: + deploy: + runs-on: ubuntu-latest + env: + K3S_HOST: 121.37.117.181 + APP_NAME: ${{ gitea.repo_name }} + REGISTRY: 你的镜像仓库地址 # 比如 docker.io/你的用户名 + steps: + - uses: gitea/actions/checkout@v4 + + # 1. 初始化 Docker Buildx + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + # 2. 登录镜像仓库(按需) + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PWD }} + + # 3. 构建+推送,启用缓存 + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ env.REGISTRY }}/${{ env.APP_NAME }}:${{ gitea.sha }} + # 缓存配置:推送到镜像仓库 + cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.APP_NAME }}:buildcache + cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.APP_NAME }}:buildcache,mode=max + + # 4. 你原来的 SSH 部署步骤不变 + - name: SSH部署K3s + run: | + mkdir -p ~/.ssh + echo "${{ secrets.K3S_PEM_KEY }}" > k3s.pem + chmod 600 k3s.pem + ssh -i k3s.pem -o StrictHostKeyChecking=no root@${K3S_HOST} << CMD + kubectl apply -f /k8s/deploy.yaml + kubectl rollout restart deployment ${APP_NAME} + CMD \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index ba8ad82..51c1ee2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,7 @@ +FROM gitea/gitea:latest +# 拷贝预设工作流模板到容器内仓库模板目录 +COPY ./workflow_template/.gitea /data/gitea/templates/repo/.gitea + # ==================== 第一阶段:构建前端 ==================== FROM node:18-alpine AS builder