From 3ca6362356b963ea3a8f680f32bbd311c6479067 Mon Sep 17 00:00:00 2001 From: XingHeYuZhuan <93032435+XingHeYuZhuan@users.noreply.github.com> Date: Tue, 26 May 2026 22:39:36 +0800 Subject: [PATCH] =?UTF-8?q?chore:=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E6=89=8B=E5=8A=A8actions=E4=B8=BA=E6=9C=89=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E7=9A=84=E7=94=A8=E6=88=B7=E6=8F=90=E4=BE=9B=E4=BA=91=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-build.yml | 95 ++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 .github/workflows/docker-build.yml diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000000..3ffa059e00 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,95 @@ +name: actions云构建docker镜像 + +on: + workflow_dispatch: + inputs: + image_name: + description: '目标 Docker 镜像名称 (系统会自动将其转换为纯小写格式)' + required: true + default: 'alas' + type: string + + custom_tag: + description: 'Docker 镜像标签 (Tag)' + required: true + default: 'latest' + type: string + + context_path: + description: 'Docker 构建上下文路径 (包含 Dockerfile 的目录)' + required: true + default: './deploy/docker' + type: string + + dockerfile_path: + description: 'Dockerfile 文件的具体路径 (相对于构建上下文路径)' + required: true + default: 'Dockerfile' + type: string + + output_type: + description: '发布与导出方式 (ghcr: 推送到 GitHub 容器注册表, local-tar: 导出为离线产物包)' + required: true + default: 'ghcr' + type: choice + options: + - ghcr + - local-tar + +jobs: + build-process: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Initialize Environment Variables + id: prep + run: | + IMAGE_NAME=$(echo "${{ github.event.inputs.image_name }}" | tr '[:upper:]' '[:lower:]') + OWNER_LOWER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]') + echo "ghcr_tag=ghcr.io/${OWNER_LOWER}/${IMAGE_NAME}:${{ github.event.inputs.custom_tag }}" >> $GITHUB_ENV + echo "tar_name=${IMAGE_NAME}-${{ github.event.inputs.custom_tag }}.tar" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GitHub Container Registry + if: ${{ github.event.inputs.output_type == 'ghcr' }} + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and Push to GHCR + if: ${{ github.event.inputs.output_type == 'ghcr' }} + uses: docker/build-push-action@v6 + with: + context: ${{ github.event.inputs.context_path }} + file: ${{ github.event.inputs.context_path }}/${{ github.event.inputs.dockerfile_path }} + platforms: linux/amd64 + push: true + tags: ${{ env.ghcr_tag }} + + - name: Build and Export OCI Tarball + if: ${{ github.event.inputs.output_type == 'local-tar' }} + uses: docker/build-push-action@v6 + with: + context: ${{ github.event.inputs.context_path }} + file: ${{ github.event.inputs.context_path }}/${{ github.event.inputs.dockerfile_path }} + platforms: linux/amd64 + outputs: type=docker,dest=/tmp/${{ env.tar_name }},name=${{ env.ghcr_tag }} + push: false + + - name: Upload Tarball Artifact + if: ${{ github.event.inputs.output_type == 'local-tar' }} + uses: actions/upload-artifact@v4 + with: + name: docker-tar-${{ env.tar_name }} + path: /tmp/${{ env.tar_name }} + retention-days: 5 \ No newline at end of file