name: Build and Push Docker Image on: push: branches: - master - main tags: - 'v*' jobs: build: runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Checkout code run: | git clone --depth=1 "https://${{ gitea.actor }}:${{ secrets.GITHUB_TOKEN }}@git.openlocalpdf.com/${{ gitea.repository }}.git" . git checkout "${{ github.sha }}" || true - name: Check Runner Environment run: | echo "=== System Info ===" uname -a || true which docker || echo "docker CLI not found!" docker version || echo "docker daemon not accessible!" - name: Log in to Gitea Container Registry run: | echo "${{ secrets.REGISTRY_TOKEN }}" | docker login git.openlocalpdf.com -u "${{ gitea.actor }}" --password-stdin - name: Build and Push Docker image run: | IMAGE_NAME="git.openlocalpdf.com/${{ gitea.repository }}" echo "Building image: ${IMAGE_NAME}:latest" docker build -t "${IMAGE_NAME}:latest" -f Dockerfile . docker push "${IMAGE_NAME}:latest" # 如果是 tag 触发,则同步打 tag 推送 if [ "${{ github.ref_type }}" = "tag" ]; then TAG_NAME="${{ github.ref_name }}" echo "Tag detected: ${TAG_NAME}" docker tag "${IMAGE_NAME}:latest" "${IMAGE_NAME}:${TAG_NAME}" docker push "${IMAGE_NAME}:${TAG_NAME}" fi