github.com/sijibomii/docker@v0.0.0-20231230191044-5cf6ca554647/hack/make/build-deb (about)

     1  #!/bin/bash
     2  set -e
     3  
     4  # subshell so that we can export PATH and TZ without breaking other things
     5  (
     6  	export TZ=UTC # make sure our "date" variables are UTC-based
     7  	bundle .integration-daemon-start
     8  	bundle .detect-daemon-osarch
     9  
    10  	# TODO consider using frozen images for the dockercore/builder-deb tags
    11  
    12  	tilde='~' # ouch Bash 4.2 vs 4.3, you keel me
    13  	debVersion="${VERSION//-/$tilde}" # using \~ or '~' here works in 4.3, but not 4.2; just ~ causes $HOME to be inserted, hence the $tilde
    14  	# if we have a "-dev" suffix or have change in Git, let's make this package version more complex so it works better
    15  	if [[ "$VERSION" == *-dev ]] || [ -n "$(git status --porcelain)" ]; then
    16  		gitUnix="$(git log -1 --pretty='%at')"
    17  		gitDate="$(date --date "@$gitUnix" +'%Y%m%d.%H%M%S')"
    18  		gitCommit="$(git log -1 --pretty='%h')"
    19  		gitVersion="git${gitDate}.0.${gitCommit}"
    20  		# gitVersion is now something like 'git20150128.112847.0.17e840a'
    21  		debVersion="$debVersion~$gitVersion"
    22  
    23  		# $ dpkg --compare-versions 1.5.0 gt 1.5.0~rc1 && echo true || echo false
    24  		# true
    25  		# $ dpkg --compare-versions 1.5.0~rc1 gt 1.5.0~git20150128.112847.17e840a && echo true || echo false
    26  		# true
    27  		# $ dpkg --compare-versions 1.5.0~git20150128.112847.17e840a gt 1.5.0~dev~git20150128.112847.17e840a && echo true || echo false
    28  		# true
    29  
    30  		# ie, 1.5.0 > 1.5.0~rc1 > 1.5.0~git20150128.112847.17e840a > 1.5.0~dev~git20150128.112847.17e840a
    31  	fi
    32  
    33  	debSource="$(awk -F ': ' '$1 == "Source" { print $2; exit }' hack/make/.build-deb/control)"
    34  	debMaintainer="$(awk -F ': ' '$1 == "Maintainer" { print $2; exit }' hack/make/.build-deb/control)"
    35  	debDate="$(date --rfc-2822)"
    36  
    37  	# if go-md2man is available, pre-generate the man pages
    38  	./man/md2man-all.sh -q || true
    39  	# TODO decide if it's worth getting go-md2man in _each_ builder environment to avoid this
    40  
    41  	builderDir="contrib/builder/deb/${PACKAGE_ARCH}"
    42  	pkgs=( $(find "${builderDir}/"*/ -type d) )
    43  	if [ ! -z "$DOCKER_BUILD_PKGS" ]; then
    44  		pkgs=( $(echo ${DOCKER_BUILD_PKGS[@]/#/$builderDir\/}) )
    45  	fi
    46  	for dir in "${pkgs[@]}"; do
    47  		[ -d "$dir" ] || { echo >&2 "skipping nonexistent $dir"; continue; }
    48  		version="$(basename "$dir")"
    49  		suite="${version##*-}"
    50  
    51  		image="dockercore/builder-deb:$version"
    52  		if ! docker inspect "$image" &> /dev/null; then
    53  			( set -x && docker build ${DOCKER_BUILD_ARGS} -t "$image" "$dir" )
    54  		fi
    55  
    56  		mkdir -p "$DEST/$version"
    57  		cat > "$DEST/$version/Dockerfile.build" <<-EOF
    58  			FROM $image
    59  			WORKDIR /usr/src/docker
    60  			COPY . /usr/src/docker
    61  			RUN mkdir -p /go/src/github.com/docker && mkdir -p /go/src/github.com/opencontainers \
    62  				&& ln -snf /usr/src/docker /go/src/github.com/docker/docker
    63  		EOF
    64  
    65  		# get the RUNC and CONTAINERD commit from the root Dockerfile, this keeps the commits in sync
    66  		awk '$1 == "ENV" && $2 == "RUNC_COMMIT" { print; exit }' Dockerfile >> "$DEST/$version/Dockerfile.build"
    67  		awk '$1 == "ENV" && $2 == "CONTAINERD_COMMIT" { print; exit }' Dockerfile >> "$DEST/$version/Dockerfile.build"
    68  
    69  		# add runc and containerd compile and install
    70  		cat >> "$DEST/$version/Dockerfile.build" <<-EOF
    71  			# Install runc
    72  			RUN git clone https://github.com/opencontainers/runc.git "/go/src/github.com/opencontainers/runc" \
    73  					&& cd "/go/src/github.com/opencontainers/runc" \
    74  					&& git checkout -q "\$RUNC_COMMIT"
    75  			RUN set -x && export GOPATH="/go" && cd "/go/src/github.com/opencontainers/runc" \
    76  					&& make BUILDTAGS="\$RUNC_BUILDTAGS" && make install
    77  			# Install containerd
    78  			RUN git clone https://github.com/docker/containerd.git "/go/src/github.com/docker/containerd" \
    79  					&& cd "/go/src/github.com/docker/containerd" \
    80  					&& git checkout -q "\$CONTAINERD_COMMIT"
    81  			RUN set -x && export GOPATH="/go" && cd "/go/src/github.com/docker/containerd" && make && make install
    82  		EOF
    83  		if [ "$DOCKER_EXPERIMENTAL" ]; then
    84  			echo 'ENV DOCKER_EXPERIMENTAL 1' >> "$DEST/$version/Dockerfile.build"
    85  		fi
    86  		cat >> "$DEST/$version/Dockerfile.build" <<-EOF
    87  			RUN cp -aL hack/make/.build-deb debian
    88  			RUN { echo '$debSource (${debVersion}-0~${suite}) $suite; urgency=low'; echo; echo '  * Version: $VERSION'; echo; echo " -- $debMaintainer  $debDate"; } > debian/changelog && cat >&2 debian/changelog
    89  		EOF
    90  		# Remove the following case-based substitution when none of these are supported, and the TasksMax value is uncommented in docker.service
    91  		case "$version" in
    92  		debian-jessie|debian-wheezy|ubuntu-precise|ubuntu-trusty|ubuntu-wily)
    93  			;;
    94  		*)
    95  			echo "RUN sed -i -- 's/#TasksMax=infinity/TasksMax=infinity/' contrib/init/systemd/docker.service" >> "$DEST/$version/Dockerfile.build"
    96  			;;
    97  		esac
    98  		cat >> "$DEST/$version/Dockerfile.build" <<-EOF
    99  			RUN dpkg-buildpackage -uc -us
   100  		EOF
   101  		tempImage="docker-temp/build-deb:$version"
   102  		( set -x && docker build -t "$tempImage" -f "$DEST/$version/Dockerfile.build" . )
   103  		docker run --rm "$tempImage" bash -c 'cd .. && tar -c *_*' | tar -xvC "$DEST/$version"
   104  		docker rmi "$tempImage"
   105  	done
   106  
   107  	bundle .integration-daemon-stop
   108  ) 2>&1 | tee -a "$DEST/test.log"