From d66f7a68c9cf5ecb42d7aa66c22287ea5f0241c3 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 3 Jul 2021 13:01:16 +0200 Subject: [PATCH 1/3] deb: add docker-compose-plugin package Adds a deb package for the docker-compose cli plugin with this: dpkg -i ./docker-ce-cli_0.0.0-20210629140245-4a6fe51-0~ubuntu-focal_amd64.deb dpkg -i ./docker-compose-plugin_2.3.1.3~ubuntu-focal_amd64.deb docker info --format '{{json .ClientInfo.Plugins}}' | jq . [ { "SchemaVersion": "0.1.0", "Vendor": "Docker Inc.", "Version": "v0.5.1-docker", "ShortDescription": "Build with BuildKit", "Name": "buildx", "Path": "/usr/libexec/docker/cli-plugins/docker-buildx" }, { "SchemaVersion": "0.1.0", "Vendor": "Docker Inc.", "Version": "v2.3.1", "ShortDescription": "Docker Compose", "Name": "compose", "Path": "/usr/libexec/docker/cli-plugins/docker-compose" } ] Signed-off-by: Sebastiaan van Stijn --- Makefile | 12 ++++++++++-- common.mk | 8 +++++--- deb/Makefile | 11 ++++++++++- deb/build-deb | 3 +++ deb/common/control | 12 ++++++++++++ deb/common/rules | 19 +++++++++++++++++++ 6 files changed, 59 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 52377ad84b..1241a6de3d 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ clean-src: $(RM) -r src .PHONY: src -src: src/github.com/docker/cli src/github.com/docker/docker src/github.com/docker/scan-cli-plugin ## clone source +src: src/github.com/docker/cli src/github.com/docker/docker src/github.com/docker/compose src/github.com/docker/scan-cli-plugin ## clone source ifdef CLI_DIR src/github.com/docker/cli: @@ -37,6 +37,10 @@ src/github.com/docker/docker: git -C $@ remote add origin "$(DOCKER_ENGINE_REPO)" endif +src/github.com/docker/compose: + git init $@ + git -C $@ remote add origin "$(DOCKER_COMPOSE_REPO)" + src/github.com/docker/scan-cli-plugin: git init $@ git -C $@ remote add origin "$(DOCKER_SCAN_REPO)" @@ -50,12 +54,16 @@ checkout-cli: src/github.com/docker/cli checkout-docker: src/github.com/docker/docker ./scripts/checkout.sh src/github.com/docker/docker "$(DOCKER_ENGINE_REF)" +.PHONY: checkout-compose +checkout-compose: src/github.com/docker/compose + ./scripts/checkout.sh src/github.com/docker/compose "$(DOCKER_COMPOSE_REF)" + .PHONY: checkout-scan-cli-plugin checkout-scan-cli-plugin: src/github.com/docker/scan-cli-plugin ./scripts/checkout.sh src/github.com/docker/scan-cli-plugin "$(DOCKER_SCAN_REF)" .PHONY: checkout -checkout: checkout-cli checkout-docker checkout-scan-cli-plugin ## checkout source at the given reference(s) +checkout: checkout-cli checkout-docker checkout-compose checkout-scan-cli-plugin ## checkout source at the given reference(s) .PHONY: clean clean: clean-src ## remove build artifacts diff --git a/common.mk b/common.mk index 57dd1ffb31..1e27adc32f 100644 --- a/common.mk +++ b/common.mk @@ -23,9 +23,10 @@ VERSION?=0.0.1-dev # DOCKER_CLI_REPO and DOCKER_ENGINE_REPO define the source repositories to clone # the source from. These can be overridden to build from a fork. -DOCKER_CLI_REPO ?= https://github.com/docker/cli.git -DOCKER_ENGINE_REPO ?= https://github.com/docker/docker.git -DOCKER_SCAN_REPO ?= https://github.com/docker/scan-cli-plugin.git +DOCKER_CLI_REPO ?= https://github.com/docker/cli.git +DOCKER_ENGINE_REPO ?= https://github.com/docker/docker.git +DOCKER_SCAN_REPO ?= https://github.com/docker/scan-cli-plugin.git +DOCKER_COMPOSE_REPO ?= https://github.com/docker/compose.git # REF can be used to specify the same branch or tag to use for *both* the CLI # and Engine source code. This can be useful if both the CLI and Engine have a @@ -37,6 +38,7 @@ REF ?= HEAD DOCKER_CLI_REF ?= $(REF) DOCKER_ENGINE_REF ?= $(REF) DOCKER_SCAN_REF ?= v0.17.0 +DOCKER_COMPOSE_REF ?= v2.3.1 export BUILDTIME export DEFAULT_PRODUCT_LICENSE diff --git a/deb/Makefile b/deb/Makefile index a27310b513..652ebe5525 100644 --- a/deb/Makefile +++ b/deb/Makefile @@ -33,6 +33,7 @@ RUN?=docker run --rm \ -e VERSION=$(word 2, $(GEN_DEB_VER)) \ -e CLI_GITCOMMIT=$(CLI_GITCOMMIT) \ -e ENGINE_GITCOMMIT=$(ENGINE_GITCOMMIT) \ + -e COMPOSE_VERSION=$(DOCKER_COMPOSE_REF) \ -e SCAN_VERSION=$(DOCKER_SCAN_REF) \ -e SCAN_GITCOMMIT=$(SCAN_GITCOMMIT) \ -v $(CURDIR)/debbuild/$@:/build \ @@ -77,7 +78,7 @@ $(DISTROS): sources $(CHOWN) -R $(shell id -u):$(shell id -g) "debbuild/$@" .PHONY: sources -sources: sources/cli.tgz sources/engine.tgz sources/scan-cli-plugin.tgz sources/plugin-installers.tgz +sources: sources/cli.tgz sources/engine.tgz sources/compose.tgz sources/scan-cli-plugin.tgz sources/plugin-installers.tgz sources/engine.tgz: mkdir -p $(@D) @@ -95,6 +96,14 @@ sources/cli.tgz: alpine \ tar -C / -c -z -f /v/cli.tgz --exclude .git cli +sources/compose.tgz: + mkdir -p $(@D) + docker run --rm -w /v \ + -v $(realpath $(CURDIR)/../src/github.com/docker/compose):/compose \ + -v $(CURDIR)/$(@D):/v \ + alpine \ + tar -C / -c -z -f /v/compose.tgz --exclude .git compose + sources/scan-cli-plugin.tgz: mkdir -p $(@D) docker run --rm -w /v \ diff --git a/deb/build-deb b/deb/build-deb index c960b95d38..21eec2baf3 100755 --- a/deb/build-deb +++ b/deb/build-deb @@ -7,6 +7,8 @@ mkdir -p /root/build-deb/engine tar -C /root/build-deb -xzf /sources/engine.tgz mkdir -p /root/build-deb/cli tar -C /root/build-deb -xzf /sources/cli.tgz +mkdir -p /root/build-deb/compose +tar -C /root/build-deb -xzf /sources/compose.tgz mkdir -p /root/build-deb/scan-cli-plugin tar -C /root/build-deb -xzf /sources/scan-cli-plugin.tgz @@ -14,6 +16,7 @@ tar -C /root/build-deb -xzf /sources/scan-cli-plugin.tgz mkdir -p /go/src/github.com/docker ln -snf /root/build-deb/engine /go/src/github.com/docker/docker ln -snf /root/build-deb/cli /go/src/github.com/docker/cli +ln -snf /root/build-deb/compose /go/src/github.com/docker/compose ln -snf /root/build-deb/scan-cli-plugin /go/src/github.com/docker/scan-cli-plugin EPOCH="${EPOCH:-}" diff --git a/deb/common/control b/deb/common/control index e16a215275..a9cd38b1ed 100644 --- a/deb/common/control +++ b/deb/common/control @@ -102,6 +102,18 @@ Description: Rootless support for Docker. Either VPNKit or slirp4netns (>= 0.4.0) needs to be installed separately. Homepage: https://docs.docker.com/engine/security/rootless/ +Package: docker-compose-plugin +Priority: optional +Architecture: linux-any +Enhances: docker-ce-cli +Description: Docker Compose (V2) plugin for the Docker CLI. + . + This plugin provides the 'docker compose' subcommand. + . + The binary can also be run standalone as a direct replacement for + Docker Compose V1 ('docker-compose'). +Homepage: https://github.com/docker/compose + Package: docker-scan-plugin Priority: optional # TODO change once we support scan-plugin on other architectures (see dpkg-architecture -L) diff --git a/deb/common/rules b/deb/common/rules index 32e8b95c66..aadd3b8de7 100755 --- a/deb/common/rules +++ b/deb/common/rules @@ -16,6 +16,15 @@ override_dh_auto_build: # Build the CLI cd /go/src/github.com/docker/cli && VERSION=$(VERSION) GITCOMMIT=$(CLI_GITCOMMIT) LDFLAGS='' GO_LINKMODE=dynamic ./scripts/build/binary && DISABLE_WARN_OUTSIDE_CONTAINER=1 LDFLAGS='' make manpages + # Build the compose plugin + # FIXME: using GOPROXY, to work around: + # go: github.com/Azure/azure-sdk-for-go@v48.2.0+incompatible: reading github.com/Azure/azure-sdk-for-go/go.mod at revision v48.2.0: unknown revision v48.2.0 + cd /go/src/github.com/docker/compose \ + && GOPROXY="https://proxy.golang.org" GO111MODULE=on go mod download \ + && mkdir -p /usr/libexec/docker/cli-plugins/ \ + && GOPROXY="https://proxy.golang.org" GO111MODULE=on GIT_TAG=$(COMPOSE_VERSION) \ + make COMPOSE_BINARY=/usr/libexec/docker/cli-plugins/docker-compose -f builder.Makefile compose-plugin + # Build the scan-plugin # TODO change once we support scan-plugin on other architectures if [ "$(TARGET_ARCH)" = "amd64" ]; then \ @@ -40,6 +49,9 @@ override_dh_auto_test: ver="$$(cli/build/docker --version)"; \ test "$$ver" = "Docker version $(VERSION), build $(CLI_GITCOMMIT)" && echo "PASS: cli version OK" || (echo "FAIL: cli version ($$ver) did not match" && exit 1) + ver="$$(/usr/libexec/docker/cli-plugins/docker-compose docker-cli-plugin-metadata | awk '{ gsub(/[",:]/,"")}; $$1 == "Version" { print $$2 }')"; \ + test "$$ver" = "$(COMPOSE_VERSION)" && echo "PASS: docker-compose version OK" || (echo "FAIL: docker-compose version ($$ver) did not match" && exit 1) + # FIXME: --version currently doesn't work as it makes a connection to the daemon, so using the plugin metadata instead # TODO change once we support scan-plugin on other architectures if [ "$(TARGET_ARCH)" = "amd64" ]; then \ @@ -69,6 +81,9 @@ override_dh_auto_install: install -D -m 0755 $(shell readlink -e engine/bundles/dynbinary-daemon/docker-proxy) debian/docker-ce/usr/bin/docker-proxy install -D -m 0755 /usr/local/bin/docker-init debian/docker-ce/usr/bin/docker-init + # docker-compose-plugin install + install -D -m 0755 /usr/libexec/docker/cli-plugins/docker-compose debian/docker-compose-plugin/usr/libexec/docker/cli-plugins/docker-compose + # docker-scan-plugin install # TODO change once we support scan-plugin on other architectures if [ "$(TARGET_ARCH)" = "amd64" ]; then \ @@ -95,6 +110,10 @@ override_dh_install: dh_apparmor --profile-name=docker-ce -pdocker-ce override_dh_gencontrol: + # Use separate version for the compose-plugin package, then generate the other control files as usual + # TODO override "Source" field in control as well (to point to compose, as it doesn't match the package name) + dh_gencontrol -pdocker-compose-plugin -- -v$${COMPOSE_VERSION#v}~$${DISTRO}-$${SUITE} + # Use separate version for the scan-plugin package, then generate the other control files as usual # TODO override "Source" field in control as well (to point to scan-cli-plugin, as it doesn't match the package name) # TODO change once we support scan-plugin on other architectures (see dpkg-architecture -L) From 276d806d084c0b11acf66ede0aef484049632449 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 3 Jul 2021 13:07:56 +0200 Subject: [PATCH 2/3] rpm: add docker-compose-plugin package Adds an rpm package for the docker-compose cli plugin with this: rpm -i \ ./docker-ce-cli-0.0.0.20210702143511.f782d13-0.el8.x86_64.rpm \ ./docker-scan-plugin-0.8.0-0.el8.x86_64.rpm \ ./docker-compose-plugin-2.3.1.3-0.el8.x86_64.rpm docker info --format '{{json .ClientInfo.Plugins}}' | jq . [ { "SchemaVersion": "0.1.0", "Vendor": "Docker Inc.", "Version": "v0.5.1-docker", "ShortDescription": "Build with BuildKit", "Name": "buildx", "Path": "/usr/libexec/docker/cli-plugins/docker-buildx" }, { "SchemaVersion": "0.1.0", "Vendor": "Docker Inc.", "Version": "v2.3.1", "ShortDescription": "Docker Compose", "Name": "compose", "Path": "/usr/libexec/docker/cli-plugins/docker-compose" }, { "SchemaVersion": "0.1.0", "Vendor": "Docker Inc.", "Version": "v0.8.0", "ShortDescription": "Docker Scan", "Name": "scan", "Path": "/usr/libexec/docker/cli-plugins/docker-scan" } ] Signed-off-by: Sebastiaan van Stijn --- rpm/Makefile | 20 +++++++-- rpm/SPECS/docker-compose-plugin.spec | 64 ++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 rpm/SPECS/docker-compose-plugin.spec diff --git a/rpm/Makefile b/rpm/Makefile index 29ad74e767..ba79b6e14f 100644 --- a/rpm/Makefile +++ b/rpm/Makefile @@ -4,6 +4,7 @@ PLUGINS_DIR=$(realpath $(CURDIR)/../plugins) GO_BASE_IMAGE=golang GO_IMAGE?=$(GO_BASE_IMAGE):$(GO_VERSION)-buster GEN_RPM_VER=$(shell ./gen-rpm-ver $(realpath $(CURDIR)/../src/github.com/docker/cli) "$(VERSION)") +GEN_COMPOSE_RPM_VER=$(shell ./gen-rpm-ver $(realpath $(CURDIR)/../src/github.com/docker/compose) "$(DOCKER_COMPOSE_REF)") GEN_SCAN_RPM_VER=$(shell ./gen-rpm-ver $(realpath $(CURDIR)/../src/github.com/docker/scan-cli-plugin) "$(DOCKER_SCAN_REF)") CLI_GITCOMMIT?=$(shell cd $(realpath $(CURDIR)/../src/github.com/docker/cli) && git rev-parse --short HEAD) ENGINE_GITCOMMIT?=$(shell cd $(realpath $(CURDIR)/../src/github.com/docker/docker) && git rev-parse --short HEAD) @@ -22,9 +23,9 @@ BUILD?=DOCKER_BUILDKIT=1 \ ifeq ($(ARCH),x86_64) -SPEC_FILES?=docker-ce.spec docker-ce-cli.spec docker-ce-rootless-extras.spec docker-scan-plugin.spec +SPEC_FILES?=docker-ce.spec docker-ce-cli.spec docker-ce-rootless-extras.spec docker-compose-plugin.spec docker-scan-plugin.spec else -SPEC_FILES?=docker-ce.spec docker-ce-cli.spec docker-ce-rootless-extras.spec +SPEC_FILES?=docker-ce.spec docker-ce-cli.spec docker-ce-rootless-extras.spec docker-compose-plugin.spec endif SPECS?=$(addprefix SPECS/, $(SPEC_FILES)) @@ -34,6 +35,8 @@ RPMBUILD_FLAGS?=-ba\ --define '_release $(word 2,$(GEN_RPM_VER))' \ --define '_version $(word 1,$(GEN_RPM_VER))' \ --define '_origversion $(word 4, $(GEN_RPM_VER))' \ + --define '_compose_rpm_version $(word 1,$(GEN_COMPOSE_RPM_VER))' \ + --define '_compose_version $(word 4,$(GEN_COMPOSE_RPM_VER))' \ --define '_scan_rpm_version $(word 1,$(GEN_SCAN_RPM_VER))' \ --define '_scan_version $(word 4,$(GEN_SCAN_RPM_VER))' \ --define '_scan_gitcommit $(SCAN_GITCOMMIT)' \ @@ -87,13 +90,16 @@ centos: $(CENTOS_RELEASES) ## build all centos rpm packages rhel: $(RHEL_RELEASES) ## build all rhel rpm packages .PHONY: $(DISTROS) -$(DISTROS): rpmbuild/SOURCES/engine.tgz rpmbuild/SOURCES/cli.tgz rpmbuild/SOURCES/scan-cli-plugin.tgz rpmbuild/SOURCES/plugin-installers.tgz +$(DISTROS): sources @echo "== Building packages for $@ ==" mkdir -p "rpmbuild/$@" $(BUILD) $(RUN) $(CHOWN) -R $(shell id -u):$(shell id -g) "rpmbuild/$@" +.PHONY: sources +sources: rpmbuild/SOURCES/engine.tgz rpmbuild/SOURCES/cli.tgz rpmbuild/SOURCES/compose.tgz rpmbuild/SOURCES/scan-cli-plugin.tgz rpmbuild/SOURCES/plugin-installers.tgz + rpmbuild/SOURCES/engine.tgz: mkdir -p $(@D) docker run --rm -w /v \ @@ -110,6 +116,14 @@ rpmbuild/SOURCES/cli.tgz: alpine \ tar -C / -c -z -f /v/cli.tgz --exclude .git cli +rpmbuild/SOURCES/compose.tgz: + mkdir -p $(@D) + docker run --rm -w /v \ + -v $(realpath $(CURDIR)/../src/github.com/docker/compose):/compose \ + -v $(CURDIR)/$(@D):/v \ + alpine \ + tar -C / -c -z -f /v/compose.tgz --exclude .git compose + rpmbuild/SOURCES/scan-cli-plugin.tgz: mkdir -p $(@D) docker run --rm -w /v \ diff --git a/rpm/SPECS/docker-compose-plugin.spec b/rpm/SPECS/docker-compose-plugin.spec new file mode 100644 index 0000000000..6aa96c9a88 --- /dev/null +++ b/rpm/SPECS/docker-compose-plugin.spec @@ -0,0 +1,64 @@ +%global debug_package %{nil} + +Name: docker-compose-plugin +Version: %{_compose_rpm_version} +Release: %{_release}%{?dist} +Epoch: 0 +Source0: compose.tgz +Summary: Docker Compose (V2) plugin for the Docker CLI +Group: Tools/Docker +License: ASL 2.0 +URL: https://github.com/docker/compose/ +Vendor: Docker +Packager: Docker + +Requires: docker-ce-cli + +BuildRequires: bash + +%description +Docker Compose (V2) plugin for the Docker CLI. + +This plugin provides the 'docker compose' subcommand. + +The binary can also be run standalone as a direct replacement for +Docker Compose V1 ('docker-compose'). + +%prep +%setup -q -c -n src -a 0 + +%build +pushd ${RPM_BUILD_DIR}/src/compose + # FIXME: using GOPROXY, to work around: + # go: github.com/Azure/azure-sdk-for-go@v48.2.0+incompatible: reading github.com/Azure/azure-sdk-for-go/go.mod at revision v48.2.0: unknown revision v48.2.0 + GOPROXY="https://proxy.golang.org" GO111MODULE=on go mod download + GOPROXY="https://proxy.golang.org" GO111MODULE=on GIT_TAG="%{_compose_version}" \ + make COMPOSE_BINARY="bin/docker-compose" -f builder.Makefile compose-plugin +popd + +%check +ver="$(${RPM_BUILD_ROOT}%{_libexecdir}/docker/cli-plugins/docker-compose docker-cli-plugin-metadata | awk '{ gsub(/[",:]/,"")}; $1 == "Version" { print $2 }')"; \ + test "$ver" = "%{_compose_version}" && echo "PASS: docker-compose version OK" || (echo "FAIL: docker-compose version ($ver) did not match" && exit 1) + +%install +pushd ${RPM_BUILD_DIR}/src/compose + install -D -p -m 0755 bin/docker-compose ${RPM_BUILD_ROOT}%{_libexecdir}/docker/cli-plugins/docker-compose +popd + +for f in LICENSE MAINTAINERS NOTICE README.md; do + install -D -p -m 0644 "${RPM_BUILD_DIR}/src/compose/$f" "docker-compose-plugin-docs/$f" +done + +%files +%doc docker-compose-plugin-docs/* +%license docker-compose-plugin-docs/LICENSE +%license docker-compose-plugin-docs/NOTICE +%{_libexecdir}/docker/cli-plugins/docker-compose + +%post + +%preun + +%postun + +%changelog From cab7b567fdd3e7108af65ed2734820d3095d2e4d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 3 Jul 2021 13:43:55 +0200 Subject: [PATCH 3/3] rpm: docker-compose-plugin: allow stand-alone installation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This removes the "require" docker-ce-cli, so that the package can be installed stand-alone (withouth the docker cli itself installed). Unlike "deb" packages, rpm package do not have "soft" requirement ("enhances", "recommends"), so having a "requires" makes the docker-cli a hard requirement. While in most situations, the plugin would be installed together with the docker cli, the plugin _is_ able to run standalone: /usr/libexec/docker/cli-plugins/docker-compose up [+] Running 2/2 ⠿ Network test_default Created 4.3s ⠿ Container test_web_1 Started 2.1s Attaching to web_1 web_1 | 10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf web_1 | 10-listen-on-ipv6-by-default.sh: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf web_1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh web_1 | /docker-entrypoint.sh: Configuration complete; ready for start up This removes the "Requires" annotation from the package, to simplify the dependency graph, and to allow installing the package separately (which could be for testing purposes, or for a minimal install). Signed-off-by: Sebastiaan van Stijn --- rpm/SPECS/docker-compose-plugin.spec | 2 -- 1 file changed, 2 deletions(-) diff --git a/rpm/SPECS/docker-compose-plugin.spec b/rpm/SPECS/docker-compose-plugin.spec index 6aa96c9a88..a4a583a0bf 100644 --- a/rpm/SPECS/docker-compose-plugin.spec +++ b/rpm/SPECS/docker-compose-plugin.spec @@ -12,8 +12,6 @@ URL: https://github.com/docker/compose/ Vendor: Docker Packager: Docker -Requires: docker-ce-cli - BuildRequires: bash %description