From 455b1e49b31e0daafa3607e75f5e10b4ddca8be0 Mon Sep 17 00:00:00 2001 From: rohow Date: Mon, 12 Jan 2026 10:15:02 +0800 Subject: [PATCH] feat(build): add build-image script and GitHub Actions workflow for container image build and push --- .github/workflows/build-image.sh | 117 +++++++++++++++++++++++++++++ .github/workflows/build-image.yml | 32 ++++++++ .github/workflows/release.yml | 35 --------- README.md | 6 +- images/node-base/Dockerfile | 11 --- images/node-puppeteer/Dockerfile | 21 ------ images/node-puppeteer/sources.list | 15 ---- 7 files changed, 150 insertions(+), 87 deletions(-) create mode 100644 .github/workflows/build-image.sh create mode 100644 .github/workflows/build-image.yml delete mode 100644 .github/workflows/release.yml delete mode 100644 images/node-base/Dockerfile delete mode 100644 images/node-puppeteer/Dockerfile delete mode 100644 images/node-puppeteer/sources.list diff --git a/.github/workflows/build-image.sh b/.github/workflows/build-image.sh new file mode 100644 index 0000000..d08191a --- /dev/null +++ b/.github/workflows/build-image.sh @@ -0,0 +1,117 @@ +#!/bin/sh +set -e + +# 配置默认值 +REGISTRY="${REGISTRY:-registry.hub.docker.com}" +REPO_PREFIX="${REPO_PREFIX:-devcm}" + +echo "=========================================" +echo "Building Docker Image with Buildah" +echo "=========================================" + +# 验证必需的环境变量 +if [ -z "${GIT_TAG}" ]; then + echo "Error: GIT_TAG is not set!" + exit 1 +fi + +if [ -z "${REGISTRY_USERNAME}" ] || [ -z "${REGISTRY_PASSWORD}" ]; then + echo "Error: Registry credentials not set!" + exit 1 +fi + +# 从 GIT_TAG 解析镜像目录和版本 +IMAGE_DIR=$(echo ${GIT_TAG} | rev | cut -d'-' -f2- | rev) +VERSION=$(echo ${GIT_TAG} | rev | cut -d'-' -f1 | rev) + +# 验证解析结果 +if [ -z "${IMAGE_DIR}" ] || [ -z "${VERSION}" ]; then + echo "Error: Failed to parse GIT_TAG: ${GIT_TAG}" + exit 1 +fi + +# 构建路径 +CONTEXT_PATH="images/${IMAGE_DIR}" +DOCKERFILE_PATH="${CONTEXT_PATH}/Dockerfile" + +echo "" +echo "Build Configuration:" +echo " Tag: ${GIT_TAG}" +echo " Image Dir: ${IMAGE_DIR}" +echo " Version: ${VERSION}" +echo " Context: ${CONTEXT_PATH}" +echo " Dockerfile: ${DOCKERFILE_PATH}" +echo " Registry: ${REGISTRY}" +echo " Repository: ${REGISTRY}/${REPO_PREFIX}/${IMAGE_DIR}" +echo "" + +# 验证 Dockerfile 存在 +if [ ! -f "${DOCKERFILE_PATH}" ]; then + echo "Error: Dockerfile not found at ${DOCKERFILE_PATH}" + exit 1 +fi + +# 登录镜像仓库 +echo "Logging in to registry..." +buildah login --username "${REGISTRY_USERNAME}" --password "${REGISTRY_PASSWORD}" --tls-verify=false "${REGISTRY}" + +# 配置镜像源(如果设置了 IMAGE_MIRROR) +if [ -n "${IMAGE_MIRROR}" ]; then + echo "" + echo "Configuring registry mirror: ${IMAGE_MIRROR}" + mkdir -p /etc/containers + cat > /etc/containers/registries.conf < /etc/timezone -RUN echo "ZONE=Asia/Shanghai" >> /etc/timezone && rm -f /etc/localtime && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime - -RUN apt-get update && apt-get install -y curl git vim - -RUN npm config set registry https://registry.npmmirror.com - -RUN npm i pnpm -g diff --git a/images/node-puppeteer/Dockerfile b/images/node-puppeteer/Dockerfile deleted file mode 100644 index 62c453d..0000000 --- a/images/node-puppeteer/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -# node 爬虫镜像 -FROM node:18.16.1-slim - -RUN echo "Asia/Shanghai" > /etc/timezone -RUN echo "ZONE=Asia/Shanghai" >> /etc/timezone && rm -f /etc/localtime && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime - -# 更新apt源 -COPY sources.list /etc/apt/sources.list - -RUN apt-get update - -# 补全chrome依赖 -RUN apt install ca-certificates fonts-liberation libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils -y - -RUN apt install curl -y - -# 更新npm源 -RUN npm config set registry https://registry.npmmirror.com - -# 安装pnpm -RUN npm i pnpm -g \ No newline at end of file diff --git a/images/node-puppeteer/sources.list b/images/node-puppeteer/sources.list deleted file mode 100644 index 592eeef..0000000 --- a/images/node-puppeteer/sources.list +++ /dev/null @@ -1,15 +0,0 @@ -# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 -deb https://mirrors.aliyun.com/debian/ bookworm main contrib non-free non-free-firmware -# deb-src https://mirrors.aliyun.com/debian/ bookworm main contrib non-free non-free-firmware - -deb https://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free non-free-firmware -# deb-src https://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free non-free-firmware - -deb https://mirrors.aliyun.com/debian/ bookworm-backports main contrib non-free non-free-firmware -# deb-src https://mirrors.aliyun.com/debian/ bookworm-backports main contrib non-free non-free-firmware - -deb https://mirrors.aliyun.com/debian-security bookworm-security main contrib non-free non-free-firmware -# deb-src https://mirrors.aliyun.com/debian-security bookworm-security main contrib non-free non-free-firmware - -# deb https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware -# # deb-src https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware