mirror of https://github.com/docker/compose.git
Makefile: mutualize local and Dockerfile build opts (#9776)
Ensure that everything works nicely for `docker-ce-packaging` as well as local development. Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
f3e0c386d2
commit
69651136cf
11
Dockerfile
11
Dockerfile
|
@ -36,6 +36,7 @@ RUN apk add --no-cache \
|
||||||
docker \
|
docker \
|
||||||
file \
|
file \
|
||||||
git \
|
git \
|
||||||
|
make \
|
||||||
protoc \
|
protoc \
|
||||||
protobuf-dev
|
protobuf-dev
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
@ -68,20 +69,14 @@ RUN --mount=type=bind,target=.,rw <<EOT
|
||||||
fi
|
fi
|
||||||
EOT
|
EOT
|
||||||
|
|
||||||
FROM base AS version
|
|
||||||
RUN --mount=target=. \
|
|
||||||
PKG=github.com/docker/compose/v2 VERSION=$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags); \
|
|
||||||
echo "-X ${PKG}/internal.Version=${VERSION}" | tee /tmp/.ldflags; \
|
|
||||||
echo -n "${VERSION}" | tee /tmp/.version;
|
|
||||||
|
|
||||||
FROM build-base AS build
|
FROM build-base AS build
|
||||||
ARG BUILD_TAGS
|
ARG BUILD_TAGS
|
||||||
ARG TARGETPLATFORM
|
ARG TARGETPLATFORM
|
||||||
|
RUN xx-go --wrap
|
||||||
RUN --mount=type=bind,target=. \
|
RUN --mount=type=bind,target=. \
|
||||||
--mount=type=cache,target=/root/.cache \
|
--mount=type=cache,target=/root/.cache \
|
||||||
--mount=type=cache,target=/go/pkg/mod \
|
--mount=type=cache,target=/go/pkg/mod \
|
||||||
--mount=type=bind,source=/tmp/.ldflags,target=/tmp/.ldflags,from=version \
|
make build GO_BUILDTAGS="$BUILD_TAGS" DESTDIR=/usr/bin && \
|
||||||
set -x; xx-go build -trimpath -tags "$BUILD_TAGS" -ldflags "$(cat /tmp/.ldflags) -w -s" -o /usr/bin/docker-compose ./cmd && \
|
|
||||||
xx-verify --static /usr/bin/docker-compose
|
xx-verify --static /usr/bin/docker-compose
|
||||||
|
|
||||||
FROM build-base AS lint
|
FROM build-base AS lint
|
||||||
|
|
41
Makefile
41
Makefile
|
@ -12,15 +12,11 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
ifneq (, $(BUILDX_BIN))
|
PKG := github.com/docker/compose/v2
|
||||||
export BUILDX_CMD = $(BUILDX_BIN)
|
VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.m' --always --tags)
|
||||||
else ifneq (, $(shell docker buildx version))
|
|
||||||
export BUILDX_CMD = docker buildx
|
GO_LDFLAGS ?= -s -w -X ${PKG}/internal.Version=${VERSION}
|
||||||
else ifneq (, $(shell which buildx))
|
GO_BUILDTAGS ?= e2e,kube
|
||||||
export BUILDX_CMD = $(which buildx)
|
|
||||||
else
|
|
||||||
$(error "Buildx is required: https://github.com/docker/buildx#installing")
|
|
||||||
endif
|
|
||||||
|
|
||||||
UNAME_S := $(shell uname -s)
|
UNAME_S := $(shell uname -s)
|
||||||
ifeq ($(UNAME_S),Linux)
|
ifeq ($(UNAME_S),Linux)
|
||||||
|
@ -30,8 +26,6 @@ ifeq ($(UNAME_S),Darwin)
|
||||||
MOBY_DOCKER=/Applications/Docker.app/Contents/Resources/bin/docker
|
MOBY_DOCKER=/Applications/Docker.app/Contents/Resources/bin/docker
|
||||||
endif
|
endif
|
||||||
|
|
||||||
BINARY_FOLDER=$(shell pwd)/bin
|
|
||||||
GIT_TAG?=$(shell git describe --tags --match "v[0-9]*")
|
|
||||||
TEST_FLAGS?=
|
TEST_FLAGS?=
|
||||||
E2E_TEST?=
|
E2E_TEST?=
|
||||||
ifeq ($(E2E_TEST),)
|
ifeq ($(E2E_TEST),)
|
||||||
|
@ -39,14 +33,21 @@ else
|
||||||
TEST_FLAGS=-run $(E2E_TEST)
|
TEST_FLAGS=-run $(E2E_TEST)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
all: compose-plugin
|
BUILDX_CMD ?= docker buildx
|
||||||
|
DESTDIR ?= ./bin/build
|
||||||
|
|
||||||
.PHONY: compose-plugin
|
all: build
|
||||||
compose-plugin: ## Compile the compose cli-plugin
|
|
||||||
|
.PHONY: build ## Build the compose cli-plugin
|
||||||
|
build:
|
||||||
|
CGO_ENABLED=0 GO111MODULE=on go build -trimpath -tags "$(GO_BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" -o "$(DESTDIR)/docker-compose" ./cmd
|
||||||
|
|
||||||
|
.PHONY: binary
|
||||||
|
binary:
|
||||||
$(BUILDX_CMD) bake binary
|
$(BUILDX_CMD) bake binary
|
||||||
|
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
install: compose-plugin
|
install: binary
|
||||||
mkdir -p ~/.docker/cli-plugins
|
mkdir -p ~/.docker/cli-plugins
|
||||||
install bin/build/docker-compose ~/.docker/cli-plugins/docker-compose
|
install bin/build/docker-compose ~/.docker/cli-plugins/docker-compose
|
||||||
|
|
||||||
|
@ -61,10 +62,10 @@ e2e-compose-standalone: ## Run End to end local tests in standalone mode. Set E2
|
||||||
go test $(TEST_FLAGS) -v -count=1 -parallel=1 --tags=standalone ./pkg/e2e
|
go test $(TEST_FLAGS) -v -count=1 -parallel=1 --tags=standalone ./pkg/e2e
|
||||||
|
|
||||||
.PHONY: build-and-e2e-compose
|
.PHONY: build-and-e2e-compose
|
||||||
build-and-e2e-compose: compose-plugin 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
|
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
|
||||||
|
|
||||||
.PHONY: build-and-e2e-compose-standalone
|
.PHONY: build-and-e2e-compose-standalone
|
||||||
build-and-e2e-compose-standalone: compose-plugin 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
|
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
|
||||||
|
|
||||||
.PHONY: mocks
|
.PHONY: mocks
|
||||||
mocks:
|
mocks:
|
||||||
|
@ -76,11 +77,11 @@ mocks:
|
||||||
e2e: e2e-compose e2e-compose-standalone ## Run end to end local tests in both modes. Set E2E_TEST=TestName to run a single test
|
e2e: e2e-compose e2e-compose-standalone ## Run end to end local tests in both modes. Set E2E_TEST=TestName to run a single test
|
||||||
|
|
||||||
.PHONY: build-and-e2e
|
.PHONY: build-and-e2e
|
||||||
build-and-e2e: compose-plugin 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
|
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
|
||||||
|
|
||||||
.PHONY: cross
|
.PHONY: cross
|
||||||
cross: ## Compile the CLI for linux, darwin and windows
|
cross: ## Compile the CLI for linux, darwin and windows
|
||||||
$(BUILDX_CMD) bake binary
|
$(BUILDX_CMD) bake binary-cross
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: ## Run unit tests
|
test: ## Run unit tests
|
||||||
|
@ -124,7 +125,7 @@ validate-go-mod: ## Validate go.mod and go.sum are up-to-date
|
||||||
|
|
||||||
validate: validate-go-mod validate-headers validate-docs ## Validate sources
|
validate: validate-go-mod validate-headers validate-docs ## Validate sources
|
||||||
|
|
||||||
pre-commit: validate check-dependencies lint compose-plugin test e2e-compose
|
pre-commit: validate check-dependencies lint build test e2e-compose
|
||||||
|
|
||||||
help: ## Show help
|
help: ## Show help
|
||||||
@echo Please specify a build target. The choices are:
|
@echo Please specify a build target. The choices are:
|
||||||
|
|
Loading…
Reference in New Issue