mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-02-03 03:21:54 +08:00
feat: 完善 Docker 镜像构建工作流和配置优化
- 重构 GitHub Actions 工作流,支持分阶段构建和多平台部署 - 优化 Dockerfile 依赖库配置,增加必要的系统包 - 完善初始化脚本和 KVMD 配置项 - 修复构建过程中的依赖和库文件处理
This commit is contained in:
244
.github/workflows/docker-build.yaml
vendored
244
.github/workflows/docker-build.yaml
vendored
@@ -3,81 +3,197 @@ name: Build and Push Docker Image
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: 'Version'
|
||||
build_type:
|
||||
description: 'Build type'
|
||||
required: true
|
||||
type: choice
|
||||
options:
|
||||
- stage-0
|
||||
- dev
|
||||
- latest
|
||||
- release
|
||||
version:
|
||||
description: 'Version tag (for main image)'
|
||||
required: false
|
||||
default: 'latest'
|
||||
type: string
|
||||
platforms:
|
||||
description: 'Target platforms'
|
||||
required: false
|
||||
default: 'linux/amd64,linux/arm64,linux/arm/v7'
|
||||
type: string
|
||||
enable_aliyun:
|
||||
description: 'Push to Aliyun Registry'
|
||||
required: false
|
||||
default: true
|
||||
type: boolean
|
||||
|
||||
env:
|
||||
DOCKERHUB_REGISTRY: docker.io
|
||||
ALIYUN_REGISTRY: registry.cn-hangzhou.aliyuncs.com
|
||||
STAGE0_IMAGE: kvmd-stage-0
|
||||
MAIN_IMAGE: kvmd
|
||||
|
||||
jobs:
|
||||
build:
|
||||
build-stage-0:
|
||||
runs-on: ubuntu-22.04
|
||||
container:
|
||||
image: node:18
|
||||
env:
|
||||
TZ: Asia/Shanghai
|
||||
if: github.event.inputs.build_type == 'stage-0'
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install dependencies
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
driver: docker-container
|
||||
platforms: ${{ github.event.inputs.platforms }}
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
with:
|
||||
platforms: all
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.DOCKERHUB_REGISTRY }}
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Login to Aliyun Registry
|
||||
if: github.event.inputs.enable_aliyun == 'true'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.ALIYUN_REGISTRY }}
|
||||
username: ${{ secrets.ALIYUN_USERNAME }}
|
||||
password: ${{ secrets.ALIYUN_PASSWORD }}
|
||||
|
||||
- name: Extract metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: |
|
||||
silentwind0/${{ env.STAGE0_IMAGE }}
|
||||
${{ github.event.inputs.enable_aliyun == 'true' && format('{0}/silentwind/{1}', env.ALIYUN_REGISTRY, env.STAGE0_IMAGE) || '' }}
|
||||
tags: |
|
||||
type=raw,value=latest
|
||||
type=raw,value=latest-{{date 'YYYYMMDD-HHmmss'}}
|
||||
type=sha,prefix={{branch}}-
|
||||
labels: |
|
||||
org.opencontainers.image.title=One-KVM Stage-0 Base Image
|
||||
org.opencontainers.image.description=Base image for One-KVM build environment
|
||||
org.opencontainers.image.vendor=One-KVM Project
|
||||
|
||||
- name: Build and push stage-0 image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: ./build/Dockerfile-stage-0
|
||||
platforms: ${{ github.event.inputs.platforms }}
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=gha,scope=stage-0
|
||||
cache-to: type=gha,mode=max,scope=stage-0
|
||||
provenance: false
|
||||
sbom: false
|
||||
allow: security.insecure
|
||||
|
||||
build-main:
|
||||
runs-on: ubuntu-22.04
|
||||
if: github.event.inputs.build_type != 'stage-0'
|
||||
permissions:
|
||||
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: docker-container
|
||||
platforms: ${{ github.event.inputs.platforms }}
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
with:
|
||||
platforms: all
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.DOCKERHUB_REGISTRY }}
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Login to Aliyun Registry
|
||||
if: github.event.inputs.enable_aliyun == 'true'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.ALIYUN_REGISTRY }}
|
||||
username: ${{ secrets.ALIYUN_USERNAME }}
|
||||
password: ${{ secrets.ALIYUN_PASSWORD }}
|
||||
|
||||
- name: Set version tag
|
||||
id: version
|
||||
run: |
|
||||
apt-get update
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
apt-get install -y --no-install-recommends \
|
||||
sudo tzdata docker.io qemu-utils qemu-user-static binfmt-support parted e2fsprogs \
|
||||
curl tar python3 python3-pip rsync git android-sdk-libsparse-utils coreutils zerofree
|
||||
apt-get clean
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime
|
||||
echo $TZ > /etc/timezone
|
||||
update-binfmts --enable
|
||||
env:
|
||||
DEBIAN_FRONTEND: noninteractive
|
||||
if [[ "${{ github.event.inputs.build_type }}" == "dev" ]]; then
|
||||
echo "tag=dev" >> $GITHUB_OUTPUT
|
||||
echo "cachebust=$(date +%s)" >> $GITHUB_OUTPUT
|
||||
elif [[ "${{ github.event.inputs.build_type }}" == "release" ]]; then
|
||||
echo "tag=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
|
||||
echo "cachebust=$(date +%s)" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Install Docker Buildx
|
||||
- name: Extract metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: |
|
||||
silentwind0/${{ env.MAIN_IMAGE }}
|
||||
${{ github.event.inputs.enable_aliyun == 'true' && format('{0}/silentwind/{1}', env.ALIYUN_REGISTRY, env.MAIN_IMAGE) || '' }}
|
||||
tags: |
|
||||
type=raw,value=${{ steps.version.outputs.tag }}
|
||||
type=raw,value=${{ steps.version.outputs.tag }}-{{date 'YYYYMMDD-HHmmss'}}
|
||||
type=sha,prefix={{branch}}-
|
||||
labels: |
|
||||
org.opencontainers.image.title=One-KVM
|
||||
org.opencontainers.image.description=DIY IP-KVM solution based on PiKVM
|
||||
org.opencontainers.image.vendor=One-KVM Project
|
||||
org.opencontainers.image.version=${{ steps.version.outputs.tag }}
|
||||
|
||||
- name: Build and push main image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: ./build/Dockerfile
|
||||
platforms: ${{ github.event.inputs.platforms }}
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=gha,scope=main
|
||||
cache-to: type=gha,mode=max,scope=main
|
||||
provenance: false
|
||||
sbom: false
|
||||
build-args: |
|
||||
CACHEBUST=${{ steps.version.outputs.cachebust }}
|
||||
|
||||
- name: Build summary
|
||||
run: |
|
||||
# 创建插件目录
|
||||
mkdir -p ~/.docker/cli-plugins
|
||||
# 下载 buildx 二进制文件
|
||||
BUILDX_VERSION="v0.11.2"
|
||||
curl -L "https://github.com/docker/buildx/releases/download/${BUILDX_VERSION}/buildx-${BUILDX_VERSION}.linux-amd64" -o ~/.docker/cli-plugins/docker-buildx
|
||||
chmod +x ~/.docker/cli-plugins/docker-buildx
|
||||
# 验证安装
|
||||
docker buildx version
|
||||
|
||||
#- name: Install QEMU
|
||||
# run: |
|
||||
# 安装 QEMU 模拟器
|
||||
#docker run --privileged --rm tonistiigi/binfmt --install all
|
||||
# 验证 QEMU 安装
|
||||
#docker buildx inspect --bootstrap
|
||||
|
||||
- name: Create and use new builder instance
|
||||
run: |
|
||||
# 创建新的 builder 实例
|
||||
docker buildx create --name mybuilder --driver docker-container --bootstrap
|
||||
# 使用新创建的 builder
|
||||
docker buildx use mybuilder
|
||||
# 验证支持的平台
|
||||
docker buildx inspect --bootstrap
|
||||
|
||||
- name: Build multi-arch image
|
||||
run: |
|
||||
# 构建多架构镜像
|
||||
docker buildx build \
|
||||
--platform linux/amd64,linux/arm64,linux/arm/v7 \
|
||||
--file ./build/Dockerfile \
|
||||
--tag silentwind/kvmd:${{ github.event.inputs.version }} \
|
||||
.
|
||||
|
||||
#- name: Login to DockerHub
|
||||
# uses: docker/login-action@v2
|
||||
# with:
|
||||
# username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
# password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
|
||||
echo "## Build Summary" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- **Build Type**: ${{ github.event.inputs.build_type }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- **Version Tag**: ${{ steps.version.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- **Platforms**: ${{ github.event.inputs.platforms }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- **Aliyun Enabled**: ${{ github.event.inputs.enable_aliyun }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- **Cache Bust**: ${{ steps.version.outputs.cachebust }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- **Tags**:" >> $GITHUB_STEP_SUMMARY
|
||||
echo "${{ steps.meta.outputs.tags }}" | sed 's/^/ - /' >> $GITHUB_STEP_SUMMARY
|
||||
Reference in New Issue
Block a user