зеркало из https://github.com/docker/compose-cli.git
Merge pull request #364 from chris-crone/set-version-docker
Set version when building with Docker
This commit is contained in:
Коммит
b881f16085
10
Dockerfile
10
Dockerfile
|
@ -36,9 +36,11 @@ FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION} AS lint-base
|
|||
FROM base AS lint
|
||||
ENV CGO_ENABLED=0
|
||||
COPY --from=lint-base /usr/bin/golangci-lint /usr/bin/golangci-lint
|
||||
ARG GIT_TAG
|
||||
RUN --mount=target=. \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
--mount=type=cache,target=/root/.cache/golangci-lint \
|
||||
GIT_TAG=${GIT_TAG} \
|
||||
make -f builder.Makefile lint
|
||||
|
||||
FROM base AS make-cli
|
||||
|
@ -46,18 +48,22 @@ ENV CGO_ENABLED=0
|
|||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
ARG BUILD_TAGS
|
||||
ARG GIT_TAG
|
||||
RUN --mount=target=. \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
GOOS=${TARGETOS} \
|
||||
GOARCH=${TARGETARCH} \
|
||||
BUILD_TAGS=${BUILD_TAGS} \
|
||||
GIT_TAG=${GIT_TAG} \
|
||||
make BINARY=/out/docker -f builder.Makefile cli
|
||||
|
||||
FROM base AS make-cross
|
||||
ARG BUILD_TAGS
|
||||
ARG GIT_TAG
|
||||
RUN --mount=target=. \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
BUILD_TAGS=${BUILD_TAGS} \
|
||||
GIT_TAG=${GIT_TAG} \
|
||||
make BINARY=/out/docker -f builder.Makefile cross
|
||||
|
||||
FROM scratch AS protos
|
||||
|
@ -70,9 +76,11 @@ FROM scratch AS cross
|
|||
COPY --from=make-cross /out/* .
|
||||
|
||||
FROM base as test
|
||||
ARG BUILD_TAGS
|
||||
ENV CGO_ENABLED=0
|
||||
ARG BUILD_TAGS
|
||||
ARG GIT_TAG
|
||||
RUN --mount=target=. \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
BUILD_TAGS=${BUILD_TAGS} \
|
||||
GIT_TAG=${GIT_TAG} \
|
||||
make -f builder.Makefile test
|
||||
|
|
9
Makefile
9
Makefile
|
@ -22,6 +22,8 @@ ifeq ($(UNAME_S),Darwin)
|
|||
MOBY_DOCKER=/Applications/Docker.app/Contents/Resources/bin/docker
|
||||
endif
|
||||
|
||||
GIT_TAG?=$(shell git describe --tags --match "v[0-9]*")
|
||||
|
||||
all: cli
|
||||
|
||||
protos: ## Generate go code from .proto files
|
||||
|
@ -32,6 +34,7 @@ cli: ## Compile the cli
|
|||
@docker build . --target cli \
|
||||
--platform local \
|
||||
--build-arg BUILD_TAGS=example,local \
|
||||
--build-arg GIT_TAG=$(GIT_TAG) \
|
||||
--output ./bin
|
||||
|
||||
e2e-local: ## Run End to end local tests
|
||||
|
@ -46,18 +49,22 @@ e2e-aci: ## Run End to end ACI tests (requires azure login)
|
|||
cross: ## Compile the CLI for linux, darwin and windows
|
||||
@docker build . --target cross \
|
||||
--build-arg BUILD_TAGS \
|
||||
--build-arg GIT_TAG=$(GIT_TAG) \
|
||||
--output ./bin \
|
||||
|
||||
test: ## Run unit tests
|
||||
@docker build . \
|
||||
--build-arg BUILD_TAGS=example,local \
|
||||
--build-arg GIT_TAG=$(GIT_TAG) \
|
||||
--target test
|
||||
|
||||
cache-clear: ## Clear the builder cache
|
||||
@docker builder prune --force --filter type=exec.cachemount --filter=unused-for=24h
|
||||
|
||||
lint: ## run linter(s)
|
||||
@docker build . --target lint
|
||||
@docker build . \
|
||||
--build-arg GIT_TAG=$(GIT_TAG) \
|
||||
--target lint
|
||||
|
||||
serve: cli ## start server
|
||||
@./bin/docker serve --address unix:///tmp/backend.sock
|
||||
|
|
|
@ -23,7 +23,8 @@ ifeq ($(GOOS),windows)
|
|||
endif
|
||||
|
||||
STATIC_FLAGS=CGO_ENABLED=0
|
||||
GIT_TAG=$(shell git describe --tags --match "v[0-9]*")
|
||||
|
||||
GIT_TAG?=$(shell git describe --tags --match "v[0-9]*")
|
||||
|
||||
LDFLAGS="-s -w -X main.version=${GIT_TAG}"
|
||||
GO_BUILD=$(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS)
|
||||
|
|
Загрузка…
Ссылка в новой задаче