From 74687fb25942848af29902f897f548d9f552571d Mon Sep 17 00:00:00 2001 From: Endial Fang Date: Wed, 2 Aug 2023 10:41:42 +0800 Subject: [PATCH 01/12] =?UTF-8?q?feat:=20CI/CD=20=E5=A2=9E=E5=8A=A0=20tag?= =?UTF-8?q?=20=E9=80=89=E6=8B=A9=E7=BC=96=E8=AF=91=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4bb38dd..7ec664e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,13 +23,15 @@ default: if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then IMG_TAG=":latest" else - IMG_TAG=":$CI_COMMIT_REF_SLUG" + IMG_TAG=":$CI_COMMIT_REF_NAME" fi - docker login -u "$HARBOR_USERNAME" -p "$HARBOR_PASSWORD" $HARBOR_URL # 编译阶段任务 build-arm64: stage: build + tags: + - arm64 script: - export - env @@ -37,6 +39,8 @@ build-arm64: build-amd64: stage: build + tags: + - amd64 script: - docker buildx build --platform=linux/amd64 --pull -t "$IMG_URL$IMG_TAG-linux-amd64" . --push From 98545d1e268471c6bbe21e75bf3c08faf8b77792 Mon Sep 17 00:00:00 2001 From: Endial Fang Date: Fri, 4 Aug 2023 15:05:15 +0800 Subject: [PATCH 02/12] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=20Dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index c267539..4c0b6d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ # 该部分变量,在编译命令中通过 `--build-arg` 传入;如果未设置,则使用下面对应的默认值 # 设置当前应用名称及版本 -ARG APP_NAME=dBuilder +ARG APP_NAME=dbuilder ARG APP_VER=12 # 设置默认仓库地址,默认为本地仓库;定义时需要包含末尾的`/` @@ -36,21 +36,14 @@ FROM --platform=${TARGETPLATFORM:-linux/amd64} ${REGISTRY_URL}colovu/debian:${AP # 声明需要使用的全局可变参数 ARG APP_NAME ARG APP_VER -ARG REGISTRY_URL ARG APT_SOURCE -ARG LOCAL_URL -ARG TARGETARCH LABEL \ "Version"="v${APP_VER}" \ "Description"="Docker image for Builder based on Debian." \ - "Github"="https://github.com/colovu/docker-dbuilder" \ + "Github"="https://github.com/colovu/docker-${APP_NAME}" \ "Vendor"="Endial Fang (endial@126.com)" - -# 选择软件包源(Optional),以加速后续软件包安装 -RUN select_source ${APT_SOURCE} - # 以下命令安装的软件包 # apt-transport-https apt-utils binutils binutils-common # binutils-x86-64-linux-gnu build-essential bzip2 ca-certificates cmake @@ -72,9 +65,16 @@ RUN select_source ${APT_SOURCE} # patch perl perl-modules-5.28 pinentry-curses pkg-config procps python3 # python3-minimal python3.7 python3.7-minimal readline-common sudo wget # xz-utils -RUN install_pkg sudo wget curl git ca-certificates iproute2 net-tools nano dpkg gnupg \ +RUN set -eux; \ + \ + # 选择软件包源 + select_source ${APT_SOURCE}; \ + \ + # 安装编译环境及常用开发库 + install_pkg sudo wget git ca-certificates iproute2 net-tools nano dpkg gnupg \ dirmngr apt-utils apt-transport-https lsb-release iputils-ping \ - build-essential cmake libcmocka-dev pkg-config libssl3 libssl-dev \ - libtool libltdl7 libltdl-dev + build-essential cmake libcmocka-dev pkg-config \ + libssl3 libssl-dev \ + libtool libltdl7 libltdl-dev; CMD [] From 41320b75cb94555173d6ed820462af7b0b13263b Mon Sep 17 00:00:00 2001 From: Endial Fang Date: Fri, 4 Aug 2023 15:11:53 +0800 Subject: [PATCH 03/12] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=20CI/CD=20?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E9=98=B6=E6=AE=B5=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7ec664e..70ebbc3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -27,14 +27,18 @@ default: fi - docker login -u "$HARBOR_USERNAME" -p "$HARBOR_PASSWORD" $HARBOR_URL +# 环境变量信息 +env-variables: + stage: .pre + script: + - export + # 编译阶段任务 build-arm64: stage: build tags: - arm64 script: - - export - - env - docker buildx build --platform=linux/arm64 --pull -t "$IMG_URL$IMG_TAG-linux-arm64" . --push build-amd64: From 72da404b29a8b84e31143f84a268f6b91b2194cd Mon Sep 17 00:00:00 2001 From: Endial Fang Date: Fri, 11 Aug 2023 11:09:40 +0800 Subject: [PATCH 04/12] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20CI/CD=20?= =?UTF-8?q?=E6=B8=85=E7=90=86=E4=B8=B4=E6=97=B6=E8=B5=84=E6=BA=90=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 70ebbc3..e850088 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -40,13 +40,15 @@ build-arm64: - arm64 script: - docker buildx build --platform=linux/arm64 --pull -t "$IMG_URL$IMG_TAG-linux-arm64" . --push + - docker rmi "$IMG_URL$IMG_TAG-linux-arm64" build-amd64: stage: build - tags: + tags: - amd64 script: - docker buildx build --platform=linux/amd64 --pull -t "$IMG_URL$IMG_TAG-linux-amd64" . --push + - docker rmi "$IMG_URL$IMG_TAG-linux-amd64" build-artifact: stage: build @@ -54,13 +56,16 @@ build-artifact: script: - docker manifest create "$IMG_URL$IMG_TAG" "$IMG_URL$IMG_TAG-linux-arm64" "$IMG_URL$IMG_TAG-linux-amd64" - docker manifest push "$IMG_URL$IMG_TAG" + - docker manifest rm "$IMG_URL$IMG_TAG" # 测试阶段任务 test: stage: test script: - docker run --rm --platform=linux/arm64 "$IMG_URL$IMG_TAG" /bin/uname -a + - sleep 1 && docker rmi -f "$IMG_URL$IMG_TAG" - docker run --rm --platform=linux/amd64 "$IMG_URL$IMG_TAG" /bin/uname -a + - sleep 1 && docker rmi -f "$IMG_URL$IMG_TAG" # 部署阶段任务 deploy: From e341cd625a0839be58d808fac27eb3805673f72d Mon Sep 17 00:00:00 2001 From: Endial Fang Date: Fri, 11 Aug 2023 11:13:00 +0800 Subject: [PATCH 05/12] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E7=BC=93=E5=AD=98=E8=B5=84=E6=BA=90=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- Makefile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4c0b6d1..781917b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,7 +27,7 @@ ARG REGISTRY_URL="docker.colovu.com/" ARG APT_SOURCE=aliyun # 编译镜像时指定用于加速的本地软件包存储服务器地址 -ARG LOCAL_URL="" +ARG LOCAL_URL="https://local.colovu.com/dist" # 1. 生成镜像 ===================================================================== diff --git a/Makefile b/Makefile index c2885d6..cc76c49 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ build-arg+=--build-arg APT_SOURCE=$(APT_SOURCE) # 设置本地下载服务器路径,加速调试时的本地编译速度 local_ip:=`echo "en0 eth0" | xargs -n1 ip addr show 2>/dev/null | grep inet | grep -v 127.0.0.1 | grep -v inet6 | tr "/" " " | awk '{print $$2}'` -build-arg+=--build-arg LOCAL_URL=http://$(local_ip)/dist-files +build-arg+=--build-arg LOCAL_URL=https://local.colovu.com/dist .PHONY: build clean clearclean upgrade @@ -32,7 +32,7 @@ export DOCKER_SCAN_SUGGEST=false build: @echo "Build $(image_name):$(image_tag)" - @docker build --progress plain --force-rm $(build-arg) -t $(image_name):$(image_tag) . + @docker buildx build --progress plain --force-rm $(build-arg) -t $(image_name):$(image_tag) . @echo "Add tag: $(image_name):latest" @docker tag $(image_name):$(image_tag) $(image_name):latest @echo "Build complete" From 045bc39896615536a710e9b021632ad33c598990 Mon Sep 17 00:00:00 2001 From: Endial Fang Date: Wed, 6 Sep 2023 15:07:43 +0800 Subject: [PATCH 06/12] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0Docker=E6=89=93?= =?UTF-8?q?=E5=8C=85=E7=9A=84=E5=BF=BD=E7=95=A5=E6=96=87=E4=BB=B6=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index c0b11c0..4df4001 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,6 @@ .git .gitignore -./alpine ./Makefile *.yml From ddbba81e5ec9fd5f0e2c55b35fa0b3b0f5e43b3d Mon Sep 17 00:00:00 2001 From: Endial Fang Date: Wed, 6 Sep 2023 15:08:49 +0800 Subject: [PATCH 07/12] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E9=95=9C=E5=83=8F=E7=9A=84=E6=B8=85=E7=90=86=E6=93=8D?= =?UTF-8?q?=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e850088..c536fb3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,10 +13,10 @@ variables: default: # 各 stage 使用的默认镜像,如果不定义,则为 gitlab-runner 创建时指定的镜像;各 stage 可以覆盖该值以使用不同的镜像 image: docker.colovu.com/library/docker:20.10.16 - # Gitlab-runner 配置的执行器为 Docker 时,需要 配置对应的 dind 服务 - services: - - name: docker.colovu.com/library/docker:20.10.16-dind - alias: docker + # Gitlab-runner 配置的执行器为 Docker 时,需要 配置对应的 dind 服务(这里使用Runner中配置的Dind服务) + #services: + # - name: docker.colovu.com/library/docker:20.10.16-dind + # alias: docker # 流水线中,各阶段都会执行的脚本命令,包括`before_script`(在各阶段 script 前执行)/`after_script`(在各阶段 script 后执行) before_script: - | @@ -44,7 +44,7 @@ build-arm64: build-amd64: stage: build - tags: + tags: - amd64 script: - docker buildx build --platform=linux/amd64 --pull -t "$IMG_URL$IMG_TAG-linux-amd64" . --push @@ -62,10 +62,9 @@ build-artifact: test: stage: test script: - - docker run --rm --platform=linux/arm64 "$IMG_URL$IMG_TAG" /bin/uname -a - - sleep 1 && docker rmi -f "$IMG_URL$IMG_TAG" - - docker run --rm --platform=linux/amd64 "$IMG_URL$IMG_TAG" /bin/uname -a - - sleep 1 && docker rmi -f "$IMG_URL$IMG_TAG" + - docker run --pull always --rm --platform=linux/arm64 "$IMG_URL$IMG_TAG" /bin/uname -a + - docker run --pull always --rm --platform=linux/amd64 "$IMG_URL$IMG_TAG" /bin/uname -a + - docker images -q "$IMG_URL" | sort -u | xargs docker rmi -f # 部署阶段任务 deploy: From b65a926e48f89bd8a2adc22a603e49213dfee45d Mon Sep 17 00:00:00 2001 From: Endial Fang Date: Wed, 6 Sep 2023 15:10:05 +0800 Subject: [PATCH 08/12] =?UTF-8?q?feat:=20=E6=9C=AC=E5=9C=B0=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E8=84=9A=E6=9C=AC=E5=A2=9E=E5=8A=A0main/master?= =?UTF-8?q?=E5=88=86=E6=94=AF=E7=9A=84=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index cc76c49..6d59538 100644 --- a/Makefile +++ b/Makefile @@ -12,24 +12,21 @@ REGISTRY_URL :=docker.colovu.com APT_SOURCE :=aliyun # 定义镜像TAG,类似: -# <镜像名>:<分支名>-<7位Git ID> # Git 仓库且无文件修改直接编译 -# <镜像名>:<分支名>-<年月日>-<时分秒> # Git 仓库有文件修改后的编译 -# <镜像名>:latest-<年月日>-<时分秒> # 非 Git 仓库编译 +# <镜像名>:<分支名>-<7位Git ID> # Git 仓库且无文件修改直接编译 +# <镜像名>:<分支名>-<年月日>-<时分秒> # Git 仓库有文件修改后的编译 +# <镜像名>:latest-<年月日>-<时分秒> # 非 Git 仓库编译 current_subversion:=$(shell if [ ! `git status >/dev/null 2>&1` ]; then git rev-parse --short HEAD; else date +%y%m%d-%H%M%S; fi) -image_tag:=$(shell if [ ! `git status >/dev/null 2>&1` ]; then git rev-parse --abbrev-ref HEAD | sed -e 's/master/latest/'; else echo "latest"; fi)-$(current_subversion) +image_tag:=$(shell if [ ! `git status >/dev/null 2>&1` ]; then git rev-parse --abbrev-ref HEAD | sed -e 's/master/latest/' | sed -e 's/main/latest/'; else echo "latest"; fi)-$(current_subversion) build-arg:=--build-arg REGISTRY_URL=$(REGISTRY_URL) build-arg+=--build-arg APT_SOURCE=$(APT_SOURCE) # 设置本地下载服务器路径,加速调试时的本地编译速度 local_ip:=`echo "en0 eth0" | xargs -n1 ip addr show 2>/dev/null | grep inet | grep -v 127.0.0.1 | grep -v inet6 | tr "/" " " | awk '{print $$2}'` -build-arg+=--build-arg LOCAL_URL=https://local.colovu.com/dist +build-arg+=--build-arg LOCAL_URL=http://local.colovu.com/dist .PHONY: build clean clearclean upgrade -# 屏蔽 "Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them" -export DOCKER_SCAN_SUGGEST=false - build: @echo "Build $(image_name):$(image_tag)" @docker buildx build --progress plain --force-rm $(build-arg) -t $(image_name):$(image_tag) . From ea09e4cf197b79225b3b0291c885dc15bfe03150 Mon Sep 17 00:00:00 2001 From: Endial Fang Date: Wed, 6 Sep 2023 15:13:44 +0800 Subject: [PATCH 09/12] =?UTF-8?q?feat:=20=E5=9F=BA=E4=BA=8EDockerfile?= =?UTF-8?q?=E6=96=B0=E6=A8=A1=E6=9D=BF=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index 781917b..f6c553c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,8 @@ -# Ver: 1.9 by Endial Fang (endial@126.com) +# Ver: 1.10 by Endial Fang (endial@126.com) # -# 默认变量 ======================================================================== +# 系统默认变量 ==================================================================== # 该部分变量为系统根据编译命令默认设置 - # `TARGETPLATFORM`:构建后的目标平台信息。如 `linux/amd64`,`linux/arm/v7`,`windows/amd64` # `TARGETOS`:目标平台信息(TARGETPLATFORM)中的操作系统部分,如:`linux`、`windows` # `TARGETARCH`:目标平台信息(TARGETPLATFORM)中的平台架构部分,如:`amd64`、`arm` @@ -16,24 +15,16 @@ # 可变参数 ======================================================================== # 该部分变量,在编译命令中通过 `--build-arg` 传入;如果未设置,则使用下面对应的默认值 -# 设置当前应用名称及版本 -ARG APP_NAME=dbuilder -ARG APP_VER=12 - -# 设置默认仓库地址,默认为本地仓库;定义时需要包含末尾的`/` -ARG REGISTRY_URL="docker.colovu.com/" - -# 设置 apt-get 源:default / ustc / aliyun -ARG APT_SOURCE=aliyun - -# 编译镜像时指定用于加速的本地软件包存储服务器地址 -ARG LOCAL_URL="https://local.colovu.com/dist" - +ARG APP_NAME=dbuilder # 设置当前应用名称 +ARG APP_VER=12 # 设置当前应用版本 +ARG REGISTRY_URL="docker.colovu.com/" # 设置默认仓库地址,默认为本地仓库;定义时需要包含末尾的`/` +ARG APT_SOURCE=aliyun # 设置 apt-get 源:default / ustc / aliyun +ARG LOCAL_URL="http://local.colovu.com/dist" # 编译镜像时指定用于加速的本地软件包存储服务器地址 # 1. 生成镜像 ===================================================================== FROM --platform=${TARGETPLATFORM:-linux/amd64} ${REGISTRY_URL}colovu/debian:${APP_VER} -# 声明需要使用的全局可变参数 +# 声明需要使用的全局可变参数(ARG声明的变量仅编译打包阶段有效) ARG APP_NAME ARG APP_VER ARG APT_SOURCE @@ -60,14 +51,13 @@ LABEL \ # libpcre2-8-0 libperl5.28 libprocps7 libpsl5 libpython3-stdlib # libpython3.7-minimal libpython3.7-stdlib libquadmath0 libreadline7 librhash0 # librtmp1 libsasl2-2 libsasl2-modules-db libsqlite3-0 libssh2-1 libssl-dev -# libssl1.1 libstdc++-8-dev libtsan0 libubsan1 libuv1 libxml2 libxtables12 +# libssl3 libstdc++-8-dev libtsan0 libubsan1 libuv1 libxml2 libxtables12 # linux-libc-dev lsb-base lsb-release make mime-support nano net-tools openssl # patch perl perl-modules-5.28 pinentry-curses pkg-config procps python3 # python3-minimal python3.7 python3.7-minimal readline-common sudo wget # xz-utils RUN set -eux; \ - \ - # 选择软件包源 + # 选择软件包源,以加速后续软件包安装 select_source ${APT_SOURCE}; \ \ # 安装编译环境及常用开发库 From a4e17d008d5f40a388588acce7b0f6c5855cbd69 Mon Sep 17 00:00:00 2001 From: Endial Fang Date: Wed, 6 Sep 2023 15:20:07 +0800 Subject: [PATCH 10/12] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E4=B8=AD=E6=9C=89=E5=85=B3=E9=95=9C=E5=83=8F=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2d63859..6aceea5 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,10 @@ * 镜像地址: - 阿里云: registry.cn-shenzhen.aliyuncs.com/colovu/dbuilder:latest - - DockerHub:colovu/dbuilder:latest - Colovu Registry: docker.colovu.com/colovu/dbuilder:latest - - 依赖镜像:colovu/debian:latest + - 依赖镜像:colovu/debian:12 -> 后续相关命令行默认使用`[Colovu Registry](https://docker.colovu.com)`镜像服务器做说明 +> 后续相关命令行默认使用 Aliyun ACR 镜像服务器做说明 ## TL;DR @@ -25,7 +24,7 @@ Docker 快速启动命令: ```shell # 从 Registry 服务器下载镜像并启动 -$ docker run -it docker.colovu.com/colovu/dbuilder /bin/bash +$ docker run -it registry.cn-shenzhen.aliyuncs.com/colovu/dbuilder:latest /bin/bash ``` ## 数据卷 @@ -43,7 +42,7 @@ $ docker run -it docker.colovu.com/colovu/dbuilder /bin/bash ```dockerfile # 预编译阶段 =============================== -FROM docker.colovu.com/colovu/dbuilder:latest +FROM registry.cn-shenzhen.aliyuncs.com/colovu/dbuilder:latest WORKDIR /tmp @@ -66,7 +65,7 @@ CMD [] ```dockerfile # 预编译阶段。命名为`builder` ================== -FROM docker.colovu.com/colovu/dbuilder:latest as builder +FROM registry.cn-shenzhen.aliyuncs.com/colovu/dbuilder:latest as builder WORKDIR /tmp From e9e6f8b24669aafdebab3af206775d032815ad79 Mon Sep 17 00:00:00 2001 From: Endial Fang Date: Wed, 9 Apr 2025 16:16:46 +0800 Subject: [PATCH 11/12] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E8=84=9A=E6=9C=AC=EF=BC=9B=E5=90=AF=E7=94=A8=E5=8D=8E?= =?UTF-8?q?=E4=B8=BA=E4=BA=91=E9=95=9C=E5=83=8F=E5=AD=98=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 22 +++++------ build.sh | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 11 deletions(-) create mode 100755 build.sh diff --git a/Dockerfile b/Dockerfile index f6c553c..148693a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,28 @@ -# Ver: 1.10 by Endial Fang (endial@126.com) +# Ver: 1.11 by Endial Fang (endial@126.com) # # 系统默认变量 ==================================================================== # 该部分变量为系统根据编译命令默认设置 -# `TARGETPLATFORM`:构建后的目标平台信息。如 `linux/amd64`,`linux/arm/v7`,`windows/amd64` +# `TARGETPLATFORM`:构建后的目标平台信息。如 `linux/amd64`,`linux/arm/v7`,`windows/amd64` # `TARGETOS`:目标平台信息(TARGETPLATFORM)中的操作系统部分,如:`linux`、`windows` # `TARGETARCH`:目标平台信息(TARGETPLATFORM)中的平台架构部分,如:`amd64`、`arm` # `TARGETVARIANT`:目标平台信息(TARGETPLATFORM)中的版本变体部分,如:`v7` # `BUILDPLATFORM`:用于构建的节点平台信息 # `BUILDOS`:用于构建的节点平台信息(BUILDPLATFORM)中的操作系统部分 -# `BUILDARCH`用于构建的节点平台信息(BUILDPLATFORM)中的平台架构部分 -# `BUILDVARIANT`用于构建的节点平台信息(BUILDPLATFORM)中的版本变体部分 +# `BUILDARCH`:用于构建的节点平台信息(BUILDPLATFORM)中的平台架构部分 +# `BUILDVARIANT`:用于构建的节点平台信息(BUILDPLATFORM)中的版本变体部分 # 可变参数 ======================================================================== # 该部分变量,在编译命令中通过 `--build-arg` 传入;如果未设置,则使用下面对应的默认值 -ARG APP_NAME=dbuilder # 设置当前应用名称 -ARG APP_VER=12 # 设置当前应用版本 -ARG REGISTRY_URL="docker.colovu.com/" # 设置默认仓库地址,默认为本地仓库;定义时需要包含末尾的`/` -ARG APT_SOURCE=aliyun # 设置 apt-get 源:default / ustc / aliyun -ARG LOCAL_URL="http://local.colovu.com/dist" # 编译镜像时指定用于加速的本地软件包存储服务器地址 +ARG APP_NAME=dBuilder +ARG APP_VER=12 +ARG REGISTRY_URL="swr.cn-north-4.myhuaweicloud.com/colovu/" +ARG APT_SOURCE=aliyun +ARG LOCAL_URL="http://pkgs.colovu.com/dist" # 1. 生成镜像 ===================================================================== -FROM --platform=${TARGETPLATFORM:-linux/amd64} ${REGISTRY_URL}colovu/debian:${APP_VER} +FROM --platform=${TARGETPLATFORM:-linux/amd64} ${REGISTRY_URL}debian:${APP_VER} # 声明需要使用的全局可变参数(ARG声明的变量仅编译打包阶段有效) ARG APP_NAME @@ -32,7 +32,7 @@ ARG APT_SOURCE LABEL \ "Version"="v${APP_VER}" \ "Description"="Docker image for Builder based on Debian." \ - "Github"="https://github.com/colovu/docker-${APP_NAME}" \ + "Github"="https://gitee.com/colovu/docker-${APP_NAME}" \ "Vendor"="Endial Fang (endial@126.com)" # 以下命令安装的软件包 diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..5816448 --- /dev/null +++ b/build.sh @@ -0,0 +1,110 @@ +#!/bin/bash +# Ver: 1.0 by Endial Fang (endial@126.com) +# +# Docker 镜像构建脚本 (仅linux/amd64) + +IMAGE_NAME="dbuilder" +REGISTRY_URL="swr.cn-north-4.myhuaweicloud.com/colovu/" +APT_SOURCE="aliyun" + +# 获取发布版本标签 +get_release_tag() { + if ! git rev-parse --git-dir >/dev/null 2>&1; then + echo "unknown" + elif [ -n "$(git status --porcelain)" ]; then + echo "latest" + else + # 尝试获取最近的git标签 + local tag=$(git describe --tags --abbrev=0 2>/dev/null) + if [ -n "$tag" ]; then + echo "$tag" + else + local branch=$(git rev-parse --abbrev-ref HEAD) + case "$branch" in + master|main) echo "latest" ;; + *) echo "$branch" ;; + esac + fi + fi +} + +# 获取镜像完整TAG +get_image_tag() { + local CURRENT_SUBVERSION + if git rev-parse --git-dir >/dev/null 2>&1; then + if [ -z "$(git status --porcelain)" ]; then + CURRENT_SUBVERSION=$(git rev-parse --short=12 HEAD) + else + CURRENT_SUBVERSION=$(date +%Y%m%d-%H%M%S) + fi + local branch=$(git rev-parse --abbrev-ref HEAD) + branch=$(echo "$branch" | sed -e 's/master/latest/' -e 's/main/latest/') + echo "${branch}-${CURRENT_SUBVERSION}" + else + CURRENT_SUBVERSION=$(date +%Y%m%d-%H%M%S) + echo "latest-${CURRENT_SUBVERSION}" + fi +} + +# 构建amd64架构镜像 +build() { + local TAG=${1:-$(get_image_tag)} + echo "Building image ${IMAGE_NAME}:${TAG} (linux/amd64)" + + podman build --platform linux/amd64 \ + --progress plain --force-rm \ + --build-arg REGISTRY_URL=${REGISTRY_URL} \ + --build-arg APT_SOURCE=${APT_SOURCE} \ + --build-arg LOCAL_URL=http://pkgs.colovu.com/dist \ + -t ${IMAGE_NAME}:${TAG} \ + -t ${IMAGE_NAME}:latest \ + . + + echo "Build complete" +} + +# 推送镜像到colovu仓库 +push_colovu() { + local TAG=${1:-$(get_image_tag)} + echo "Pushing ${IMAGE_NAME}:${TAG} to registry.colovu.com" + + podman tag "${IMAGE_NAME}:${TAG}" "registry.colovu.com/library/${IMAGE_NAME}:${TAG}" + podman push "registry.colovu.com/library/${IMAGE_NAME}:${TAG}" + + podman tag "${IMAGE_NAME}:latest" "registry.colovu.com/library/${IMAGE_NAME}:latest" + podman push "registry.colovu.com/library/${IMAGE_NAME}:latest" +} + +# 推送镜像到华为云仓库 +push_huawei() { + local TAG=${1:-$(get_release_tag)} + echo "Pushing ${IMAGE_NAME}:${TAG} to swr.cn-north-4.myhuaweicloud.com" + + podman tag "${IMAGE_NAME}:${TAG}" "swr.cn-north-4.myhuaweicloud.com/colovu/${IMAGE_NAME}:${TAG}" + podman push "swr.cn-north-4.myhuaweicloud.com/colovu/${IMAGE_NAME}:${TAG}" + + podman tag "${IMAGE_NAME}:latest" "swr.cn-north-4.myhuaweicloud.com/colovu/${IMAGE_NAME}:latest" + podman push "swr.cn-north-4.myhuaweicloud.com/colovu/${IMAGE_NAME}:latest" +} + +# 清理工作空间 +clean() { + echo "Cleaning workspace..." + podman images | grep "${IMAGE_NAME} " | awk '{print $3}' | xargs -L 1 podman rmi -f + podman ps -a | grep "Exited" | awk '{print $1}' | xargs -L 1 podman rm + podman images | grep '' | awk '{print $3}' | xargs -L 1 podman rmi -f +} + +# 主函数中更新使用说明 +main() { + case "$1" in + build) build "$2" ;; # 传递第二个参数作为标签 + clean) clean ;; + push-cv) push_colovu "$2" ;; + push-hw) push_huawei "$2" ;; + push) push_colovu "$2"; push_huawei "$2" ;; + *) echo "Usage: $0 {build [tag]|clean|push-cv [tag]|push-hw [tag]|push [tag]}"; exit 1 ;; + esac +} + +main "$@" \ No newline at end of file From 5c5f028a9f8717ae5b88d22f1779b3ecd255681a Mon Sep 17 00:00:00 2001 From: Endial Fang Date: Wed, 9 Apr 2025 16:17:04 +0800 Subject: [PATCH 12/12] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0=E6=8F=8F?= =?UTF-8?q?=E8=BF=B0=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 6aceea5..7051597 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Builder +# dBuilder 预安装常用工具及编译工具的镜像。 @@ -7,16 +7,17 @@ **版本信息:** -- latest +- 12、latest **镜像信息:** * 镜像地址: - - 阿里云: registry.cn-shenzhen.aliyuncs.com/colovu/dbuilder:latest - - Colovu Registry: docker.colovu.com/colovu/dbuilder:latest - - 依赖镜像:colovu/debian:12 + * 华为云: swr.cn-north-4.myhuaweicloud.com/colovu/dBuilder:latest + * Colovu: registry.colovu.com/library/dBuilder:latest + * 依赖镜像:registry.colovu.com/library/debian:12 + swr.cn-north-4.myhuaweicloud.com/colovu/debian:12 -> 后续相关命令行默认使用 Aliyun ACR 镜像服务器做说明 +> 后续相关命令行默认使用华为云 SWR 镜像服务器做说明。 ## TL;DR @@ -24,7 +25,7 @@ Docker 快速启动命令: ```shell # 从 Registry 服务器下载镜像并启动 -$ docker run -it registry.cn-shenzhen.aliyuncs.com/colovu/dbuilder:latest /bin/bash +docker run -it swr.cn-north-4.myhuaweicloud.com/colovu/dbuilder:latest /bin/bash ``` ## 数据卷 @@ -42,7 +43,7 @@ $ docker run -it registry.cn-shenzhen.aliyuncs.com/colovu/dbuilder:latest /bin/b ```dockerfile # 预编译阶段 =============================== -FROM registry.cn-shenzhen.aliyuncs.com/colovu/dbuilder:latest +FROM swr.cn-north-4.myhuaweicloud.com/colovu/dbuilder:latest WORKDIR /tmp @@ -65,7 +66,7 @@ CMD [] ```dockerfile # 预编译阶段。命名为`builder` ================== -FROM registry.cn-shenzhen.aliyuncs.com/colovu/dbuilder:latest as builder +FROM swr.cn-north-4.myhuaweicloud.com/colovu/dbuilder:latest as builder WORKDIR /tmp @@ -92,4 +93,4 @@ CMD [] ---- -本文原始来源 [Endial Fang](https://github.com/colovu) @ [Github.com](https://github.com) +本文原始来源 [Endial Fang](https://gitee.com/colovu) @ [Gitee.com](https://gitee.com)