Linux运维_Bash脚本_源码编译Moby(Docker-CE)-20240803
Bash (Bourne Again Shell) 是一个解释器,负责处理 Unix 系统命令行上的命令。它是由 Brian Fox 编写的免费软件,并于 1989 年发布的免费软件,作为 Sh (Bourne Shell) 的替代品。
您可以在 Linux 和 MacOS 机器上使用 Bash,甚至可以通过适用于 Linux 的 Windows 子系统在 Windows 10 机器上使用。
使用方法
- 下载源码包:
alpine-3.20.0-in-docker-amd64.tar.gz (Docker 镜像)
golang-1.21.12-alpine3.20-in-docker-amd64.tar.gz (Docker 镜像)
tonistiigi-xx-1.4.0-in-docker-amd64.tar.gz (Docker 镜像)
golang-1.21.12-bookworm-in-docker-amd64.tar.gz (Docker 镜像)
apk_for_build-base-alpine_FROM_golang_1.21.12-alpine3.20.zip (Alpine Apk 缓存包)
apk_for_build-alpine_FROM_build-base-alpine.zip (Alpine Apk 缓存包)
apk_for_e2e-base-alpine_FROM_build-base-alpine.zip (Alpine Apk 缓存包)
(以上 Alpine Apk 缓存包链接: https://download.csdn.net/download/goufeng93/89711123)
deb_for_base_FROM_golang-1.21.12-bookworm.zip (Debian Deb 缓存包)
deb_for_criu_FROM_base.zip (Debian Deb 缓存包)
deb_for_frozen-images_FROM_debian-bookworm.zip (Debian Deb 缓存包)
deb_for_containerd-build_FROM_base.zip (Debian Deb 缓存包)
deb_for_runc-build_FROM_base.zip (Debian Deb 缓存包)
deb_for_tini-build_FROM_base_apt-get.zip (Debian Deb 缓存包)
deb_for_tini-build_FROM_base_xx-apt-get.zip (Debian Deb 缓存包)
deb_for_rootlesskit-build_FROM_base.zip (Debian Deb 缓存包)
deb_for_crun_FROM_base.zip (Debian Deb 缓存包)
deb_for_containerutil-build_FROM_base.zip (Debian Deb 缓存包)
deb_for_dev-systemd-true_FROM_dev-systemd-false.zip (Debian Deb 缓存包)
deb_for_dev-base_FROM_dev-systemd-false_apt-get-1.zip (Debian Deb 缓存包)
deb_for_dev-base_FROM_dev-systemd-false_apt-get-2.zip (Debian Deb 缓存包)
deb_for_build_FROM_base_apt-get.zip (Debian Deb 缓存包)
deb_for_build_FROM_base_xx-apt-get.zip (Debian Deb 缓存包)
(以上 Debian Deb 缓存包链接: https://download.csdn.net/download/goufeng93/89714645)
buildx-0.16.2.tar.gz
runc-master-20240804.tar.gz
cli-master-20240805.tar.gz
(以上 cli-master-20240805.tar.gz 源码包链接: https://download.csdn.net/download/goufeng93/89711126)
moby-matser-20240803.tar.gz
(以上 moby-matser-20240803.tar.gz 源码包链接: https://download.csdn.net/download/goufeng93/89714646)
- 放于指定路径:
这里 Bash Shell 脚本的全局变量 STORAGE 指定的存放源码包的路径 /home/goufeng 可进行修改。
- 执行 Bash Shell 脚本:
输入 /[路径名]/[脚本名].sh 即可进行自动编译部署,过程中提示输入 (y/n) 输入 y 则进行下一步,这样分阶段确认的原因是为了确保能够看到上一个源码编译结果中可能的错误和提示。
完整脚本
shell
#! /bin/bash
# Create By GF 2024-08-03 01:34
# --------------------------------------------------
# Install First:
# * Go >= 1.21.x
# * Git
# * Docker-CE >= 20.10 (Binary Deploy)
# -------------- Docker Image for Cli --------------
# Need File: alpine-3.20.0-in-docker-amd64.tar.gz
# Need File: golang-1.21.12-alpine3.20-in-docker-amd64.tar.gz
# Need File: tonistiigi-xx-1.4.0-in-docker-amd64.tar.gz
# -------------- Docker Image for Moby -------------
# Need File: golang-1.21.12-bookworm-in-docker-amd64.tar.gz
# ----------------- Apk for Alpine -----------------
# Need File: apk_for_build-base-alpine_FROM_golang_1.21.12-alpine3.20.zip
# Need File: apk_for_build-alpine_FROM_build-base-alpine.zip
# Need File: apk_for_e2e-base-alpine_FROM_build-base-alpine.zip
# ----------------- Deb for Debian -----------------
# Need File: deb_for_base_FROM_golang-1.21.12-bookworm.zip
# Need File: deb_for_criu_FROM_base.zip
# Need File: deb_for_frozen-images_FROM_debian-bookworm.zip
# Need File: deb_for_containerd-build_FROM_base.zip
# Need File: deb_for_runc-build_FROM_base.zip
# Need File: deb_for_tini-build_FROM_base_apt-get.zip
# Need File: deb_for_tini-build_FROM_base_xx-apt-get.zip
# Need File: deb_for_rootlesskit-build_FROM_base.zip
# Need File: deb_for_crun_FROM_base.zip
# Need File: deb_for_containerutil-build_FROM_base.zip
# Need File: deb_for_dev-systemd-true_FROM_dev-systemd-false.zip
# Need File: deb_for_dev-base_FROM_dev-systemd-false_apt-get-1.zip
# Need File: deb_for_dev-base_FROM_dev-systemd-false_apt-get-2.zip
# Need File: deb_for_build_FROM_base_apt-get.zip
# Need File: deb_for_build_FROM_base_xx-apt-get.zip
# ------------------- Dependency -------------------
# Need File: buildx-0.16.2.tar.gz
# Need File: runc-master-20240804.tar.gz
# ------------ Docker-CE-Cli - 20240805 ------------
# Need File: cli-master-20240805.tar.gz
# ----------- Moby(Docker-CE) - 20240803 -----------
# Need File: moby-matser-20240803.tar.gz
# ##################################################
STORAGE=/home/goufeng
# ############# Compilation Environment ############
ORIGINAL_PATH=$PATH
# ########################################### Docker Image ###########################################
DOCKER_IMAGE_UNZIPPED=0
test ! -f "$STORAGE/alpine-3.20.0-in-docker-amd64.tar" &&
(gunzip $STORAGE/alpine-3.20.0-in-docker-amd64.tar.gz && DOCKER_IMAGE_UNZIPPED=1)
test ! -f "$STORAGE/golang-1.21.12-alpine3.20-in-docker-amd64.tar" &&
(gunzip $STORAGE/golang-1.21.12-alpine3.20-in-docker-amd64.tar.gz && DOCKER_IMAGE_UNZIPPED=2)
test ! -f "$STORAGE/tonistiigi-xx-1.4.0-in-docker-amd64.tar" &&
(gunzip $STORAGE/tonistiigi-xx-1.4.0-in-docker-amd64.tar.gz && DOCKER_IMAGE_UNZIPPED=3)
# docker load -i image_of_docker.tar
# ########################################## Apk for Alpine ##########################################
ALPINE_APK_UNZIPPED=0
# build-base-alpine (FROM golang:1.21.12-alpine3.20)
# apk add bash clang lld llvm file git
test ! -d "$STORAGE/apk_for_build-base-alpine_FROM_golang_1.21.12-alpine3.20" &&
(unzip -o $STORAGE/apk_for_build-base-alpine_FROM_golang_1.21.12-alpine3.20.zip && ALPINE_APK_UNZIPPED=1)
# build-alpine (FROM build-base-alpine)
# apk add musl-dev gcc
test ! -d "$STORAGE/apk_for_build-alpine_FROM_build-base-alpine" &&
(unzip -o $STORAGE/apk_for_build-alpine_FROM_build-base-alpine.zip && ALPINE_APK_UNZIPPED=2)
# e2e-base-alpine (FROM build-base-alpine)
# apk add build-base curl openssl openssh-client
test ! -d "$STORAGE/apk_for_e2e-base-alpine_FROM_build-base-alpine" &&
(unzip -o $STORAGE/apk_for_e2e-base-alpine_FROM_build-base-alpine.zip && ALPINE_APK_UNZIPPED=3)
# ########################################## Deb for Debian ##########################################
DEBIAN_DEB_UNZIPPED=0
# base (FROM golang:1.21.12-bookworm)
# apt-get install --no-install-recommends -y file
test ! -d "$STORAGE/deb_for_base_FROM_golang-1.21.12-bookworm" &&
(unzip -o $STORAGE/deb_for_base_FROM_golang-1.21.12-bookworm.zip && DEBIAN_DEB_UNZIPPED=1)
# criu (FROM base)
# apt-get install -y --no-install-recommends criu
test ! -d "$STORAGE/deb_for_criu_FROM_base" &&
(unzip -o $STORAGE/deb_for_criu_FROM_base.zip && DEBIAN_DEB_UNZIPPED=2)
# frozen-images (FROM debian:bookworm)
# apt-get install -y --no-install-recommends ca-certificates curl jq
test ! -d "$STORAGE/deb_for_frozen-images_FROM_debian-bookworm" &&
(unzip -o $STORAGE/deb_for_frozen-images_FROM_debian-bookworm.zip && DEBIAN_DEB_UNZIPPED=3)
# containerd-build (FROM base)
# xx-apt-get install -y --no-install-recommends gcc libbtrfs-dev libsecret-1-dev pkg-config
test ! -d "$STORAGE/deb_for_containerd-build_FROM_base" &&
(unzip -o $STORAGE/deb_for_containerd-build_FROM_base.zip && DEBIAN_DEB_UNZIPPED=4)
# runc-build (FROM base)
# xx-apt-get install -y --no-install-recommends dpkg-dev gcc libc6-dev libseccomp-dev pkg-config
test ! -d "$STORAGE/deb_for_runc-build_FROM_base" &&
(unzip -o $STORAGE/deb_for_runc-build_FROM_base.zip && DEBIAN_DEB_UNZIPPED=5)
# tini-build (FROM base)
# apt-get install -y --no-install-recommends cmake
# xx-apt-get install -y --no-install-recommends gcc libc6-dev pkg-config
test ! -d "$STORAGE/deb_for_tini-build_FROM_base_apt-get" &&
(unzip -o $STORAGE/deb_for_tini-build_FROM_base_apt-get.zip && DEBIAN_DEB_UNZIPPED=6)
test ! -d "$STORAGE/deb_for_tini-build_FROM_base_xx-apt-get" &&
(unzip -o $STORAGE/deb_for_tini-build_FROM_base_xx-apt-get.zip && DEBIAN_DEB_UNZIPPED=7)
# rootlesskit-build (FROM base)
# xx-apt-get install -y --no-install-recommends gcc libc6-dev pkg-config
test ! -d "$STORAGE/deb_for_rootlesskit-build_FROM_base" &&
(unzip -o $STORAGE/deb_for_rootlesskit-build_FROM_base.zip && DEBIAN_DEB_UNZIPPED=8)
# crun (FROM base)
# apt-get install -y --no-install-recommends autoconf automake build-essential libcap-dev libprotobuf-c-dev libseccomp-dev libsystemd-dev libtool \
# libudev-dev libyajl-dev python3 ;
test ! -d "$STORAGE/deb_for_crun_FROM_base" &&
(unzip -o $STORAGE/deb_for_crun_FROM_base.zip && DEBIAN_DEB_UNZIPPED=9)
# containerutil-build (FROM base)
# xx-apt-get install -y --no-install-recommends gcc g++ libc6-dev pkg-config
test ! -d "$STORAGE/deb_for_containerutil-build_FROM_base" &&
(unzip -o $STORAGE/deb_for_containerutil-build_FROM_base.zip && DEBIAN_DEB_UNZIPPED=10)
# dev-systemd-true (FROM dev-systemd-false)
# apt-get install -y --no-install-recommends dbus dbus-user-session systemd systemd-sysv
test ! -d "$STORAGE/deb_for_dev-systemd-true_FROM_dev-systemd-false" &&
(unzip -o $STORAGE/deb_for_dev-systemd-true_FROM_dev-systemd-false.zip && DEBIAN_DEB_UNZIPPED=11)
# dev-base (FROM dev-systemd-false)
# apt-get install -y --no-install-recommends apparmor bash-completion bzip2 inetutils-ping iproute2 iptables jq libcap2-bin libnet1 libnl-3-200 \
# libprotobuf-c1 libyajl2 net-tools patch pigz sudo systemd-journal-remote thin-provisioning-tools \
# uidmap vim vim-common xfsprogs xz-utils zip zstd
# apt-get install --no-install-recommends -y gcc pkg-config dpkg-dev libapparmor-dev libseccomp-dev libsecret-1-dev libsystemd-dev libudev-dev yamllint
test ! -d "$STORAGE/deb_for_dev-base_FROM_dev-systemd-false_apt-get-1" &&
(unzip -o $STORAGE/deb_for_dev-base_FROM_dev-systemd-false_apt-get-1.zip && DEBIAN_DEB_UNZIPPED=12)
test ! -d "$STORAGE/deb_for_dev-base_FROM_dev-systemd-false_apt-get-2" &&
(unzip -o $STORAGE/deb_for_dev-base_FROM_dev-systemd-false_apt-get-2.zip && DEBIAN_DEB_UNZIPPED=13)
# build (FROM base)
# apt-get install --no-install-recommends -y clang lld llvm
# xx-apt-get install --no-install-recommends -y dpkg-dev gcc libapparmor-dev libc6-dev libseccomp-dev libsecret-1-dev libsystemd-dev libudev-dev pkg-config
test ! -d "$STORAGE/deb_for_build_FROM_base_apt-get" &&
(unzip -o $STORAGE/deb_for_build_FROM_base_apt-get.zip && DEBIAN_DEB_UNZIPPED=14)
test ! -d "$STORAGE/deb_for_build_FROM_base_xx-apt-get" &&
(unzip -o $STORAGE/deb_for_build_FROM_base_xx-apt-get.zip && DEBIAN_DEB_UNZIPPED=15)
# ######################################## Go Library for Cli ########################################
GO_LIB_FOR_CLI_UNZIPPED=0
test ! -d "$STORAGE/rsrc-master-20240807" &&
(tar -zxvf $STORAGE/rsrc-master-20240807.tar.gz && GO_LIB_FOR_CLI_UNZIPPED=1)
test ! -d "$STORAGE/goversioninfo-master-20240807" &&
(tar -zxvf $STORAGE/goversioninfo-master-20240807.tar.gz && GO_LIB_FOR_CLI_UNZIPPED=2)
# ######################################## Go Library for Moby #######################################
GO_LIB_FOR_MOBY_UNZIPPED=0
test ! -d "$STORAGE/winres-0.2.1" &&
(tar -zxvf $STORAGE/winres-0.2.1.tar.gz && GO_LIB_FOR_MOBY_UNZIPPED=1)
test ! -d "$STORAGE/resize-master-20180222" &&
(tar -zxvf $STORAGE/resize-master-20180222.tar.gz && GO_LIB_FOR_MOBY_UNZIPPED=2)
test ! -d "$STORAGE/image-master-20240806" &&
(tar -zxvf $STORAGE/image-master-20240806.tar.gz && GO_LIB_FOR_MOBY_UNZIPPED=3)
test ! -d "$STORAGE/cli-2.27.4" &&
(tar -zxvf $STORAGE/cli-2.27.4.tar.gz && GO_LIB_FOR_MOBY_UNZIPPED=4)
test ! -d "$STORAGE/go-md2man-2.0.4" &&
(tar -zxvf $STORAGE/go-md2man-2.0.4.tar.gz && GO_LIB_FOR_MOBY_UNZIPPED=5)
test ! -d "$STORAGE/smetrics-master-20240522" &&
(tar -zxvf $STORAGE/smetrics-master-20240522.tar.gz && GO_LIB_FOR_MOBY_UNZIPPED=6)
test ! -d "$STORAGE/blackfriday-2.1.0" &&
(tar -zxvf $STORAGE/blackfriday-2.1.0.tar.gz && GO_LIB_FOR_MOBY_UNZIPPED=7)
test ! -d "$STORAGE/go-winres-0.3.1" &&
(tar -zxvf $STORAGE/go-winres-0.3.1.tar.gz && GO_LIB_FOR_MOBY_UNZIPPED=8)
# ############################################ Dependency ############################################
# 构建安装(Build Install) buildx - 0.16.2
# --------------------------------------------------
export PATH=/opt/go-1.21.11/bin:$ORIGINAL_PATH
export GOPATH=/opt/go-1.21.11
BUILDX_VERIFY='n'
BUILDX_UNZIPPED=0
BUILDX_BUILDED=0
read -p "[Confirm] Build and Install ( buildx-0.16.2 )? (y/n)>" BUILDX_VERIFY
test "$BUILDX_VERIFY" != "y" && exit 1
test ! -f "/$USER/.docker/cli-plugins/docker-buildx" && (
(tar -zxvf $STORAGE/buildx-0.16.2.tar.gz && BUILDX_UNZIPPED=1) &&
(cd $STORAGE/buildx-0.16.2 && hack/build && BUILDX_BUILDED=1) &&
(cp -v $STORAGE/buildx-0.16.2/bin/build/docker-buildx /$USER/.docker/cli-plugins/) &&
(chmod +x /$USER/.docker/cli-plugins/docker-buildx) &&
(cd $STORAGE && rm -rf $STORAGE/buildx-0.16.2)
) || (
echo "[Caution] Binary: ( /$USER/.docker/cli-plugins/docker-buildx ) Already Exists."
)
# 编译安装(Build Install) runc - master - 20240804
# --------------------------------------------------
export PATH=/opt/go-1.21.11/bin:$ORIGINAL_PATH
export GOPATH=/opt/go-1.21.11
RUNC_VERIFY='n'
RUNC_UNZIPPED=0
RUNC_BUILDED=0
read -p "[Confirm] Build and Install ( runc-master-20240804 )? (y/n)>" RUNC_VERIFY
test "$RUNC_VERIFY" != "y" && exit 1
test ! -f "/opt/runc-master-20240804/bin/runc" && (
(tar -zxvf $STORAGE/runc-master-20240804.tar.gz && RUNC_UNZIPPED=1) &&
(cd $STORAGE/runc-master-20240804 && go build && RUNC_BUILDED=1) &&
(mkdir -p /opt/runc-master-20240804/bin) &&
(cp -v $STORAGE/runc-master-20240804/runc /opt/runc-master-20240804/bin/) &&
(chmod +x /opt/runc-master-20240804/bin/runc) &&
(cd $STORAGE && rm -rf $STORAGE/runc-master-20240804)
) || (
echo "[Caution] Binary: ( /opt/runc-master-20240804/bin/runc ) Already Exists."
)
# ################################ Docker-CE: Cli - master - 20240805 ################################
# 编译安装(Make Install) Docker-CE: Cli - master - 20240805
# --------------------------------------------------
DOCKER_CE_CLI_VERIFY='n'
DOCKER_CE_CLI_UNZIPPED=0
DOCKER_CE_CLI_MADE=0
NUMBER_OF_NEW_ADDED_ROWS=0
read -p "[Confirm] Make and Install ( docker-ce: cli-master-20240805 )? (y/n)>" DOCKER_CE_CLI_VERIFY
test "$DOCKER_CE_CLI_VERIFY" != "y" && exit 1
test ! -f "/opt/cli-master-20240805/bin/docker" && (
(tar -zxvf $STORAGE/cli-master-20240805.tar.gz && DOCKER_CE_CLI_UNZIPPED=1) &&
(echo "--------------------------------------------------") &&
(mkdir -p $STORAGE/cli-master-20240805/local_apk_part_1) &&
(mkdir -p $STORAGE/cli-master-20240805/local_apk_part_2) &&
(mkdir -p $STORAGE/cli-master-20240805/local_apk_part_3) &&
(cp -v $STORAGE/apk_for_build-base-alpine_FROM_golang_1.21.12-alpine3.20/*.apk $STORAGE/cli-master-20240805/local_apk_part_1/) &&
(cp -v $STORAGE/apk_for_build-alpine_FROM_build-base-alpine/*.apk $STORAGE/cli-master-20240805/local_apk_part_2/) &&
(cp -v $STORAGE/apk_for_e2e-base-alpine_FROM_build-base-alpine/*.apk $STORAGE/cli-master-20240805/local_apk_part_3/) &&
(echo "--------------------------------------------------") &&
(mkdir -p $STORAGE/cli-master-20240805/rsrc ) &&
(mkdir -p $STORAGE/cli-master-20240805/goversioninfo) &&
(cp -vr $STORAGE/rsrc-master-20240807/* $STORAGE/cli-master-20240805/rsrc/ ) &&
(cp -vr $STORAGE/goversioninfo-master-20240807/* $STORAGE/cli-master-20240805/goversioninfo/) &&
(echo "--------------------------------------------------") &&
(echo "Modify> 1:# syntax=docker/dockerfile:1 [ ===> # null ]") &&
(echo " 2:" ) &&
(echo " 3:ARG BASE_VARIANT=alpine" ) &&
(echo " ......" ) &&
(sed -i "1s/.*/# null/" $STORAGE/cli-master-20240805/Dockerfile) &&
(NUMBER_OF_NEW_ADDED_ROWS=0) &&
(echo "--------------------------------------------------") &&
(echo " 18:COPY --link --from=xx / /" ) &&
(echo "Insert> COPY local_apk_part_1/ /tmp/local_apk_part_1/" ) &&
(echo "Insert> RUN sed -ir 's#dl-cdn.alpinelinux.org#mirrors.aliyun.com#g' /etc/apk/repositories" ) &&
(echo "Delete> 19:RUN apk add --no-cache bash clang lld llvm file git" ) &&
(echo "Insert> 19:RUN apk add /tmp/local_apk_part_1/*.apk" ) &&
(echo " 20:WORKDIR /go/src/github.com/docker/cli" ) &&
(echo " ......" ) &&
(sed -i "19i\COPY local_apk_part_1/ /tmp/local_apk_part_1/" $STORAGE/cli-master-20240805/Dockerfile) &&
(sed -i "20i\RUN sed -ir 's#dl-cdn.alpinelinux.org#mirrors.aliyun.com#g' /etc/apk/repositories" $STORAGE/cli-master-20240805/Dockerfile) &&
(sed -i "21d" $STORAGE/cli-master-20240805/Dockerfile) &&
(sed -i "21i\RUN apk add /tmp/local_apk_part_1/*.apk" $STORAGE/cli-master-20240805/Dockerfile) &&
(NUMBER_OF_NEW_ADDED_ROWS=2) &&
(echo "--------------------------------------------------") &&
(echo " 23:ARG TARGETPLATFORM" ) &&
(echo "Insert> COPY local_apk_part_2/ /tmp/local_apk_part_2/" ) &&
(echo "Insert> RUN sed -ir 's#dl-cdn.alpinelinux.org#mirrors.aliyun.com#g' /etc/apk/repositories" ) &&
(echo " 24:# gcc is installed for libgcc only" ) &&
(echo "Delete> 25:RUN xx-apk add --no-cache musl-dev gcc" ) &&
(echo "Insert> 25:RUN xx-apk add /tmp/local_apk_part_2/*.apk" ) &&
(echo " ......" ) &&
(sed -i "26i\COPY local_apk_part_2/ /tmp/local_apk_part_2/" $STORAGE/cli-master-20240805/Dockerfile) &&
(sed -i "27i\RUN sed -ir 's#dl-cdn.alpinelinux.org#mirrors.aliyun.com#g' /etc/apk/repositories" $STORAGE/cli-master-20240805/Dockerfile) &&
(sed -i "29d" $STORAGE/cli-master-20240805/Dockerfile) &&
(sed -i "29i\RUN xx-apk add /tmp/local_apk_part_2/*.apk" $STORAGE/cli-master-20240805/Dockerfile) &&
(NUMBER_OF_NEW_ADDED_ROWS=4) &&
(echo "--------------------------------------------------") &&
(echo " 37:FROM build-base-\${BASE_VARIANT} AS goversioninfo" ) &&
(echo " 38:ARG GOVERSIONINFO_VERSION" ) &&
(echo "Insert> COPY rsrc/ /usr/local/go/src/github.com/akavel/rsrc/" ) &&
(echo "Insert> COPY goversioninfo/ /usr/local/go/src/github.com/josephspurrier/goversioninfo/" ) &&
(echo "Insert> WORKDIR /usr/local/go" ) &&
(echo " 39:RUN --mount=type=cache,target=/root/.cache/go-build \\" ) &&
(echo " 40: --mount=type=cache,target=/go/pkg/mod \\" ) &&
(echo "Delete> 41: GOBIN=/out GO111MODULE=on CGO_ENABLED=0 go install \"github.com/josephspurrier/goversioninfo/cmd/goversioninfo@\${GOVERSIONINFO_VERSION}\"" ) &&
(echo "Insert> 41: GOBIN=/out GO111MODULE=off CGO_ENABLED=0 go install ./src/github.com/josephspurrier/goversioninfo/cmd/goversioninfo" ) &&
(echo " 42:" ) &&
(echo " 43:FROM build-base-\${BASE_VARIANT} AS gotestsum" ) &&
(echo " ......" ) &&
(sed -i "43i\COPY rsrc/ /usr/local/go/src/github.com/akavel/rsrc/" $STORAGE/cli-master-20240805/Dockerfile) &&
(sed -i "44i\COPY goversioninfo/ /usr/local/go/src/github.com/josephspurrier/goversioninfo/" $STORAGE/cli-master-20240805/Dockerfile) &&
(sed -i "45i\WORKDIR /usr/local/go" $STORAGE/cli-master-20240805/Dockerfile) &&
(sed -i "48d" $STORAGE/cli-master-20240805/Dockerfile) &&
(sed -i "48i\ GOBIN=/out GO111MODULE=off CGO_ENABLED=0 go install ./src/github.com/josephspurrier/goversioninfo/cmd/goversioninfo" $STORAGE/cli-master-20240805/Dockerfile) &&
(NUMBER_OF_NEW_ADDED_ROWS=7) &&
(echo "--------------------------------------------------") &&
(echo " 62:ARG PACKAGER_NAME" ) &&
(echo "Delete> 63:COPY --link --from=goversioninfo /out/goversioninfo /usr/bin/goversioninfo" ) &&
(echo "Insert> 63:COPY --link --from=goversioninfo /usr/local/go/bin/goversioninfo /usr/bin/goversioninfo" ) &&
(echo " 64:RUN --mount=type=bind,target=.,ro \\" ) &&
(echo " ......" ) &&
(sed -i "70d" $STORAGE/cli-master-20240805/Dockerfile) &&
(sed -i "70i\COPY --link --from=goversioninfo /usr/local/go/bin/goversioninfo /usr/bin/goversioninfo" $STORAGE/cli-master-20240805/Dockerfile) &&
(NUMBER_OF_NEW_ADDED_ROWS=7) &&
(echo "--------------------------------------------------") &&
(cd $STORAGE/cli-master-20240805 && make -f docker.Makefile binary && DOCKER_CE_CLI_MADE=1) &&
(mkdir -p /opt/cli-master-20240805/bin ) &&
(cp -v $STORAGE/cli-master-20240805/build/* /opt/cli-master-20240805/bin/ ) &&
(chmod +x /opt/cli-master-20240805/bin/*) &&
(cd $STORAGE && rm -rf $STORAGE/cli-master-20240805)
) || (
echo "[Caution] Binary: ( /opt/cli-master-20240805/bin/docker ) Already Exists."
)
# ################################ Moby(Docker-CE) - master - 20240803 ###############################
# 编译安装(Make Install) Moby(Docker-CE) - master - 20240803
# --------------------------------------------------
# Git Clone Preparation:
# ----------------------------------------------
# moby-26.1.4/hack/dockerfile/install/containerd.installer:22: git clone https://github.com/containerd/containerd.git "$GOPATH/src/github.com/containerd/containerd"
# moby-26.1.4/hack/dockerfile/install/dockercli.installer:24: git clone https://github.com/docker/docker-ce "$GOPATH/tmp/docker-ce"
# moby-26.1.4/hack/dockerfile/install/runc.installer:18: git clone https://github.com/opencontainers/runc.git "$GOPATH/src/github.com/opencontainers/runc"
# moby-26.1.4/hack/dockerfile/install/tini.installer:10: git clone https://github.com/krallin/tini.git "$GOPATH/tini"
# Error Handle:
# ----------------------------------------------
# cp: 无法获取 'bundles/binary-daemon/docker-init' 的文件状态(stat): No such file or directory
# Makefile:190: recipe for target 'install' failed
export PATH=/opt/go-1.21.11/bin:$ORIGINAL_PATH
export GOPATH=/opt/go-1.21.11
MOBY_VERIFY='n'
MOBY_UNZIPPED=0
MOBY_MADE=0
MOBY_INSTALLED=0
NUMBER_OF_NEW_ADDED_ROWS=0
read -p "[Confirm] Make and Install ( moby(docker-ce)-master-20240803 )? (y/n)>" MOBY_VERIFY
test "$MOBY_VERIFY" != "y" && exit 1
test ! -f "/opt/moby-master-20240803/bin/dockerd" && (
(tar -zxvf $STORAGE/moby-master-20240803.tar.gz && MOBY_UNZIPPED=1) &&
(echo "--------------------------------------------------") &&
(mkdir -p $STORAGE/moby-master-20240803/local_deb_part_01) &&
(mkdir -p $STORAGE/moby-master-20240803/local_deb_part_02) &&
(mkdir -p $STORAGE/moby-master-20240803/local_deb_part_03) &&
(mkdir -p $STORAGE/moby-master-20240803/local_deb_part_04) &&
(mkdir -p $STORAGE/moby-master-20240803/local_deb_part_05) &&
(mkdir -p $STORAGE/moby-master-20240803/local_deb_part_06) &&
(mkdir -p $STORAGE/moby-master-20240803/local_deb_part_07) &&
(mkdir -p $STORAGE/moby-master-20240803/local_deb_part_08) &&
(mkdir -p $STORAGE/moby-master-20240803/local_deb_part_09) &&
(mkdir -p $STORAGE/moby-master-20240803/local_deb_part_10) &&
(mkdir -p $STORAGE/moby-master-20240803/local_deb_part_11) &&
(mkdir -p $STORAGE/moby-master-20240803/local_deb_part_12) &&
(mkdir -p $STORAGE/moby-master-20240803/local_deb_part_13) &&
(mkdir -p $STORAGE/moby-master-20240803/local_deb_part_14) &&
(mkdir -p $STORAGE/moby-master-20240803/local_deb_part_15) &&
(cp -v $STORAGE/deb_for_base_FROM_golang-1.21.12-bookworm/*.deb $STORAGE/moby-master-20240803/local_deb_part_01/) &&
(cp -v $STORAGE/deb_for_criu_FROM_base/*.deb $STORAGE/moby-master-20240803/local_deb_part_02/) &&
(cp -v $STORAGE/deb_for_frozen-images_FROM_debian-bookworm/*.deb $STORAGE/moby-master-20240803/local_deb_part_03/) &&
(cp -v $STORAGE/deb_for_containerd-build_FROM_base/*.deb $STORAGE/moby-master-20240803/local_deb_part_04/) &&
(cp -v $STORAGE/deb_for_runc-build_FROM_base/*.deb $STORAGE/moby-master-20240803/local_deb_part_05/) &&
(cp -v $STORAGE/deb_for_tini-build_FROM_base_apt-get/*.deb $STORAGE/moby-master-20240803/local_deb_part_06/) &&
(cp -v $STORAGE/deb_for_tini-build_FROM_base_xx-apt-get/*.deb $STORAGE/moby-master-20240803/local_deb_part_07/) &&
(cp -v $STORAGE/deb_for_rootlesskit-build_FROM_base/*.deb $STORAGE/moby-master-20240803/local_deb_part_08/) &&
(cp -v $STORAGE/deb_for_crun_FROM_base/*.deb $STORAGE/moby-master-20240803/local_deb_part_09/) &&
(cp -v $STORAGE/deb_for_containerutil-build_FROM_base/*.deb $STORAGE/moby-master-20240803/local_deb_part_10/) &&
(cp -v $STORAGE/deb_for_dev-systemd-true_FROM_dev-systemd-false/*.deb $STORAGE/moby-master-20240803/local_deb_part_11/) &&
(cp -v $STORAGE/deb_for_dev-base_FROM_dev-systemd-false_apt-get-1/*.deb $STORAGE/moby-master-20240803/local_deb_part_12/) &&
(cp -v $STORAGE/deb_for_dev-base_FROM_dev-systemd-false_apt-get-2/*.deb $STORAGE/moby-master-20240803/local_deb_part_13/) &&
(cp -v $STORAGE/deb_for_build_FROM_base_apt-get/*.deb $STORAGE/moby-master-20240803/local_deb_part_14/) &&
(cp -v $STORAGE/deb_for_build_FROM_base_xx-apt-get/*.deb $STORAGE/moby-master-20240803/local_deb_part_15/) &&
(mkdir -p $STORAGE/moby-master-20240803/winres ) &&
(mkdir -p $STORAGE/moby-master-20240803/resize ) &&
(mkdir -p $STORAGE/moby-master-20240803/image ) &&
(mkdir -p $STORAGE/moby-master-20240803/cli ) &&
(mkdir -p $STORAGE/moby-master-20240803/go-md2man ) &&
(mkdir -p $STORAGE/moby-master-20240803/smetrics ) &&
(mkdir -p $STORAGE/moby-master-20240803/blackfriday ) &&
(mkdir -p $STORAGE/moby-master-20240803/go-winres ) &&
(cp -vr $STORAGE/winres-0.2.1/* $STORAGE/moby-master-20240803/winres/ ) &&
(cp -vr $STORAGE/resize-master-20180222/* $STORAGE/moby-master-20240803/resize/ ) &&
(cp -vr $STORAGE/image-master-20240806/* $STORAGE/moby-master-20240803/image/ ) &&
(cp -vr $STORAGE/cli-2.27.4/* $STORAGE/moby-master-20240803/cli/ ) &&
(cp -vr $STORAGE/go-md2man-2.0.4/* $STORAGE/moby-master-20240803/go-md2man/ ) &&
(cp -vr $STORAGE/smetrics-master-20240522/* $STORAGE/moby-master-20240803/smetrics/ ) &&
(cp -vr $STORAGE/blackfriday-2.1.0/* $STORAGE/moby-master-20240803/blackfriday/) &&
(cp -vr $STORAGE/go-winres-0.3.1/* $STORAGE/moby-master-20240803/go-winres/ ) &&
(echo "--------------------------------------------------") &&
(echo "Modify> 1:# syntax=docker/dockerfile:1.7 [ ===> # null ]") &&
(echo " 2:" ) &&
(echo " 3:ARG GO_VERSION=1.21.12" ) &&
(echo " ......" ) &&
(sed -i "1s/.*/# null/" $STORAGE/moby-master-20240803/Dockerfile) &&
(NUMBER_OF_NEW_ADDED_ROWS=0) &&
(echo "--------------------------------------------------") &&
(rm -v $STORAGE/moby-master-20240803/local_deb_part_01/libc6*.deb) &&
(echo "--------------------------------------------------") &&
(echo " 45:COPY --from=xx / /" ) &&
(echo "Insert> RUN sed -i \'s#deb.debian.org#mirrors.aliyun.com#g\' /etc/apt/sources.list.d/debian.sources" ) &&
(echo "Insert> COPY local_deb_part_01/ /tmp/local_deb_part_01/" ) &&
(echo " 46:RUN echo \'Binary::apt::APT::Keep-Downloaded-Packages \"true\";\' > /etc/apt/apt.conf.d/keep-cache") &&
(echo "Delete> 47:RUN apt-get update && apt-get install --no-install-recommends -y file" ) &&
(echo "Insert> 47:RUN dpkg -i /tmp/local_deb_part_01/*.deb" ) &&
(echo " ......" ) &&
(sed -i "46i\RUN sed -i \'s#deb.debian.org#mirrors.aliyun.com#g\' /etc/apt/sources.list.d/debian.sources" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "47i\COPY local_deb_part_01/ /tmp/local_deb_part_01/" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "49d" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "49i\RUN dpkg -i /tmp/local_deb_part_01/*.deb" $STORAGE/moby-master-20240803/Dockerfile) &&
(NUMBER_OF_NEW_ADDED_ROWS=2) &&
(echo "--------------------------------------------------") &&
(echo " 182:ARG GOWINRES_VERSION=v0.3.1" ) &&
(echo "Insert> COPY winres/ /usr/local/go/src/github.com/tc-hib/winres/" ) &&
(echo "Insert> COPY resize/ /usr/local/go/src/github.com/nfnt/resize/" ) &&
(echo "Insert> COPY image/ /usr/local/go/src/golang.org/x/image/" ) &&
(echo "Insert> COPY cli/ /usr/local/go/src/github.com/urfave/cli/v2/" ) &&
(echo "Insert> COPY go-md2man/ /usr/local/go/src/github.com/cpuguy83/go-md2man/v2/" ) &&
(echo "Insert> COPY smetrics/ /usr/local/go/src/github.com/xrash/smetrics/" ) &&
(echo "Insert> COPY blackfriday/ /usr/local/go/src/github.com/russross/blackfriday/v2/" ) &&
(echo "Insert> COPY go-winres/ /usr/local/go/src/github.com/tc-hib/go-winres/" ) &&
(echo "Insert> WORKDIR /usr/local/go" ) &&
(echo " 183:RUN --mount=type=cache,target=/root/.cache/go-build \\" ) &&
(echo " 184: --mount=type=cache,target=/go/pkg/mod \\" ) &&
(echo "Delete> 185: GOBIN=/build/ GO111MODULE=on go install \"github.com/tc-hib/go-winres@\${GOWINRES_VERSION}\" \\" ) &&
(echo "Insert> 185: GOBIN=/build/ GO111MODULE=on go install ./src/github.com/tc-hib/go-winres && /usr/local/go/bin/go-winres --help" ) &&
(echo "Modify> 186: && /build/go-winres --help [ ===> # null ]" ) &&
(sed -i "185i\COPY winres/ /usr/local/go/src/github.com/tc-hib/winres/" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "186i\COPY resize/ /usr/local/go/src/github.com/nfnt/resize/" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "187i\COPY image/ /usr/local/go/src/golang.org/x/image/" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "188i\COPY cli/ /usr/local/go/src/github.com/urfave/cli/v2/" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "189i\COPY go-md2man/ /usr/local/go/src/github.com/cpuguy83/go-md2man/v2/" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "190i\COPY smetrics/ /usr/local/go/src/github.com/xrash/smetrics/" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "191i\COPY blackfriday/ /usr/local/go/src/github.com/russross/blackfriday/v2/" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "192i\COPY go-winres/ /usr/local/go/src/github.com/tc-hib/go-winres/" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "193i\WORKDIR /usr/local/go" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "196d" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "196i\ GOBIN=/build/ GO111MODULE=off go install ./src/github.com/tc-hib/go-winres && /usr/local/go/bin/go-winres --help" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "197s/.*/# null/" $STORAGE/moby-master-20240803/Dockerfile) &&
(NUMBER_OF_NEW_ADDED_ROWS=11) &&
(echo "--------------------------------------------------") &&
(echo " 571:FROM base AS build" ) &&
(echo "Delete> 572:COPY --from=gowinres /build/ /usr/local/bin/" ) &&
(echo "Insert> 572:COPY --from=gowinres /usr/local/go/bin/ /usr/local/bin/" ) &&
(echo " 573:WORKDIR /go/src/github.com/docker/docker" ) &&
(echo " ......" ) &&
(sed -i "583d" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "583i\COPY --from=gowinres /usr/local/go/bin/ /usr/local/bin/" $STORAGE/moby-master-20240803/Dockerfile) &&
(NUMBER_OF_NEW_ADDED_ROWS=11) &&
(echo "--------------------------------------------------") &&
(rm -v $STORAGE/moby-master-20240803/local_deb_part_14/libc6*.deb) &&
(rm -v $STORAGE/moby-master-20240803/local_deb_part_14/libc-dev-bin*.deb) &&
(rm -v $STORAGE/moby-master-20240803/local_deb_part_15/libc6*.deb) &&
(rm -v $STORAGE/moby-master-20240803/local_deb_part_15/libc-dev-bin*.deb) &&
(echo "--------------------------------------------------") &&
(echo " 575:ENV CGO_ENABLED=1" ) &&
(echo "Insert> RUN sed -i \'s#deb.debian.org#mirrors.aliyun.com#g\' /etc/apt/sources.list.d/debian.sources") &&
(echo "Insert> COPY local_deb_part_14/ /tmp/local_deb_part_14/" ) &&
(echo " 576:RUN --mount=type=cache,sharing=locked,id=moby-build-aptlib,target=/var/lib/apt \\" ) &&
(echo " 577: --mount=type=cache,sharing=locked,id=moby-build-aptcache,target=/var/cache/apt \\" ) &&
(echo "Delete> 578: apt-get update && apt-get install --no-install-recommends -y \\" ) &&
(echo "Insert> 578: dpkg -i /tmp/local_deb_part_14/*.deb" ) &&
(echo "Modify> 579: clang \\ [ ===> # null ]" ) &&
(echo "Modify> 580: lld \\ [ ===> # null ]" ) &&
(echo "Modify> 581: llvm [ ===> # null ]" ) &&
(echo " 582:ARG TARGETPLATFORM" ) &&
(echo "Insert> COPY local_deb_part_15/ /tmp/local_deb_part_15/" ) &&
(echo " 583:RUN --mount=type=cache,sharing=locked,id=moby-build-aptlib,target=/var/lib/apt \\" ) &&
(echo " 584: --mount=type=cache,sharing=locked,id=moby-build-aptcache,target=/var/cache/apt \\" ) &&
(echo "Delete> 585: xx-apt-get install --no-install-recommends -y \\" ) &&
(echo "Insert> 585: xx-apt-get install --no-install-recommends -y /tmp/local_deb_part_15/*.deb" ) &&
(echo "Modify> 586: dpkg-dev \\ [ ===> # null ]" ) &&
(echo "Modify> 587: gcc \\ [ ===> # null ]" ) &&
(echo "Modify> 588: libapparmor-dev \\ [ ===> # null ]" ) &&
(echo "Modify> 589: libc6-dev \\ [ ===> # null ]" ) &&
(echo "Modify> 590: libseccomp-dev \\ [ ===> # null ]" ) &&
(echo "Modify> 591: libsecret-1-dev \\ [ ===> # null ]" ) &&
(echo "Modify> 592: libsystemd-dev \\ [ ===> # null ]" ) &&
(echo "Modify> 593: libudev-dev \\ [ ===> # null ]" ) &&
(echo "Modify> 594: pkg-config [ ===> # null ]" ) &&
(echo " 595:ARG DOCKER_BUILDTAGS" ) &&
(echo " ......" ) &&
(sed -i "587i\RUN sed -i \'s#deb.debian.org#mirrors.aliyun.com#g\' /etc/apt/sources.list.d/debian.sources" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "588i\COPY local_deb_part_14/ /tmp/local_deb_part_14/" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "591d" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "591i\ dpkg -i /tmp/local_deb_part_14/*.deb" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "592,594s/.*/# null/" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "596i\COPY local_deb_part_15/ /tmp/local_deb_part_15/" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "599d" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "599i\ xx-apt-get install --no-install-recommends -y /tmp/local_deb_part_15/*.deb" $STORAGE/moby-master-20240803/Dockerfile) &&
(sed -i "600,608s/.*/# null/" $STORAGE/moby-master-20240803/Dockerfile) &&
(NUMBER_OF_NEW_ADDED_ROWS=14) &&
(echo "--------------------------------------------------") &&
(echo "# Compilation Method for \"moby(docker-ce)\":" ) &&
(echo "# ----- Compile in Docker Environment: \$ cd ./moby-master-20240803 && make binary" ) &&
(echo "# - Compile in Non Docker Environment: \$ cd ./moby-master-20240803 && hack/make.sh binary") &&
(echo "--------------------------------------------------") &&
(echo "Because \"-mod=vendor\" is Used, Only The \"vendor\" in The Local Source Code Directory is Searched for Dependencies:") &&
(echo "Handing: $STORAGE/moby-master-20240803/vendor/github.com/docker/docker" && mkdir -p $STORAGE/moby-master-20240803/vendor/github.com/docker/docker/) &&
(echo "Copying: $STORAGE/moby-master-20240803/image" && cp -r $STORAGE/moby-master-20240803/image $STORAGE/moby-master-20240803/vendor/github.com/docker/docker/) &&
(echo "--------------------------------------------------") &&
(cd $STORAGE/moby-master-20240803 && make binary && MOBY_MADE=1) &&
(mkdir -p /opt/moby-master-20240803/bin ) &&
(cp -v $STORAGE/moby-master-20240803/bundles/binary/* /opt/moby-master-20240803/bin/ ) &&
(chmod +x /opt/moby-master-20240803/bin/*) &&
(cd $STORAGE/moby-master-20240803) # && make install MOBY_INSTALLED=1
) || (
echo "[Caution] Binary: ( /opt/moby-master-20240803/bin/dockerd ) Already Exists."
)
总结
以上就是关于 Linux运维 Bash脚本 源码编译Moby(Docker-CE)-20240803 的全部内容。
更多内容可以访问我的代码仓库: