Skip to content

Commit 0889514

Browse files
debug
1 parent cfe252c commit 0889514

File tree

2 files changed

+60
-82
lines changed

2 files changed

+60
-82
lines changed

Dockerfile

+17-22
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,14 @@ ARG GO_VERSION=1.17-alpine
22
ARG GOLANGCI_LINT_VERSION=v1.40.1-alpine
33
ARG PROTOC_GEN_GO_VERSION=v1.4.3
44

5-
ARG BUILD_TAGS="e2e,kube"
6-
ARG DOCS_FORMATS="md,yaml"
7-
ARG LICENSE_FILES=".*\(Dockerfile\|Makefile\|\.go\|\.hcl\|\.sh\)"
8-
95
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS base
10-
RUN apk add --no-cache \
11-
docker \
12-
file \
13-
git \
14-
make \
15-
protoc \
16-
protobuf-dev
17-
WORKDIR /src
18-
ENV CGO_ENABLED=0
19-
20-
FROM base AS build-base
6+
WORKDIR /compose-cli
7+
RUN apk add --no-cache -vv \
8+
git \
9+
docker \
10+
make \
11+
protoc \
12+
protobuf-dev
2113
COPY go.* .
2214
RUN --mount=type=cache,target=/go/pkg/mod \
2315
--mount=type=cache,target=/root/.cache/go-build \
@@ -27,13 +19,16 @@ FROM base AS make-compose-plugin
2719
ENV CGO_ENABLED=0
2820
ARG TARGETOS
2921
ARG TARGETARCH
30-
ARG TARGETVARIANT
31-
RUN --mount=from=binary \
32-
mkdir -p /out && \
33-
# TODO: should just use standard arch
34-
TARGETARCH=$([ "$TARGETARCH" = "amd64" ] && echo "x86_64" || echo "$TARGETARCH"); \
35-
TARGETARCH=$([ "$TARGETARCH" = "arm64" ] && echo "aarch64" || echo "$TARGETARCH"); \
36-
cp docker-compose* "/out/docker-compose-${TARGETOS}-${TARGETARCH}${TARGETVARIANT}$(ls docker-compose* | sed -e 's/^docker-compose//')"
22+
ARG BUILD_TAGS
23+
ARG GIT_TAG
24+
RUN --mount=target=. \
25+
--mount=type=cache,target=/go/pkg/mod \
26+
--mount=type=cache,target=/root/.cache/go-build \
27+
GOOS=${TARGETOS} \
28+
GOARCH=${TARGETARCH} \
29+
BUILD_TAGS=${BUILD_TAGS} \
30+
GIT_TAG=${GIT_TAG} \
31+
make COMPOSE_BINARY=/out/docker-compose -f builder.Makefile compose-plugin
3732

3833
FROM debian:bullseye-slim AS compose-plugin
3934
WORKDIR /root

Makefile

+43-60
Original file line numberDiff line numberDiff line change
@@ -12,129 +12,112 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

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
1716

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)
2719
MOBY_DOCKER=/usr/bin/docker
2820
endif
29-
ifeq ($(DETECTED_OS),Darwin)
21+
ifeq ($(UNAME_S),Darwin)
3022
MOBY_DOCKER=/Applications/Docker.app/Contents/Resources/bin/docker
3123
endif
32-
ifeq ($(DETECTED_OS),Windows)
33-
BINARY_EXT=.exe
34-
endif
3524

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?=
3828
E2E_TEST?=
3929
ifeq ($(E2E_TEST),)
4030
else
4131
TEST_FLAGS=-run $(E2E_TEST)
4232
endif
4333

44-
BUILDX_CMD ?= docker buildx
45-
DESTDIR ?= ./bin/build
46-
47-
all: build
34+
all: compose-plugin
4835

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
6143

6244
.PHONY: e2e-compose
6345
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
6647

6748
.PHONY: e2e-compose-standalone
6849
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
7751

7852
.PHONY: mocks
7953
mocks:
80-
mockgen --version >/dev/null 2>&1 || go install github.com/golang/mock/[email protected]
8154
mockgen -destination pkg/mocks/mock_docker_cli.go -package mocks github.com/docker/cli/cli/command Cli
8255
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
8456

8557
.PHONY: e2e
8658
e2e: e2e-compose e2e-compose-standalone ## Run end to end local tests in both modes. Set E2E_TEST=TestName to run a single test
8759

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-
9160
.PHONY: cross
9261
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 \
9466

9567
.PHONY: test
9668
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
9873

9974
.PHONY: cache-clear
10075
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
10277

10378
.PHONY: lint
10479
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
10684

10785
.PHONY: docs
10886
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
11192
rm -rf ./docs/internal
11293
cp -R "$($@_TMP_OUT)"/out/* ./docs/
11394
rm -rf "$($@_TMP_OUT)"/*
11495

11596
.PHONY: validate-docs
11697
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
118101

119102
.PHONY: check-dependencies
120103
check-dependencies: ## check dependency updates
121104
go list -u -m -f '{{if not .Indirect}}{{if .Update}}{{.}}{{end}}{{end}}' all
122105

123106
.PHONY: validate-headers
124107
validate-headers: ## Check license header for all files
125-
$(BUILDX_CMD) bake license-validate
108+
@docker build . --target check-license-headers
126109

127110
.PHONY: go-mod-tidy
128111
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 .
130113

131114
.PHONY: validate-go-mod
132115
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
134117

135-
validate: validate-go-mod validate-headers validate-docs ## Validate sources
118+
validate: validate-go-mod validate-headers validate-docs ## Validate sources
136119

137-
pre-commit: validate check-dependencies lint build test e2e-compose
120+
pre-commit: validate check-dependencies lint compose-plugin test e2e-compose
138121

139122
help: ## Show help
140123
@echo Please specify a build target. The choices are:

0 commit comments

Comments
 (0)