Files
tftpd/.gitea/workflows/ci.yaml
Wang Defa faaa117594
All checks were successful
Build and Push TFTP Docker Image / docker-build-push (push) Successful in 29s
首次提交
2025-12-03 11:32:26 +08:00

83 lines
2.7 KiB
YAML

# .gitea/workflows/ci.yaml
name: Build and Push TFTP Docker Image
on:
push:
branches: [main, develop]
tags: ['*']
env:
DOCKER_BUILDKIT: "1"
BUILDX_NO_DEFAULT_ATTESTATIONS: "1"
jobs:
docker-build-push:
runs-on: ubuntu-latest-amd64
steps:
- uses: actions/checkout@v4
- name: Debug branch info
run: |
echo "📋 Branch Information:"
echo " github.ref: ${{ github.ref }}"
echo " github.ref_name: ${{ github.ref_name }}"
echo " github.event_name: ${{ github.event_name }}"
- name: Setup Docker Buildx and Login
run: |
# 设置 QEMU 支持多架构
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes 2>/dev/null || true
# 创建 buildx builder
docker buildx create --use --name tftpd_builder \
--driver docker-container \
--driver-opt network=host \
--driver-opt image=moby/buildkit:buildx-stable-1 \
--driver-opt env.BUILDKIT_STEP_LOG_MAX_SIZE=50000000 \
--driver-opt env.BUILDKIT_STEP_LOG_MAX_SPEED=10000000 \
|| docker buildx use tftpd_builder
docker buildx inspect --bootstrap
# 登录 Docker Registry
echo "${{ secrets.BUILD_TOKEN }}" | docker login ${{ gitea.server_url }} -u ${{ gitea.actor }} --password-stdin
- name: Determine Docker tag
id: tag
run: |
if [ "${{ github.ref_name }}" = "main" ]; then
TAG="latest"
elif [ "${{ github.ref_name }}" = "develop" ]; then
TAG="develop"
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
TAG="${{ github.ref_name }}"
else
TAG="${{ github.ref_name }}"
fi
echo "tag=${TAG}" >> $GITHUB_OUTPUT
echo "📦 Docker tag: ${TAG}"
- name: Build and push multi-arch Docker image
run: |
# 移除 URL 中的 https:// 前缀
REGISTRY=$(echo "${{ gitea.server_url }}" | sed 's|https\?://||')
IMAGE_NAME="${REGISTRY}/${{ gitea.repository }}"
TAG="${{ steps.tag.outputs.tag }}"
FINAL_IMAGE_TAG="${IMAGE_NAME}:${TAG}"
echo "🏗️ Building and pushing image: ${FINAL_IMAGE_TAG}"
echo " Platforms: linux/amd64, linux/arm64"
# 设置 BuildKit 优化参数
export BUILDKIT_PROGRESS=plain
docker buildx build --pull --push \
-t "${FINAL_IMAGE_TAG}" \
--platform linux/amd64,linux/arm64 \
--provenance=false \
--sbom=false \
-f Dockerfile .
echo ""
echo "✅ Build and push completed!"
echo "🐳 Image: ${FINAL_IMAGE_TAG}"