|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
15 |
| -PKG := github.com/docker/compose/v2 |
16 |
| -VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.m' --always --tags) |
| 15 | +export DOCKER_BUILDKIT=1 |
17 | 16 |
|
18 |
| -GO_LDFLAGS ?= -s -w -X ${PKG}/internal.Version=${VERSION} |
19 |
| -GO_BUILDTAGS ?= e2e,kube |
20 |
| - |
21 |
| -ifeq ($(OS),Windows_NT) |
22 |
| - DETECTED_OS = Windows |
23 |
| -else |
24 |
| - DETECTED_OS = $(shell uname -s) |
25 |
| -endif |
26 |
| -ifeq ($(DETECTED_OS),Linux) |
| 17 | +UNAME_S := $(shell uname -s) |
| 18 | +ifeq ($(UNAME_S),Linux) |
27 | 19 | MOBY_DOCKER=/usr/bin/docker
|
28 | 20 | endif
|
29 |
| -ifeq ($(DETECTED_OS),Darwin) |
| 21 | +ifeq ($(UNAME_S),Darwin) |
30 | 22 | MOBY_DOCKER=/Applications/Docker.app/Contents/Resources/bin/docker
|
31 | 23 | endif
|
32 |
| -ifeq ($(DETECTED_OS),Windows) |
33 |
| - BINARY_EXT=.exe |
34 |
| -endif |
35 | 24 |
|
36 |
| -TEST_COVERAGE_FLAGS = -race -coverprofile=coverage.out -covermode=atomic |
37 |
| -TEST_FLAGS?= -timeout 15m |
| 25 | +BINARY_FOLDER=$(shell pwd)/bin |
| 26 | +GIT_TAG?=$(shell git describe --tags --match "v[0-9]*") |
| 27 | +TEST_FLAGS?= |
38 | 28 | E2E_TEST?=
|
39 | 29 | ifeq ($(E2E_TEST),)
|
40 | 30 | else
|
41 | 31 | TEST_FLAGS=-run $(E2E_TEST)
|
42 | 32 | endif
|
43 | 33 |
|
44 |
| -BUILDX_CMD ?= docker buildx |
45 |
| -DESTDIR ?= ./bin/build |
46 |
| - |
47 |
| -all: build |
| 34 | +all: compose-plugin |
48 | 35 |
|
49 |
| -.PHONY: build ## Build the compose cli-plugin |
50 |
| -build: |
51 |
| - CGO_ENABLED=0 GO111MODULE=on go build -trimpath -tags "$(GO_BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" -o "$(DESTDIR)/docker-compose$(BINARY_EXT)" ./cmd |
52 |
| - |
53 |
| -.PHONY: binary |
54 |
| -binary: |
55 |
| - $(BUILDX_CMD) bake binary |
56 |
| - |
57 |
| -.PHONY: install |
58 |
| -install: binary |
59 |
| - mkdir -p ~/.docker/cli-plugins |
60 |
| - install bin/build/docker-compose ~/.docker/cli-plugins/docker-compose |
| 36 | +.PHONY: compose-plugin |
| 37 | +compose-plugin: ## Compile the compose cli-plugin |
| 38 | + @docker build . --target compose-plugin \ |
| 39 | + --platform local \ |
| 40 | + --build-arg BUILD_TAGS=e2e,kube \ |
| 41 | + --build-arg GIT_TAG=$(GIT_TAG) \ |
| 42 | + --output ./bin |
61 | 43 |
|
62 | 44 | .PHONY: e2e-compose
|
63 | 45 | e2e-compose: ## Run end to end local tests in plugin mode. Set E2E_TEST=TestName to run a single test
|
64 |
| - docker compose version |
65 |
| - go test $(TEST_FLAGS) $(TEST_COVERAGE_FLAGS) -count=1 ./pkg/e2e |
| 46 | + go test $(TEST_FLAGS) -count=1 ./pkg/e2e |
66 | 47 |
|
67 | 48 | .PHONY: e2e-compose-standalone
|
68 | 49 | e2e-compose-standalone: ## Run End to end local tests in standalone mode. Set E2E_TEST=TestName to run a single test
|
69 |
| - docker-compose version |
70 |
| - go test $(TEST_FLAGS) -v -count=1 -parallel=1 --tags=standalone ./pkg/e2e |
71 |
| - |
72 |
| -.PHONY: build-and-e2e-compose |
73 |
| -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 |
74 |
| - |
75 |
| -.PHONY: build-and-e2e-compose-standalone |
76 |
| -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 |
| 50 | + go test $(TEST_FLAGS) -count=1 --tags=standalone ./pkg/e2e |
77 | 51 |
|
78 | 52 | .PHONY: mocks
|
79 | 53 | mocks:
|
80 |
| - mockgen --version >/dev/null 2>&1 || go install github.com/golang/mock/ [email protected] |
81 | 54 | mockgen -destination pkg/mocks/mock_docker_cli.go -package mocks github.com/docker/cli/cli/command Cli
|
82 | 55 | mockgen -destination pkg/mocks/mock_docker_api.go -package mocks github.com/docker/docker/client APIClient
|
83 |
| - mockgen -destination pkg/mocks/mock_docker_compose_api.go -package mocks -source=./pkg/api/api.go Service |
84 | 56 |
|
85 | 57 | .PHONY: e2e
|
86 | 58 | e2e: e2e-compose e2e-compose-standalone ## Run end to end local tests in both modes. Set E2E_TEST=TestName to run a single test
|
87 | 59 |
|
88 |
| -.PHONY: build-and-e2e |
89 |
| -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 |
90 |
| - |
91 | 60 | .PHONY: cross
|
92 | 61 | cross: ## Compile the CLI for linux, darwin and windows
|
93 |
| - $(BUILDX_CMD) bake binary-cross |
| 62 | + @docker build . --target cross \ |
| 63 | + --build-arg BUILD_TAGS \ |
| 64 | + --build-arg GIT_TAG=$(GIT_TAG) \ |
| 65 | + --output ./bin \ |
94 | 66 |
|
95 | 67 | .PHONY: test
|
96 | 68 | test: ## Run unit tests
|
97 |
| - $(BUILDX_CMD) bake test |
| 69 | + @docker build --progress=plain . \ |
| 70 | + --build-arg BUILD_TAGS=kube \ |
| 71 | + --build-arg GIT_TAG=$(GIT_TAG) \ |
| 72 | + --target test |
98 | 73 |
|
99 | 74 | .PHONY: cache-clear
|
100 | 75 | cache-clear: ## Clear the builder cache
|
101 |
| - $(BUILDX_CMD) prune --force --filter type=exec.cachemount --filter=unused-for=24h |
| 76 | + @docker builder prune --force --filter type=exec.cachemount --filter=unused-for=24h |
102 | 77 |
|
103 | 78 | .PHONY: lint
|
104 | 79 | lint: ## run linter(s)
|
105 |
| - $(BUILDX_CMD) bake lint |
| 80 | + @docker build . \ |
| 81 | + --build-arg BUILD_TAGS=kube,e2e \ |
| 82 | + --build-arg GIT_TAG=$(GIT_TAG) \ |
| 83 | + --target lint |
106 | 84 |
|
107 | 85 | .PHONY: docs
|
108 | 86 | docs: ## generate documentation
|
109 |
| - $(eval $@_TMP_OUT := $(shell mktemp -d -t compose-output.XXXXXXXXXX)) |
110 |
| - $(BUILDX_CMD) bake --set "*.output=type=local,dest=$($@_TMP_OUT)" docs-update |
| 87 | + $(eval $@_TMP_OUT := $(shell mktemp -d -t dockercli-output.XXXXXXXXXX)) |
| 88 | + docker build . \ |
| 89 | + --output type=local,dest=$($@_TMP_OUT) \ |
| 90 | + -f ./docs/docs.Dockerfile \ |
| 91 | + --target update |
111 | 92 | rm -rf ./docs/internal
|
112 | 93 | cp -R "$($@_TMP_OUT)"/out/* ./docs/
|
113 | 94 | rm -rf "$($@_TMP_OUT)"/*
|
114 | 95 |
|
115 | 96 | .PHONY: validate-docs
|
116 | 97 | validate-docs: ## validate the doc does not change
|
117 |
| - $(BUILDX_CMD) bake docs-validate |
| 98 | + @docker build . \ |
| 99 | + -f ./docs/docs.Dockerfile \ |
| 100 | + --target validate |
118 | 101 |
|
119 | 102 | .PHONY: check-dependencies
|
120 | 103 | check-dependencies: ## check dependency updates
|
121 | 104 | go list -u -m -f '{{if not .Indirect}}{{if .Update}}{{.}}{{end}}{{end}}' all
|
122 | 105 |
|
123 | 106 | .PHONY: validate-headers
|
124 | 107 | validate-headers: ## Check license header for all files
|
125 |
| - $(BUILDX_CMD) bake license-validate |
| 108 | + @docker build . --target check-license-headers |
126 | 109 |
|
127 | 110 | .PHONY: go-mod-tidy
|
128 | 111 | go-mod-tidy: ## Run go mod tidy in a container and output resulting go.mod and go.sum
|
129 |
| - $(BUILDX_CMD) bake vendor-update |
| 112 | + @docker build . --target go-mod-tidy --output . |
130 | 113 |
|
131 | 114 | .PHONY: validate-go-mod
|
132 | 115 | validate-go-mod: ## Validate go.mod and go.sum are up-to-date
|
133 |
| - $(BUILDX_CMD) bake vendor-validate |
| 116 | + @docker build . --target check-go-mod |
134 | 117 |
|
135 |
| -validate: validate-go-mod validate-headers validate-docs ## Validate sources |
| 118 | +validate: validate-go-mod validate-headers validate-docs ## Validate sources |
136 | 119 |
|
137 |
| -pre-commit: validate check-dependencies lint build test e2e-compose |
| 120 | +pre-commit: validate check-dependencies lint compose-plugin test e2e-compose |
138 | 121 |
|
139 | 122 | help: ## Show help
|
140 | 123 | @echo Please specify a build target. The choices are:
|
|
0 commit comments