From 32e41f662e65784e1b9519ce281d659d468f01fd Mon Sep 17 00:00:00 2001 From: FreddieOliveira Date: Sat, 23 Jan 2021 22:01:06 -0300 Subject: [PATCH] Build all docker suit together --- root-packages/docker/build.sh | 112 ++++++++++++++++++ root-packages/docker/config.go.patch | 24 ++++ root-packages/{dockerd => docker}/daemon.json | 0 root-packages/docker/database.go.patch | 17 +++ root-packages/{dockerd => docker}/dockerd | 4 +- root-packages/docker/generate-man.sh.patch | 20 ++++ root-packages/docker/md2man-all.sh.patch | 11 ++ root-packages/dockerd/build.sh | 33 ------ 8 files changed, 186 insertions(+), 35 deletions(-) create mode 100644 root-packages/docker/build.sh create mode 100644 root-packages/docker/config.go.patch rename root-packages/{dockerd => docker}/daemon.json (100%) create mode 100644 root-packages/docker/database.go.patch rename root-packages/{dockerd => docker}/dockerd (92%) create mode 100644 root-packages/docker/generate-man.sh.patch create mode 100644 root-packages/docker/md2man-all.sh.patch delete mode 100644 root-packages/dockerd/build.sh diff --git a/root-packages/docker/build.sh b/root-packages/docker/build.sh new file mode 100644 index 000000000..ae9f9eced --- /dev/null +++ b/root-packages/docker/build.sh @@ -0,0 +1,112 @@ +TERMUX_PKG_HOMEPAGE=https://docker.com +TERMUX_PKG_DESCRIPTION="Set of products that use OS-level virtualization to deliver software in packages called containers." +TERMUX_PKG_LICENSE="Apache-2.0" +TERMUX_PKG_MAINTAINER="@termux" +# remember to update DOCKER_GITCOMMIT inside termux_step_make() +# bellow when upgrading to a new version +TERMUX_PKG_VERSION=20.10.2 +LIBNETWORK_COMMIT=448016ef11309bd67541dcf4d72f1f5b7de94862 +TERMUX_PKG_SRCURL="https://github.com/moby/moby/archive/v${TERMUX_PKG_VERSION}.tar.gz \ + https://github.com/docker/cli/archive/v${TERMUX_PKG_VERSION}.tar.gz \ + https://github.com/moby/libnetwork/archive/${LIBNETWORK_COMMIT}.tar.gz" +TERMUX_PKG_SHA256="dc4818f0cba2ded2f6f7420a1fda027ddbf6c6c9fe319f84d1311bfe610447ca \ + a663f54a158c6b2b23b253b14bf0de56ff035750098e760319de1edb7f4ae76d \ + 6609469024e9244cc1b9e2f023b29de04d0ab281a483ac83cfdf45d1cf9ce71e" +TERMUX_PKG_DEPENDS="containerd" +TERMUX_PKG_CONFFILES="etc/docker/daemon.json" +TERMUX_PKG_BUILD_IN_SRC=true +TERMUX_PKG_SKIP_SRC_EXTRACT=true + +termux_step_get_source() { + local PKG_SRCURL=(${TERMUX_PKG_SRCURL[@]}) + local PKG_SHA256=(${TERMUX_PKG_SHA256[@]}) + + if [ ! ${#PKG_SRCURL[@]} == ${#PKG_SHA256[@]} ]; then + termux_error_exit "Error: length of TERMUX_PKG_SRCURL isn't equal to length of TERMUX_PKG_SHA256." + fi + + # download and extract packages into its own folder inside $TERMUX_PKG_SRCDIR + mkdir -p $TERMUX_PKG_CACHEDIR + for i in $(seq 0 $(( ${#PKG_SRCURL[@]} - 1 ))); do + local file="${TERMUX_PKG_CACHEDIR}/$(basename ${PKG_SRCURL[$i]})" + rm -rf "$file" + termux_download "${PKG_SRCURL[$i]}" "$file" "${PKG_SHA256[$i]}" + tar xf "$file" -C "$TERMUX_PKG_SRCDIR" + done + + # delete trailing -$TERMUX_PKG_VERSION from folder name + # so patches become portable across different versions + cd "$TERMUX_PKG_SRCDIR" + for folder in $(ls); do + if [ ! $folder == ${folder%%-*} ]; then + mv $folder ${folder%%-*} + fi + done +} + +termux_step_make() { + # setup go build environment + termux_setup_golang + + # BUILD DOCKERD DAEMON + echo -n "Building dockerd daemon..." + ( + set -e + cd moby + + # apply some patches in a batch + xargs sed -i "s_\(/etc/docker\)_${TERMUX_PREFIX}\1_g" < <(grep -R /etc/docker | cut -d':' -f1 | sort | uniq) + xargs sed -i 's/[a-zA-Z0-9]*\.GOOS/"linux"/g' < <(grep -R '[a-zA-Z0-9]*\.GOOS' | cut -d':' -f1 | sort | uniq) + + # issue the build command + export DOCKER_GITCOMMIT=8891c58a43 + export DOCKER_BUILDTAGS='exclude_graphdriver_btrfs exclude_graphdriver_devicemapper exclude_graphdriver_quota selinux exclude_graphdriver_aufs' + # horrible, but effective way to apply patches on the fly while compiling + while ! IFS='' files=$(AUTO_GOPATH=1 PREFIX='' hack/make.sh dynbinary 2>&1 1>/dev/null); do if ! xargs sed -i 's/\("runtime"\)/_ \1/' < <(echo $files | grep runtime | cut -d':' -f1 | cut -c38-); then echo $files; exit 1; fi; done + ) + echo " Done!" + + # BUILD DOCKER-PROXY BINARY FROM LIBNETWORK + echo -n "Building docker-proxy from libnetwork..." + ( + set -e + export GOPATH="${PWD}" + cd libnetwork + go build -o docker-proxy github.com/docker/libnetwork/cmd/proxy + ) + echo " Done!" + + # BUILD DOCKER-CLI CLIENT + echo -n "Building docker-cli client..." + ( + set -e + mkdir -p go/src/github.com/docker + mv cli go/src/github.com/docker + mkdir cli + mv go cli + export GOPATH="${PWD}/cli/go" + cd "${GOPATH}/src/github.com/docker/cli" + + # apply some patches in a batch + xargs sed -i 's_/var/\(run/docker\.sock\)_/data/docker/\1_g' < <(grep -R /var/run/docker\.sock | cut -d':' -f1 | sort | uniq) + + # issue the build command + export VERSION=v${TERMUX_PKG_VERSION}-ce + export DISABLE_WARN_OUTSIDE_CONTAINER=1 + make -j ${TERMUX_MAKE_PROCESSES} dynbinary + unset GOOS GOARCH CGO_LDFLAGS CC CXX CFLAGS CXXFLAGS LDFLAGS + make -j ${TERMUX_MAKE_PROCESSES} manpages + ) + echo " Done!" +} + +termux_step_make_install() { + install -Dm 0700 moby/bundles/dynbinary-daemon/dockerd ${TERMUX_PREFIX}/libexec/dockerd + install -Dm 0700 libnetwork/docker-proxy ${TERMUX_PREFIX}/bin/docker-proxy + install -Dm 0700 cli/go/src/github.com/docker/cli/build/docker-android-* ${TERMUX_PREFIX}/bin/docker + install -Dm 600 -t ${TERMUX_PREFIX}/share/man/man1 cli/go/src/github.com/docker/cli/man/man1/* + install -Dm 600 -t ${TERMUX_PREFIX}/share/man/man5 cli/go/src/github.com/docker/cli/man/man5/* + install -Dm 600 -t ${TERMUX_PREFIX}/share/man/man8 cli/go/src/github.com/docker/cli/man/man8/* + install -Dm 0700 ${TERMUX_PKG_BUILDER_DIR}/dockerd ${TERMUX_PREFIX}/bin/dockerd + install -Dm 600 ${TERMUX_PKG_BUILDER_DIR}/daemon.json ${TERMUX_PREFIX}/etc/docker/daemon.json +} diff --git a/root-packages/docker/config.go.patch b/root-packages/docker/config.go.patch new file mode 100644 index 000000000..63cf5f37e --- /dev/null +++ b/root-packages/docker/config.go.patch @@ -0,0 +1,24 @@ +diff --git a/data/data/com.termux/files/home/test/cli-20.10.1/cli/config/config.go b/cli/config/config.go +index 703fa30..893ff58 100644 +--- a/data/data/com.termux/files/home/test/cli-20.10.1/cli/config/config.go ++++ b/cli/config/config.go +@@ -11,7 +11,6 @@ import ( + "github.com/docker/cli/cli/config/configfile" + "github.com/docker/cli/cli/config/credentials" + "github.com/docker/cli/cli/config/types" +- "github.com/docker/docker/pkg/homedir" + "github.com/pkg/errors" + ) + +@@ -32,10 +31,7 @@ func setConfigDir() { + if configDir != "" { + return + } +- configDir = os.Getenv("DOCKER_CONFIG") +- if configDir == "" { +- configDir = filepath.Join(homedir.Get(), configFileDir) +- } ++ configDir = "/data/data/com.termux/files/home/.docker" + } + + // Dir returns the directory the configuration file is stored in diff --git a/root-packages/dockerd/daemon.json b/root-packages/docker/daemon.json similarity index 100% rename from root-packages/dockerd/daemon.json rename to root-packages/docker/daemon.json diff --git a/root-packages/docker/database.go.patch b/root-packages/docker/database.go.patch new file mode 100644 index 000000000..bd53b40b7 --- /dev/null +++ b/root-packages/docker/database.go.patch @@ -0,0 +1,17 @@ +diff --git a/cli-20.10.1/vendor/github.com/containerd/containerd/platforms/database.go b/cli/vendor/github.com/containerd/containerd/platforms/database.go +index 6ede940..d010005 100644 +--- a/cli-20.10.1/vendor/github.com/containerd/containerd/platforms/database.go ++++ b/cli/vendor/github.com/containerd/containerd/platforms/database.go +@@ -25,7 +25,11 @@ import ( + // + // The OS value should be normalized before calling this function. + func isLinuxOS(os string) bool { +- return os == "linux" ++ switch os { ++ case "linux", "android": ++ return true ++ } ++ return false + } + + // These function are generated from https://golang.org/src/go/build/syslist.go. diff --git a/root-packages/dockerd/dockerd b/root-packages/docker/dockerd similarity index 92% rename from root-packages/dockerd/dockerd rename to root-packages/docker/dockerd index 858bd7c3d..5e72f53f6 100755 --- a/root-packages/dockerd/dockerd +++ b/root-packages/docker/dockerd @@ -1,4 +1,4 @@ -#!/data/data/com.termux/files/usr/bin/bash +#!@TERMUX_PREFIX@/bin/bash export PATH="${PATH}:/system/xbin:/system/bin" opts='rw,nosuid,nodev,noexec,relatime' @@ -26,4 +26,4 @@ for cg in ${cgroups}; do done # start the docker daemon -"${PREFIX}/bin/dockerd-dev" $@ +"@TERMUX_PREFIX@/libexec/dockerd" $@ diff --git a/root-packages/docker/generate-man.sh.patch b/root-packages/docker/generate-man.sh.patch new file mode 100644 index 000000000..055034402 --- /dev/null +++ b/root-packages/docker/generate-man.sh.patch @@ -0,0 +1,20 @@ +diff --git a/cli-20.10.1/scripts/docs/generate-man.sh b/cli/scripts/docs/generate-man.sh +index 136ed1e..339ee3b 100755 +--- a/cli-20.10.1/scripts/docs/generate-man.sh ++++ b/cli/scripts/docs/generate-man.sh +@@ -6,12 +6,12 @@ mkdir -p ./man/man1 + + if ! command -v md2man &> /dev/null; then + # yay, go install creates a binary named "v2" ¯\_(ツ)_/¯ +- go build -o "/go/bin/md2man" ./vendor/github.com/cpuguy83/go-md2man/v2 ++ go build -o "build/md2man" ./vendor/github.com/cpuguy83/go-md2man/v2 + fi + + # Generate man pages from cobra commands +-go build -o /tmp/gen-manpages github.com/docker/cli/man +-/tmp/gen-manpages --root "$(pwd)" --target "$(pwd)/man/man1" ++go build -o build/gen-manpages github.com/docker/cli/man ++build/gen-manpages --root "$(pwd)" --target "$(pwd)/man/man1" + + # Generate legacy pages from markdown + ./man/md2man-all.sh -q diff --git a/root-packages/docker/md2man-all.sh.patch b/root-packages/docker/md2man-all.sh.patch new file mode 100644 index 000000000..d41d63f0b --- /dev/null +++ b/root-packages/docker/md2man-all.sh.patch @@ -0,0 +1,11 @@ +diff --git a/cli-20.10.1/man/md2man-all.sh b/cli/man/md2man-all.sh +index eb0bc63..f8b9a5e 100755 +--- a/cli-20.10.1/man/md2man-all.sh ++++ b/cli/man/md2man-all.sh +@@ -18,5 +18,5 @@ for FILE in *.md; do + continue + fi + mkdir -p "./man${num}" +- md2man -in "$FILE" -out "./man${num}/${name}" ++ ../build/md2man -in "$FILE" -out "./man${num}/${name}" + done diff --git a/root-packages/dockerd/build.sh b/root-packages/dockerd/build.sh deleted file mode 100644 index f65556013..000000000 --- a/root-packages/dockerd/build.sh +++ /dev/null @@ -1,33 +0,0 @@ -TERMUX_PKG_HOMEPAGE=https://docs.docker.com/engine/ -TERMUX_PKG_DESCRIPTION="Server daemon process for building and containerizing applications." -TERMUX_PKG_LICENSE="Apache-2.0" -TERMUX_PKG_MAINTAINER="@termux" -# remember to update DOCKER_GITCOMMIT inside termux_step_make() -# bellow when upgrading to a new version -TERMUX_PKG_VERSION=20.10.2 -TERMUX_PKG_SRCURL=https://github.com/moby/moby/archive/v${TERMUX_PKG_VERSION}.tar.gz -TERMUX_PKG_SHA256=dc4818f0cba2ded2f6f7420a1fda027ddbf6c6c9fe319f84d1311bfe610447ca -TERMUX_PKG_DEPENDS="containerd" -TERMUX_PKG_CONFFILES="etc/docker/daemon.json" -TERMUX_PKG_BUILD_IN_SRC=true - -termux_step_make() { - # setup go build environment - termux_setup_golang - - # apply some patches in a batch - xargs sed -i "s_\(/etc/docker\)_${TERMUX_PREFIX}\1_g" < <(grep -R /etc/docker | cut -d':' -f1 | sort | uniq) - xargs sed -i 's/[a-zA-Z0-9]*\.GOOS/"linux"/g' < <(grep -R '[a-zA-Z0-9]*\.GOOS' | cut -d':' -f1 | sort | uniq) - - # issue the build command - export DOCKER_GITCOMMIT=8891c58a43 - export DOCKER_BUILDTAGS='exclude_graphdriver_btrfs exclude_graphdriver_devicemapper exclude_graphdriver_quota selinux exclude_graphdriver_aufs' - # horrible, but effective way to apply patches on the fly while compiling - (while ! IFS='' files=$(AUTO_GOPATH=1 PREFIX='' hack/make.sh dynbinary 2>&1 1>/dev/null); do if ! xargs sed -i 's/\("runtime"\)/_ \1/' < <(echo $files | grep runtime | cut -d':' -f1 | cut -c38-); then echo $files; exit 1; fi; done) -} - -termux_step_make_install() { - install -Dm 0700 bundles/dynbinary-daemon/dockerd-dev ${TERMUX_PREFIX}/bin/dockerd-dev - install -Dm 0700 ${TERMUX_PKG_BUILDER_DIR}/dockerd ${TERMUX_PREFIX}/bin/dockerd - install -Dm 0700 ${TERMUX_PKG_BUILDER_DIR}/daemon.json ${TERMUX_PREFIX}/etc/docker/daemon.json -}