更新 .github/workflows/build.yml
Some checks failed
Build and Push Docker Image / build (push) Failing after 41s
Build and Push Docker Image / build-multiarch (amd64, linux/amd64) (push) Has been skipped
Build and Push Docker Image / build-multiarch (arm64, linux/arm64) (push) Has been skipped

Signed-off-by: ChenKaiLiuG <ckliu119@gmail.com>
This commit is contained in:
2026-01-04 12:42:32 +00:00
parent 2f69a8d568
commit acf63ca974

View File

@@ -1,21 +1,17 @@
name: Build and Push EdgeNode Docker Image name: Build and Push Docker Image
on: on:
push: push:
branches:
- master
- main
tags: tags:
- 'v*' - 'v*'
branches:
- master
- main
pull_request:
branches:
- master
- main
workflow_dispatch: workflow_dispatch:
inputs: inputs:
build_type: build_type:
description: 'Build type (community or plus)' description: 'Build type (community or plus)'
required: true required: false
default: 'community' default: 'community'
type: choice type: choice
options: options:
@@ -23,25 +19,112 @@ on:
- plus - plus
env: env:
REGISTRY_GHCR: ghcr.io REGISTRY_HOST: 172.24.0.10:3000
IMAGE_NAME_GHCR: ${{ github.repository }} EXTERNAL_REGISTRY: 192.168.10.100:3000
REGISTRY_DOCKER: docker.io DOCKER_BUILDKIT: 1
IMAGE_NAME_DOCKER: ${{ secrets.DOCKER_HUB_USERNAME }}/edge-node
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
contents: read contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-options: |
image=moby/buildkit:latest
network=host
- name: Extract version and metadata
id: meta
run: |
# 取得 git tag 或 branch 名稱
if [[ ${{ github.ref }} == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
else
VERSION=${{ github.ref_name }}-$(git rev-parse --short HEAD)
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
# 轉換為小寫的 image name
IMAGE_NAME=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
echo "image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
# 判斷編譯類型
BUILD_TYPE=${{ inputs.build_type || 'community' }}
echo "build_type=${BUILD_TYPE}" >> $GITHUB_OUTPUT
echo "=== 構建信息 ==="
echo "版本: ${VERSION}"
echo "映像: ${IMAGE_NAME}"
echo "構建類型: ${BUILD_TYPE}"
- name: Debug Network Connectivity
run: |
echo "測試內部 Registry 連接..."
ping -c 3 172.24.0.10 || true
timeout 5 bash -c 'cat < /dev/null > /dev/tcp/172.24.0.10/3000' && echo "✓ Registry 可達" || echo "✗ Registry 不可達"
- name: Login to Gitea Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_HOST }}
username: ${{ github.repository_owner }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build and push (single architecture)
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{ env.REGISTRY_HOST }}/${{ steps.meta.outputs.image_name }}:${{ steps.meta.outputs.version }}
${{ env.REGISTRY_HOST }}/${{ steps.meta.outputs.image_name }}:latest
build-args: |
VERSION=${{ steps.meta.outputs.version }}
BUILD_TYPE=${{ steps.meta.outputs.build_type }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Display push results
run: |
echo ""
echo "✓ 編譯完成!"
echo ""
echo "=== 內部訪問 (Docker 容器內) ==="
echo " docker pull ${{ env.REGISTRY_HOST }}/${{ steps.meta.outputs.image_name }}:${{ steps.meta.outputs.version }}"
echo " docker pull ${{ env.REGISTRY_HOST }}/${{ steps.meta.outputs.image_name }}:latest"
echo ""
echo "=== 外部訪問 (Portainer/本地機器) ==="
echo " docker pull ${{ env.EXTERNAL_REGISTRY }}/${{ steps.meta.outputs.image_name }}:${{ steps.meta.outputs.version }}"
echo " docker pull ${{ env.EXTERNAL_REGISTRY }}/${{ steps.meta.outputs.image_name }}:latest"
echo ""
echo "映像名稱: ${{ steps.meta.outputs.image_name }}"
echo "版本標籤: ${{ steps.meta.outputs.version }}"
echo "構建類型: ${{ steps.meta.outputs.build_type }}"
# 可選:如果您想支持多架構編譯(需要有合適的 runner
build-multiarch:
runs-on: ubuntu-latest
if: contains(github.ref, 'tags/v') # 只在發佈版本時執行
permissions:
contents: read
strategy: strategy:
matrix: matrix:
include: include:
- platform: linux/amd64 - arch: amd64
arch: amd64 platform: linux/amd64
- platform: linux/arm64 - arch: arm64
arch: arm64 platform: linux/arm64
steps: steps:
- name: Checkout code - name: Checkout code
@@ -49,97 +132,38 @@ jobs:
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with: with:
registry: ${{ env.REGISTRY_GHCR }} driver-options: image=moby/buildkit:latest,network=host
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Docker Hub - name: Extract version and metadata
if: github.event_name != 'pull_request' && secrets.DOCKER_HUB_USERNAME != ''
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Extract metadata
id: meta id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME_GHCR }}
${{ env.REGISTRY_DOCKER }}/${{ env.IMAGE_NAME_DOCKER }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Determine build type
id: build_type
run: | run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then VERSION=${GITHUB_REF#refs/tags/}
echo "build_type=${{ inputs.build_type }}" >> $GITHUB_OUTPUT IMAGE_NAME=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
else echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "build_type=community" >> $GITHUB_OUTPUT echo "image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
fi
- name: Build and push GHCR - name: Login to Gitea Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_HOST }}
username: ${{ github.repository_owner }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build for ${{ matrix.arch }}
uses: docker/build-push-action@v5 uses: docker/build-push-action@v5
with: with:
context: . context: .
file: ./Dockerfile file: ./Dockerfile
platforms: ${{ matrix.platform }} platforms: ${{ matrix.platform }}
push: ${{ github.event_name != 'pull_request' }} push: true
tags: ${{ steps.meta.outputs.tags }} tags: |
labels: ${{ steps.meta.outputs.labels }} ${{ env.REGISTRY_HOST }}/${{ steps.meta.outputs.image_name }}:${{ steps.meta.outputs.version }}-${{ matrix.arch }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: | build-args: |
VERSION=${{ github.ref_name }} VERSION=${{ steps.meta.outputs.version }}
BUILD_TYPE=${{ steps.build_type.outputs.build_type }}
TARGETARCH=${{ matrix.arch }} TARGETARCH=${{ matrix.arch }}
publish-manifest: - name: Save architecture info
runs-on: ubuntu-latest
needs: build
if: github.event_name != 'pull_request'
permissions:
contents: read
packages: write
steps:
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_GHCR }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create manifest for GHCR
run: | run: |
docker manifest create \ echo "✓ 編譯完成: ${{ matrix.arch }}"
${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME_GHCR }}:${{ github.ref_name }} \ echo "映像: ${{ env.REGISTRY_HOST }}/${{ steps.meta.outputs.image_name }}:${{ steps.meta.outputs.version }}-${{ matrix.arch }}"
--amend ${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME_GHCR }}:${{ github.ref_name }}-amd64 \
--amend ${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME_GHCR }}:${{ github.ref_name }}-arm64
docker manifest push ${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME_GHCR }}:${{ github.ref_name }}
- name: Log in to Docker Hub
if: secrets.DOCKER_HUB_USERNAME != ''
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Create manifest for Docker Hub
if: secrets.DOCKER_HUB_USERNAME != ''
run: |
docker manifest create \
${{ env.REGISTRY_DOCKER }}/${{ env.IMAGE_NAME_DOCKER }}:${{ github.ref_name }} \
--amend ${{ env.REGISTRY_DOCKER }}/${{ env.IMAGE_NAME_DOCKER }}:${{ github.ref_name }}-amd64 \
--amend ${{ env.REGISTRY_DOCKER }}/${{ env.IMAGE_NAME_DOCKER }}:${{ github.ref_name }}-arm64
docker manifest push ${{ env.REGISTRY_DOCKER }}/${{ env.IMAGE_NAME_DOCKER }}:${{ github.ref_name }}