Skip to content

feat(cnb-image): add to cnb-image #3

feat(cnb-image): add to cnb-image

feat(cnb-image): add to cnb-image #3

Workflow file for this run

name: Build and Publish to CNB
on:
push:
branches: [ master ]
workflow_dispatch: # 允许手动触发
env:
# 设置镜像名和构建产物的名称
IMAGE_NAME: docker.cnb.cool/alinche/linux-minimal
ARTIFACT_NAME: myminilinux-build-artifacts
jobs:
build:
name: Build Linux Minimal
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential g++ qemu-utils parted dosfstools e2fsprogs udev kpartx grub2-common
- name: Build Project
run: |
echo "开始构建..."
make build
make make_diskimage
mkdir -p build bin/vmlinuz
tar -czf "${{ env.ARTIFACT_NAME }}.tar.gz" build bin/vmlinuz/vmlinuz-x86_64
ls -lh "${{ env.ARTIFACT_NAME }}.tar.gz"
- name: Upload Build Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: "${{ env.ARTIFACT_NAME }}.tar.gz"
retention-days: 1
publish:
name: Publish Docker Image
needs: build # 必须等待 build 任务成功
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
# 这里 checkout 主要是为了获取 Dockerfile
- name: Download Build Artifacts
uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
# 下载到当前目录,这样 Docker build 就能找到了
path: .
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to CNB Registry
uses: docker/login-action@v2
with:
registry: docker.cnb.cool
username: ${{ secrets.CNB_USERNAME }}
password: ${{ secrets.CNB_TOKEN }}
- name: Generate Tag
id: meta
run: |
# 生成类似 :20251218-66ccff 的标签
SHA_SHORT=$(git rev-parse --short HEAD)
DATE_TAG=$(date +%Y%m%d)
echo "tag=${DATE_TAG}-${SHA_SHORT}" >> $GITHUB_OUTPUT
- name: Build and Push Docker Image
uses: docker/build-push-action@v4
with:
context: .
# 指定你的 Dockerfile 路径
file: Dockerfile
push: true
build-args: |
TAR_FILE=${{ env.ARTIFACT_NAME }}.tar.gz
tags: |
${{ env.IMAGE_NAME }}:latest
${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.tag }}