1+ name : Build and Publish to CNB
2+
3+ on :
4+ push :
5+ branches : [ master ]
6+ paths : [ tools/BUILD_CONTAINER_VERSION ] # 必须包含对版本的修改
7+ workflow_dispatch : # 允许手动触发
8+
9+ env :
10+ # 设置镜像名和构建产物的名称
11+ IMAGE_NAME : docker.cnb.cool/alinche/linux-minimal
12+ ARTIFACT_NAME : myminilinux-build-artifacts
13+
14+ jobs :
15+ build :
16+ name : Build Linux Minimal
17+ runs-on : ubuntu-latest
18+ steps :
19+ - name : Checkout code
20+ uses : actions/checkout@v4
21+
22+ - name : Install Dependencies
23+ run : |
24+ sudo apt-get update
25+ sudo apt-get install -y build-essential g++ qemu-utils parted dosfstools e2fsprogs udev kpartx grub2-common
26+
27+ - name : Build Project
28+ run : |
29+ echo "开始构建..."
30+ make build
31+ make make_diskimage
32+
33+ mkdir -p build bin/vmlinuz
34+ tar -czf "${{ env.ARTIFACT_NAME }}.tar.gz" build bin/vmlinuz/vmlinuz-x86_64
35+ ls -lh "${{ env.ARTIFACT_NAME }}.tar.gz"
36+
37+ - name : Upload Build Artifacts
38+ uses : actions/upload-artifact@v4
39+ with :
40+ name : ${{ env.ARTIFACT_NAME }}
41+ path : " ${{ env.ARTIFACT_NAME }}.tar.gz"
42+ retention-days : 1
43+
44+ publish :
45+ name : Publish Docker Image
46+ needs : build # 必须等待 build 任务成功
47+ runs-on : ubuntu-latest
48+ steps :
49+ - name : Checkout code
50+ uses : actions/checkout@v4
51+ # 这里 checkout 主要是为了获取 Dockerfile
52+
53+ - name : Download Build Artifacts
54+ uses : actions/download-artifact@v4
55+ with :
56+ name : ${{ env.ARTIFACT_NAME }}
57+ # 下载到当前目录,这样 Docker build 就能找到了
58+ path : .
59+ - name : Debug - List Files
60+ run : |
61+ echo "当前目录是: $(pwd)"
62+ ls -lhR
63+
64+ - name : Fetch versions in the repo
65+ id : fetch_versions
66+ run : |
67+ BUILD_CONTAINER_VERSION=$(cat tools/BUILD_CONTAINER_VERSION)
68+ echo "build_container_version=$BUILD_CONTAINER_VERSION" >> "$GITHUB_OUTPUT"
69+
70+ - name : Set up Docker Buildx
71+ uses : docker/setup-buildx-action@v2
72+
73+ - name : Login to CNB Registry
74+ uses : docker/login-action@v2
75+ with :
76+ registry : docker.cnb.cool
77+ username : cnb
78+ password : ${{ secrets.CNB_TOKEN }}
79+
80+ # - name: Generate Tag
81+ # id: meta
82+ # run: |
83+ # # 生成类似 :20251218-66ccff 的标签
84+ # SHA_SHORT=$(git rev-parse --short HEAD)
85+ # DATE_TAG=$(date +%Y%m%d)
86+ # echo "tag=${DATE_TAG}-${SHA_SHORT}" >> $GITHUB_OUTPUT
87+
88+ - name : Build and Push Docker Image
89+ uses : docker/build-push-action@v4
90+ with :
91+ context : .
92+ file : tools/Dockerfile
93+ platforms : linux/amd64
94+ push : ${{ github.repository == 'oeasy1412/Linux-minimal' }}
95+ build-args : |
96+ TAR_FILE=${{ env.ARTIFACT_NAME }}.tar.gz
97+ tags : |
98+ ${{ env.IMAGE_NAME }}:latest
99+ ${{ env.IMAGE_NAME }}:${{ steps.fetch_versions.outputs.build_container_version }}
0 commit comments