From c549d8550500285b6f289cd064a3b690e29e612a Mon Sep 17 00:00:00 2001 From: Chris Crone Date: Mon, 21 Sep 2020 12:21:41 +0200 Subject: [PATCH 1/5] makefile: Tidy up Signed-off-by: Chris Crone --- builder.Makefile | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/builder.Makefile b/builder.Makefile index 28e5d395..36f5e74c 100644 --- a/builder.Makefile +++ b/builder.Makefile @@ -39,32 +39,37 @@ endif all: cli +.PHONY: protos protos: protoc -I. --go_out=plugins=grpc,paths=source_relative:. ${PROTOS} +.PHONY: cli cli: GOOS=${GOOS} GOARCH=${GOARCH} $(GO_BUILD) $(TAGS) -o $(BINARY_WITH_EXTENSION) ./cli +.PHONY: cross cross: GOOS=linux GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-linux-amd64 ./cli GOOS=darwin GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-darwin-amd64 ./cli GOOS=windows GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-windows-amd64.exe ./cli +.PHONY: test test: go test $(TAGS) -cover $(shell go list ./... | grep -vE 'e2e') +.PHONY: lint lint: golangci-lint run --timeout 10m0s ./... +.PHONY: import-restrictions import-restrictions: import-restrictions --configuration import-restrictions.yaml +.PHONY: check-licese-headers check-license-headers: ./scripts/validate/fileheader +.PHONY: check-go-mod check-go-mod: ./scripts/validate/check-go-mod -FORCE: - -.PHONY: all protos cli cross test lint From 2aea82a7c6da2480c1f8f9ad81b226f0b6566367 Mon Sep 17 00:00:00 2001 From: Chris Crone Date: Mon, 21 Sep 2020 16:15:59 +0200 Subject: [PATCH 2/5] packaging: Add EULA Signed-off-by: Chris Crone --- .dockerignore | 1 + .github/workflows/release.yaml | 4 ++-- .gitignore | 1 + builder.Makefile | 11 +++++++++++ packaging/LICENSE | 2 ++ 5 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 packaging/LICENSE diff --git a/.dockerignore b/.dockerignore index eaf4e6cb..a21b7936 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ .git/ bin/ +dist/ tests/node-client/node_modules/ diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index fb5d31bf..65b422ce 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -25,10 +25,10 @@ jobs: ${{ runner.os }}-go- - name: Build - run: make -f builder.Makefile cross + run: make -f builder.Makefile package - uses: ncipollo/release-action@v1 with: - artifacts: "bin/*" + artifacts: "dist/*" prerelease: true token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index e660fd93..a5d8f723 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ bin/ +dist/ diff --git a/builder.Makefile b/builder.Makefile index 36f5e74c..fc5697d4 100644 --- a/builder.Makefile +++ b/builder.Makefile @@ -37,6 +37,11 @@ ifdef BUILD_TAGS TAGS=-tags $(BUILD_TAGS) endif +TAR_TRANSFORM:=--transform s/packaging/docker/ --transform s/bin/docker/ +ifneq ($(findstring bsd,$(shell tar --version)),) + TAR_TRANSFORM=-s /packaging/docker/ -s /bin/docker/ +endif + all: cli .PHONY: protos @@ -73,3 +78,9 @@ check-license-headers: check-go-mod: ./scripts/validate/check-go-mod +.PHONY: package +package: cross + mkdir -p dist + tar -czf dist/docker-linux-amd64.tar.gz $(TAR_TRANSFORM) packaging/LICENSE $(BINARY)-linux-amd64 + tar -czf dist/docker-darwin-amd64.tar.gz $(TAR_TRANSFORM) packaging/LICENSE $(BINARY)-darwin-amd64 + rm -f dist/docker-windows-amd64.zip && zip dist/docker-windows-amd64.zip -j packaging/LICENSE $(BINARY)-windows-amd64.exe diff --git a/packaging/LICENSE b/packaging/LICENSE new file mode 100644 index 00000000..fcf6aa89 --- /dev/null +++ b/packaging/LICENSE @@ -0,0 +1,2 @@ +The Docker End User License Agreement (https://www.docker.com/legal/docker-software-end-user-license-agreement) describes Docker's Terms for this software. +By downloading, accessing, or using this software you expressly accept and agree to the Terms set out in the Docker End User License Agreement. From 121bc3b2e90c0c2c29792e19a6203392f8632016 Mon Sep 17 00:00:00 2001 From: Chris Crone Date: Tue, 22 Sep 2020 10:15:16 +0200 Subject: [PATCH 3/5] scripts: Update Linux install scripts Signed-off-by: Chris Crone --- scripts/install/Dockerfile-testInstall | 14 ----------- scripts/install/install_linux.sh | 26 ++++++++++--------- scripts/install/test.Dockerfile | 35 ++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 26 deletions(-) delete mode 100644 scripts/install/Dockerfile-testInstall create mode 100644 scripts/install/test.Dockerfile diff --git a/scripts/install/Dockerfile-testInstall b/scripts/install/Dockerfile-testInstall deleted file mode 100644 index 5dd7554a..00000000 --- a/scripts/install/Dockerfile-testInstall +++ /dev/null @@ -1,14 +0,0 @@ -FROM ubuntu:latest - -RUN apt-get update -RUN apt-get -y install curl grep -RUN curl https://get.docker.com | sh - -COPY install_linux.sh /scripts/install_linux.sh -RUN chmod +x /scripts/install_linux.sh -RUN /scripts/install_linux.sh -RUN docker version | grep Azure - -# check we can update -RUN /scripts/install_linux.sh -RUN docker version | grep Azure \ No newline at end of file diff --git a/scripts/install/install_linux.sh b/scripts/install/install_linux.sh index 1e6cee32..6bec9803 100644 --- a/scripts/install/install_linux.sh +++ b/scripts/install/install_linux.sh @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Script to install the Docker ACI integration CLI on Ubuntu (Beta). +# Script to install the Docker Compose CLI on Ubuntu (Beta). set -eu @@ -106,18 +106,19 @@ if ! [ "$(command -v curl)" ]; then exit 1 fi -DOWNLOAD_URL=$(curl -s ${RELEASE_URL} | grep "browser_download_url.*docker-linux-amd64" | cut -d : -f 2,3) +DOWNLOAD_URL=${DOWNLOAD_URL:-$(curl -s ${RELEASE_URL} | grep "browser_download_url.*docker-linux-amd64.tar.gz" | cut -d : -f 2,3)} -# Check if the ACI CLI is already installed +# Check if the Compose CLI is already installed if [ $(is_new_cli "docker") -eq 1 ]; then if [ $(is_new_cli "/usr/local/bin/docker") -eq 1 ]; then - echo "You already have the Docker ACI Integration CLI installed, overriding with latest version" + echo "You already have the Docker Compose CLI installed, overriding with latest version" download_dir=$($sh_c 'mktemp -d') - $sh_c "${download_cmd} ${download_dir}/docker-aci ${DOWNLOAD_URL}" - $sudo_sh_c "install -m 775 ${download_dir}/docker-aci /usr/local/bin/docker" + $sh_c "${download_cmd} ${download_dir}/docker-compose-cli.tar.gz ${DOWNLOAD_URL}" + $sh_c "tar xzf ${download_dir}/docker-compose-cli.tar.gz -C ${download_dir} --strip-components 1" + $sudo_sh_c "install -m 775 ${download_dir}/docker-linux-amd64 /usr/local/bin/docker" exit 0 fi - echo "You already have the Docker ACI Integration CLI installed, in a different location." + echo "You already have the Docker Compose CLI installed, in a different location." exit 1 fi @@ -169,7 +170,8 @@ echo "Downloading CLI..." # Download CLI to temporary directory download_dir=$($sh_c 'mktemp -d') -$sh_c "${download_cmd} ${download_dir}/docker-aci ${DOWNLOAD_URL}" +$sh_c "${download_cmd} ${download_dir}/docker-compose-cli.tar.gz ${DOWNLOAD_URL}" +$sh_c "tar xzf ${download_dir}/docker-compose-cli.tar.gz -C ${download_dir} --strip-components 1" echo "Downloaded CLI!" echo "Installing CLI..." @@ -178,7 +180,7 @@ echo "Installing CLI..." $sudo_sh_c "ln -s ${existing_cli_path} ${link_path}" # Install downloaded CLI -$sudo_sh_c "install -m 775 ${download_dir}/docker-aci /usr/local/bin/docker" +$sudo_sh_c "install -m 775 ${download_dir}/docker-linux-amd64 /usr/local/bin/docker" # Clear cache cleared_cache=1 @@ -196,12 +198,12 @@ if [ -n "$DRY_RUN" ]; then fi if [ -n "$cleared_cache" ]; then - # Check ACI CLI is working + # Check Compose CLI is working if [ $(is_new_cli "docker") -eq 0 ]; then - echo "Error: Docker ACI Integration CLI installation error" + echo "Error: Docker Compose CLI installation error" exit 1 fi echo "Done!" else - echo "Please log out and in again to use the Docker ACI integration CLI" + echo "Please log out and in again to use the Docker Compose CLI" fi diff --git a/scripts/install/test.Dockerfile b/scripts/install/test.Dockerfile new file mode 100644 index 00000000..ba844ee8 --- /dev/null +++ b/scripts/install/test.Dockerfile @@ -0,0 +1,35 @@ +# Copyright 2020 Docker Compose CLI authors + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM ubuntu:20.04 AS base +RUN apt-get update && apt-get install -y \ + curl +RUN curl https://get.docker.com | sh + +FROM base AS install +COPY install_linux.sh /scripts/install_linux.sh +RUN chmod +x /scripts/install_linux.sh +ARG DOWNLOAD_URL= +RUN DOWNLOAD_URL=${DOWNLOAD_URL} /scripts/install_linux.sh +RUN docker version | grep Cloud + +# check we can update +FROM install AS upgrade +RUN DOWNLOAD_URL=${DOWNLOAD_URL} /scripts/install_linux.sh +RUN docker version | grep Cloud + +# To run this test locally, start an HTTP server that serves the dist/ folder +# then run a docker build passing the DOWNLOAD_URL as a build arg: +# $ cd dist/ && python3 -m http.server & +# $ docker build -f test.Dockerfile --build-arg DOWNLOAD_URL=http://192.168.0.22:8000/docker-linux-amd64.tar.gz . From 2e6d739fc82969f1d96a4e722dc973264e66e8fd Mon Sep 17 00:00:00 2001 From: Chris Crone Date: Tue, 22 Sep 2020 13:32:06 +0200 Subject: [PATCH 4/5] scripts: Add test for CentOS Signed-off-by: Chris Crone --- scripts/install/test.Dockerfile | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/install/test.Dockerfile b/scripts/install/test.Dockerfile index ba844ee8..10d1fedc 100644 --- a/scripts/install/test.Dockerfile +++ b/scripts/install/test.Dockerfile @@ -12,19 +12,24 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM ubuntu:20.04 AS base +# Distro options: ubuntu, centos +ARG DISTRO=ubuntu + +FROM ubuntu:20.04 AS base-ubuntu RUN apt-get update && apt-get install -y \ curl RUN curl https://get.docker.com | sh -FROM base AS install +FROM centos:7 AS base-centos +RUN curl https://get.docker.com | sh + +FROM base-${DISTRO} AS install COPY install_linux.sh /scripts/install_linux.sh RUN chmod +x /scripts/install_linux.sh ARG DOWNLOAD_URL= RUN DOWNLOAD_URL=${DOWNLOAD_URL} /scripts/install_linux.sh RUN docker version | grep Cloud -# check we can update FROM install AS upgrade RUN DOWNLOAD_URL=${DOWNLOAD_URL} /scripts/install_linux.sh RUN docker version | grep Cloud @@ -33,3 +38,5 @@ RUN docker version | grep Cloud # then run a docker build passing the DOWNLOAD_URL as a build arg: # $ cd dist/ && python3 -m http.server & # $ docker build -f test.Dockerfile --build-arg DOWNLOAD_URL=http://192.168.0.22:8000/docker-linux-amd64.tar.gz . +# +# You can specify centos or ubuntu as distros using the DISTRO build arg. From dd57e9e6462824addaa90eaae46e1d7648513d18 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Tue, 22 Sep 2020 17:13:56 +0200 Subject: [PATCH 5/5] Binary is named docker inside tar, docker.exe inside zip package Signed-off-by: Guillaume Tardif --- builder.Makefile | 10 +++++++--- scripts/install/install_linux.sh | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/builder.Makefile b/builder.Makefile index fc5697d4..90d17de6 100644 --- a/builder.Makefile +++ b/builder.Makefile @@ -32,14 +32,16 @@ GO_BUILD=$(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS) BINARY?=bin/docker BINARY_WITH_EXTENSION=$(BINARY)$(EXTENSION) +WORK_DIR:=$(shell mktemp -d) + TAGS:= ifdef BUILD_TAGS TAGS=-tags $(BUILD_TAGS) endif -TAR_TRANSFORM:=--transform s/packaging/docker/ --transform s/bin/docker/ +TAR_TRANSFORM:=--transform s/packaging/docker/ --transform s/bin/docker/ --transform s/docker-linux-amd64/docker/ --transform s/docker-darwin-amd64/docker/ ifneq ($(findstring bsd,$(shell tar --version)),) - TAR_TRANSFORM=-s /packaging/docker/ -s /bin/docker/ + TAR_TRANSFORM=-s /packaging/docker/ -s /bin/docker/ -s /docker-linux-amd64/docker/ -s /docker-darwin-amd64/docker/ endif all: cli @@ -83,4 +85,6 @@ package: cross mkdir -p dist tar -czf dist/docker-linux-amd64.tar.gz $(TAR_TRANSFORM) packaging/LICENSE $(BINARY)-linux-amd64 tar -czf dist/docker-darwin-amd64.tar.gz $(TAR_TRANSFORM) packaging/LICENSE $(BINARY)-darwin-amd64 - rm -f dist/docker-windows-amd64.zip && zip dist/docker-windows-amd64.zip -j packaging/LICENSE $(BINARY)-windows-amd64.exe + cp $(BINARY)-windows-amd64.exe $(WORK_DIR)/docker.exe + rm -f dist/docker-windows-amd64.zip && zip dist/docker-windows-amd64.zip -j packaging/LICENSE $(WORK_DIR)/docker.exe + rm -r $(WORK_DIR) diff --git a/scripts/install/install_linux.sh b/scripts/install/install_linux.sh index 6bec9803..d5927c19 100644 --- a/scripts/install/install_linux.sh +++ b/scripts/install/install_linux.sh @@ -115,7 +115,7 @@ if [ $(is_new_cli "docker") -eq 1 ]; then download_dir=$($sh_c 'mktemp -d') $sh_c "${download_cmd} ${download_dir}/docker-compose-cli.tar.gz ${DOWNLOAD_URL}" $sh_c "tar xzf ${download_dir}/docker-compose-cli.tar.gz -C ${download_dir} --strip-components 1" - $sudo_sh_c "install -m 775 ${download_dir}/docker-linux-amd64 /usr/local/bin/docker" + $sudo_sh_c "install -m 775 ${download_dir}/docker /usr/local/bin/docker" exit 0 fi echo "You already have the Docker Compose CLI installed, in a different location."