commit faaa1175948b3e933b04da5c9796b220a8417a1d Author: Wang Defa <2-wangdefa@users.noreply.gitlab.bcde.io> Date: Wed Dec 3 11:32:26 2025 +0800 首次提交 diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml new file mode 100644 index 0000000..6c470a7 --- /dev/null +++ b/.gitea/workflows/ci.yaml @@ -0,0 +1,82 @@ +# .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}" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7cf3a93 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM alpine:latest + +RUN apk add --no-cache tftp-hpa curl + +RUN mkdir -p /var/lib/tftpboot + +VOLUME /var/lib/tftpboot + +EXPOSE 69/udp + +COPY entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod +x /usr/local/bin/entrypoint.sh + +WORKDIR /var/lib/tftpboot + +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..25133c9 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +TFTPBOOT_DIR="/var/lib/tftpboot" + +if [ "$DOWNLOAD_NETBOOT_XYZ" = "true" ]; then + echo "DOWNLOAD_NETBOOT_XYZ is true. Downloading netboot.xyz files..." + + mkdir -p "$TFTPBOOT_DIR" + + curl -o "$TFTPBOOT_DIR/netboot.xyz-arm64.efi" https://boot.netboot.xyz/ipxe/netboot.xyz-arm64.efi + if [ $? -ne 0 ]; then + echo "Error downloading netboot.xyz-arm64.efi" + fi + + curl -o "$TFTPBOOT_DIR/netboot.xyz.efi" https://boot.netboot.xyz/ipxe/netboot.xyz.efi + if [ $? -ne 0 ]; then + echo "Error downloading netboot.xyz.efi" + fi + + echo "Download complete." +else + echo "DOWNLOAD_NETBOOT_XYZ is not true or not set. Skipping netboot.xyz file download." +fi + +exec /usr/sbin/in.tftpd -L -vvv -u ftp --secure --address "0.0.0.0:69" "$TFTPBOOT_DIR" \ No newline at end of file