| 1 |
# Copyright 2020 Docker Compose CLI authors |
| 2 |
|
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
|
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
|
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
# See the License for the specific language governing permissions and |
| 13 |
# limitations under the License. |
| 14 |
|
| 15 |
PKG := github.com/docker/compose/v2 |
| 16 |
VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.m' --always --tags) |
| 17 |
|
| 18 |
GO_LDFLAGS ?= -w -X ${PKG}/internal.Version=${VERSION} |
| 19 |
GO_BUILDTAGS ?= e2e |
| 20 |
DRIVE_PREFIX?= |
| 21 |
ifeq ($(OS),Windows_NT) |
| 22 |
DETECTED_OS = Windows |
| 23 |
DRIVE_PREFIX=C: |
| 24 |
else |
| 25 |
DETECTED_OS = $(shell uname -s) |
| 26 |
endif |
| 27 |
|
| 28 |
ifeq ($(DETECTED_OS),Windows) |
| 29 |
BINARY_EXT=.exe |
| 30 |
endif |
| 31 |
|
| 32 |
BUILD_FLAGS?= |
| 33 |
TEST_FLAGS?= |
| 34 |
E2E_TEST?= |
| 35 |
ifneq ($(E2E_TEST),) |
| 36 |
TEST_FLAGS:=$(TEST_FLAGS) -run '$(E2E_TEST)' |
| 37 |
endif |
| 38 |
|
| 39 |
EXCLUDE_E2E_TESTS?= |
| 40 |
ifneq ($(EXCLUDE_E2E_TESTS),) |
| 41 |
TEST_FLAGS:=$(TEST_FLAGS) -skip '$(EXCLUDE_E2E_TESTS)' |
| 42 |
endif |
| 43 |
|
| 44 |
BUILDX_CMD ?= docker buildx |
| 45 |
|
| 46 |
# DESTDIR overrides the output path for binaries and other artifacts |
| 47 |
# this is used by docker/docker-ce-packaging for the apt/rpm builds, |
| 48 |
# so it's important that the resulting binary ends up EXACTLY at the |
| 49 |
# path $DESTDIR/docker-compose when specified. |
| 50 |
# |
| 51 |
# See https://github.com/docker/docker-ce-packaging/blob/e43fbd37e48fde49d907b9195f23b13537521b94/rpm/SPECS/docker-compose-plugin.spec#L47 |
| 52 |
# |
| 53 |
# By default, all artifacts go to subdirectories under ./bin/ in the |
| 54 |
# repo root, e.g. ./bin/build, ./bin/coverage, ./bin/release. |
| 55 |
DESTDIR ?= |
| 56 |
|
| 57 |
all: build |
| 58 |
|
| 59 |
.PHONY: build ## Build the compose cli-plugin |
| 60 |
build: |
| 61 |
GO111MODULE=on go build $(BUILD_FLAGS) -trimpath -tags "$(GO_BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" -o "$(or $(DESTDIR),./bin/build)/docker-compose$(BINARY_EXT)" ./cmd |
| 62 |
|
| 63 |
.PHONY: binary |
| 64 |
binary: |
| 65 |
$(BUILDX_CMD) bake binary |
| 66 |
|
| 67 |
.PHONY: binary-with-coverage |
| 68 |
binary-with-coverage: |
| 69 |
$(BUILDX_CMD) bake binary-with-coverage |
| 70 |
|
| 71 |
.PHONY: install |
| 72 |
install: binary |
| 73 |
mkdir -p ~/.docker/cli-plugins |
| 74 |
install $(or $(DESTDIR),./bin/build)/docker-compose ~/.docker/cli-plugins/docker-compose |
| 75 |
|
| 76 |
.PHONY: e2e-compose |
| 77 |
e2e-compose: example-provider ## Run end to end local tests in plugin mode. Set E2E_TEST=TestName to run a single test |
| 78 |
go run gotest.tools/gotestsum@latest --format testname --junitfile "/tmp/report/report.xml" -- -v $(TEST_FLAGS) -count=1 ./pkg/e2e |
| 79 |
|
| 80 |
.PHONY: e2e-compose-standalone |
| 81 |
e2e-compose-standalone: ## Run End to end local tests in standalone mode. Set E2E_TEST=TestName to run a single test |
| 82 |
go run gotest.tools/gotestsum@latest --format testname --junitfile "/tmp/report/report.xml" -- $(TEST_FLAGS) -v -count=1 -parallel=1 --tags=standalone ./pkg/e2e |
| 83 |
|
| 84 |
.PHONY: build-and-e2e-compose |
| 85 |
build-and-e2e-compose: build e2e-compose ## Compile the compose cli-plugin and run end to end local tests in plugin mode. Set E2E_TEST=TestName to run a single test |
| 86 |
|
| 87 |
.PHONY: build-and-e2e-compose-standalone |
| 88 |
build-and-e2e-compose-standalone: build e2e-compose-standalone ## Compile the compose cli-plugin and run End to end local tests in standalone mode. Set E2E_TEST=TestName to run a single test |
| 89 |
|
| 90 |
.PHONY: example-provider |
| 91 |
example-provider: ## build example provider for e2e tests |
| 92 |
go build -o bin/build/example-provider docs/examples/provider.go |
| 93 |
|
| 94 |
.PHONY: mocks |
| 95 |
mocks: |
| 96 |
mockgen --version >/dev/null 2>&1 || go install go.uber.org/mock/[email protected] |
| 97 |
mockgen -destination pkg/mocks/mock_docker_cli.go -package mocks github.com/docker/cli/cli/command Cli |
| 98 |
mockgen -destination pkg/mocks/mock_docker_api.go -package mocks github.com/docker/docker/client APIClient |
| 99 |
mockgen -destination pkg/mocks/mock_docker_compose_api.go -package mocks -source=./pkg/api/api.go Service |
| 100 |
|
| 101 |
.PHONY: e2e |
| 102 |
e2e: e2e-compose e2e-compose-standalone ## Run end to end local tests in both modes. Set E2E_TEST=TestName to run a single test |
| 103 |
|
| 104 |
.PHONY: build-and-e2e |
| 105 |
build-and-e2e: build e2e-compose e2e-compose-standalone ## Compile the compose cli-plugin and run end to end local tests in both modes. Set E2E_TEST=TestName to run a single test |
| 106 |
|
| 107 |
.PHONY: cross |
| 108 |
cross: ## Compile the CLI for linux, darwin and windows |
| 109 |
$(BUILDX_CMD) bake binary-cross |
| 110 |
|
| 111 |
.PHONY: test |
| 112 |
test: ## Run unit tests |
| 113 |
$(BUILDX_CMD) bake test |
| 114 |
|
| 115 |
.PHONY: cache-clear |
| 116 |
cache-clear: ## Clear the builder cache |
| 117 |
$(BUILDX_CMD) prune --force --filter type=exec.cachemount --filter=unused-for=24h |
| 118 |
|
| 119 |
.PHONY: lint |
| 120 |
lint: ## run linter(s) |
| 121 |
$(BUILDX_CMD) bake lint |
| 122 |
|
| 123 |
.PHONY: fmt |
| 124 |
fmt: |
| 125 |
gofumpt --version >/dev/null 2>&1 || go install mvdan.cc/gofumpt@latest |
| 126 |
gofumpt -w . |
| 127 |
|
| 128 |
.PHONY: docs |
| 129 |
docs: ## generate documentation |
| 130 |
$(eval $@_TMP_OUT := $(shell mktemp -d -t compose-output.XXXXXXXXXX)) |
| 131 |
$(BUILDX_CMD) bake --set "*.output=type=local,dest=$($@_TMP_OUT)" docs-update |
| 132 |
rm -rf ./docs/internal |
| 133 |
cp -R "$(DRIVE_PREFIX)$($@_TMP_OUT)"/out/* ./docs/ |
| 134 |
rm -rf "$(DRIVE_PREFIX)$($@_TMP_OUT)"/* |
| 135 |
|
| 136 |
.PHONY: validate-docs |
| 137 |
validate-docs: ## validate the doc does not change |
| 138 |
$(BUILDX_CMD) bake docs-validate |
| 139 |
|
| 140 |
.PHONY: check-dependencies |
| 141 |
check-dependencies: ## check dependency updates |
| 142 |
go list -u -m -f '{{if not .Indirect}}{{if .Update}}{{.}}{{end}}{{end}}' all |
| 143 |
|
| 144 |
.PHONY: validate-headers |
| 145 |
validate-headers: ## Check license header for all files |
| 146 |
$(BUILDX_CMD) bake license-validate |
| 147 |
|
| 148 |
.PHONY: go-mod-tidy |
| 149 |
go-mod-tidy: ## Run go mod tidy in a container and output resulting go.mod and go.sum |
| 150 |
$(BUILDX_CMD) bake vendor-update |
| 151 |
|
| 152 |
.PHONY: validate-go-mod |
| 153 |
validate-go-mod: ## Validate go.mod and go.sum are up-to-date |
| 154 |
$(BUILDX_CMD) bake vendor-validate |
| 155 |
|
| 156 |
validate: validate-go-mod validate-headers validate-docs ## Validate sources |
| 157 |
|
| 158 |
pre-commit: validate check-dependencies lint build test e2e-compose |
| 159 |
|
| 160 |
help: ## Show help |
| 161 |
@echo Please specify a build target. The choices are: |
| 162 |
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |