name: Docker Image CI on: workflow_dispatch: push: branches: - main jobs: build: runs-on: ubuntu-latest # 声明 DinD 服务 services: docker: image: docker:dind options: --privileged ports: - 2375:2375 container: image: catthehacker/ubuntu:act-latest env: # 【修改点 1】在 K8s Pod 中,sidecar 容器即 localhost DOCKER_HOST: tcp://localhost:2375 steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 with: # 【修改点 2】显式指定 endpoint 为 localhost driver-opts: image=moby/buildkit:master endpoint: tcp://localhost:2375 - name: Log in to Gitea Container Registry uses: docker/login-action@v3 with: registry: ${{ gitea.server_url }} username: ${{ gitea.actor }} password: ${{ secrets.GITEA_TOKEN }} - name: Build and push Docker image uses: docker/build-push-action@v5 with: context: . file: Dockerfile push: true tags: | ${{ gitea.server_url }}/${{ gitea.actor }}/my-docs:latest ${{ gitea.server_url }}/${{ gitea.actor }}/my-docs:${{ gitea.sha }}