name: Build and Push Docs run-name: Build Docs - ${{ gitea.actor }} on: push: branches: - main tags: - 'v*' workflow_dispatch: jobs: build-push: runs-on: ubuntu-latest steps: # 1. 检出代码 # 注意:必须包含 nginx/nginx.conf 和 Dockerfile - name: Checkout uses: actions/checkout@v3 # 2. 登录镜像仓库 - name: Login to Registry uses: docker/login-action@v2 with: registry: ${{ secrets.DOCKER_REGISTRY }} username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} # 3. 启用 Buildx # 这是必须的,因为 docker/build-push-action 依赖它 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 # 4. 生成 Metadata (自动生成 latest, v1.0.0 等标签) - name: Docker Metadata id: meta uses: docker/metadata-action@v4 with: images: ${{ secrets.DOCKER_REGISTRY }}/your-image-name tags: | type=ref,event=branch type=semver,pattern={{version}} type=sha,format=short # 5. 构建并推送 - name: Build and Push uses: docker/build-push-action@v4 with: context: . file: ./Dockerfile push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} # 开启缓存,加速下一次构建(会缓存各层 Layer) cache-from: type=gha cache-to: type=gha,mode=max