mirror of
https://github.com/docker/compose.git
synced 2025-04-08 17:05:13 +02:00
Merge pull request #160 from chris-crone/dockerfile-improvements
Dockerfile improvements
This commit is contained in:
commit
21b6a2ae71
@ -1,2 +1,3 @@
|
|||||||
|
.git/
|
||||||
bin/
|
bin/
|
||||||
tests/node-client/node_modules/
|
tests/node-client/node_modules/
|
||||||
|
68
Dockerfile
68
Dockerfile
@ -1,66 +1,58 @@
|
|||||||
# syntax = docker/dockerfile:experimental
|
# syntax = docker/dockerfile:experimental
|
||||||
ARG GO_VERSION=1.14.3-alpine
|
ARG GO_VERSION=1.14.3-alpine
|
||||||
ARG GOLANGCI_LINT_VERSION=1.27.0
|
ARG GOLANGCI_LINT_VERSION=v1.27.0-alpine
|
||||||
|
|
||||||
FROM golang:${GO_VERSION} AS base
|
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS base
|
||||||
ARG TARGET_OS=unknown
|
WORKDIR /api
|
||||||
ARG TARGET_ARCH=unknown
|
|
||||||
ARG PWD=/api
|
|
||||||
ENV GO111MODULE=on
|
ENV GO111MODULE=on
|
||||||
|
RUN apk add --no-cache \
|
||||||
RUN apk update && apk add -U docker make
|
docker \
|
||||||
|
make \
|
||||||
WORKDIR ${PWD}
|
protoc
|
||||||
ADD go.* ${PWD}
|
COPY go.* .
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
ADD . ${PWD}
|
|
||||||
|
|
||||||
FROM golang:${GO_VERSION} AS protos-base
|
|
||||||
ARG TARGET_OS=unknown
|
|
||||||
ARG TARGET_ARCH=unknown
|
|
||||||
ARG PWD=/api
|
|
||||||
ENV GO111MODULE=on
|
|
||||||
|
|
||||||
RUN apk update && apk add protoc make
|
|
||||||
|
|
||||||
|
FROM base AS make-protos
|
||||||
RUN go get github.com/golang/protobuf/protoc-gen-go@v1.4.1
|
RUN go get github.com/golang/protobuf/protoc-gen-go@v1.4.1
|
||||||
|
COPY . .
|
||||||
WORKDIR ${PWD}
|
|
||||||
ADD go.* ${PWD}
|
|
||||||
ADD . ${PWD}
|
|
||||||
|
|
||||||
FROM protos-base AS make-protos
|
|
||||||
RUN make -f builder.Makefile protos
|
RUN make -f builder.Makefile protos
|
||||||
|
|
||||||
FROM golangci/golangci-lint:v${GOLANGCI_LINT_VERSION}-alpine AS lint-base
|
FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION} AS lint-base
|
||||||
|
|
||||||
FROM base AS lint
|
FROM base AS lint
|
||||||
COPY --from=lint-base /usr/bin/golangci-lint /usr/bin/golangci-lint
|
|
||||||
ENV CGO_ENABLED=0
|
ENV CGO_ENABLED=0
|
||||||
RUN --mount=id=build,type=cache,target=/root/.cache/go-build \
|
COPY --from=lint-base /usr/bin/golangci-lint /usr/bin/golangci-lint
|
||||||
--mount=id=lint,type=cache,target=/root/.cache/golangci-lint \
|
RUN --mount=target=. \
|
||||||
|
--mount=type=cache,target=/root/.cache/go-build \
|
||||||
|
--mount=type=cache,target=/root/.cache/golangci-lint \
|
||||||
make -f builder.Makefile lint
|
make -f builder.Makefile lint
|
||||||
|
|
||||||
FROM base AS make-cli
|
FROM base AS make-cli
|
||||||
RUN --mount=id=build,type=cache,target=/root/.cache/go-build \
|
ENV CGO_ENABLED=0
|
||||||
GOOS=${TARGET_OS} \
|
ARG TARGETOS
|
||||||
GOARCH=${TARGET_ARCH} \
|
ARG TARGETARCH
|
||||||
make -f builder.Makefile cli
|
RUN --mount=target=. \
|
||||||
|
--mount=type=cache,target=/root/.cache/go-build \
|
||||||
|
GOOS=${TARGETOS} \
|
||||||
|
GOARCH=${TARGETARCH} \
|
||||||
|
make BINARY=/out/docker -f builder.Makefile cli
|
||||||
|
|
||||||
FROM base AS make-cross
|
FROM base AS make-cross
|
||||||
RUN --mount=id=build,type=cache,target=/root/.cache/go-build \
|
RUN --mount=target=. \
|
||||||
make -f builder.Makefile cross
|
--mount=type=cache,target=/root/.cache/go-build \
|
||||||
|
make BINARY=/out/docker -f builder.Makefile cross
|
||||||
|
|
||||||
FROM scratch AS protos
|
FROM scratch AS protos
|
||||||
COPY --from=make-protos /api/protos .
|
COPY --from=make-protos /api/protos .
|
||||||
|
|
||||||
FROM scratch AS cli
|
FROM scratch AS cli
|
||||||
COPY --from=make-cli /api/bin/* .
|
COPY --from=make-cli /out/* .
|
||||||
|
|
||||||
FROM scratch AS cross
|
FROM scratch AS cross
|
||||||
COPY --from=make-cross /api/bin/* .
|
COPY --from=make-cross /out/* .
|
||||||
|
|
||||||
FROM base as test
|
FROM base as test
|
||||||
ENV CGO_ENABLED=0
|
ENV CGO_ENABLED=0
|
||||||
RUN --mount=id=build,type=cache,target=/root/.cache/go-build \
|
RUN --mount=target=. \
|
||||||
|
--mount=type=cache,target=/root/.cache/go-build \
|
||||||
make -f builder.Makefile test
|
make -f builder.Makefile test
|
||||||
|
28
Makefile
28
Makefile
@ -23,25 +23,18 @@
|
|||||||
# ARISING FROM, OUT OF OR IN CONNECTION WITH
|
# ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||||
# THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
# THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
GOOS ?= $(shell go env GOOS)
|
|
||||||
GOARCH ?= $(shell go env GOARCH)
|
|
||||||
PWD = $(shell pwd)
|
|
||||||
|
|
||||||
export DOCKER_BUILDKIT=1
|
export DOCKER_BUILDKIT=1
|
||||||
|
|
||||||
all: cli
|
all: cli
|
||||||
|
|
||||||
protos: ## Generate go code from .proto files
|
protos: ## Generate go code from .proto files
|
||||||
@docker build . \
|
@docker build . --target protos \
|
||||||
--output type=local,dest=./protos \
|
--output ./protos
|
||||||
--target protos
|
|
||||||
|
|
||||||
cli: ## Compile the cli
|
cli: ## Compile the cli
|
||||||
@docker build . \
|
@docker build . --target cli \
|
||||||
--output type=local,dest=./bin \
|
--platform local \
|
||||||
--build-arg TARGET_OS=${GOOS} \
|
--output ./bin
|
||||||
--build-arg TARGET_ARCH=${GOARCH} \
|
|
||||||
--target cli
|
|
||||||
|
|
||||||
e2e-local: ## Run End to end local tests
|
e2e-local: ## Run End to end local tests
|
||||||
go test -v ./tests/e2e ./moby/e2e
|
go test -v ./tests/e2e ./moby/e2e
|
||||||
@ -50,20 +43,17 @@ e2e-aci: ## Run End to end ACI tests (requires azure login)
|
|||||||
go test -v ./tests/aci-e2e
|
go test -v ./tests/aci-e2e
|
||||||
|
|
||||||
cross: ## Compile the CLI for linux, darwin and windows
|
cross: ## Compile the CLI for linux, darwin and windows
|
||||||
@docker build . \
|
@docker build . --target cross \
|
||||||
--output type=local,dest=./bin \
|
--output ./bin \
|
||||||
--target cross
|
|
||||||
|
|
||||||
test: ## Run unit tests
|
test: ## Run unit tests
|
||||||
@docker build . \
|
@docker build . --target test
|
||||||
--target test
|
|
||||||
|
|
||||||
cache-clear: ## Clear the builder cache
|
cache-clear: ## Clear the builder cache
|
||||||
@docker builder prune --force --filter type=exec.cachemount --filter=unused-for=24h
|
@docker builder prune --force --filter type=exec.cachemount --filter=unused-for=24h
|
||||||
|
|
||||||
lint: ## run linter(s)
|
lint: ## run linter(s)
|
||||||
@docker build . \
|
@docker build . --target lint
|
||||||
--target lint
|
|
||||||
|
|
||||||
classic-link: ## create docker-classic symlink if does not already exist
|
classic-link: ## create docker-classic symlink if does not already exist
|
||||||
ln -s /Applications/Docker.app/Contents/Resources/bin/docker /usr/local/bin/docker-classic
|
ln -s /Applications/Docker.app/Contents/Resources/bin/docker /usr/local/bin/docker-classic
|
||||||
|
@ -23,21 +23,21 @@
|
|||||||
# ARISING FROM, OUT OF OR IN CONNECTION WITH
|
# ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||||
# THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
# THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
GOOS ?= $(shell go env GOOS)
|
GOOS?=$(shell go env GOOS)
|
||||||
GOARCH ?= $(shell go env GOARCH)
|
GOARCH?=$(shell go env GOARCH)
|
||||||
|
|
||||||
PROTOS=$(shell find protos -name \*.proto)
|
PROTOS=$(shell find protos -name \*.proto)
|
||||||
|
|
||||||
EXTENSION :=
|
EXTENSION:=
|
||||||
ifeq ($(GOOS),windows)
|
ifeq ($(GOOS),windows)
|
||||||
EXTENSION := .exe
|
EXTENSION:=.exe
|
||||||
endif
|
endif
|
||||||
|
|
||||||
STATIC_FLAGS=CGO_ENABLED=0
|
STATIC_FLAGS=CGO_ENABLED=0
|
||||||
LDFLAGS := "-s -w"
|
LDFLAGS:="-s -w"
|
||||||
GO_BUILD = $(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS)
|
GO_BUILD=$(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS)
|
||||||
|
|
||||||
BINARY=bin/docker
|
BINARY?=bin/docker
|
||||||
BINARY_WITH_EXTENSION=$(BINARY)$(EXTENSION)
|
BINARY_WITH_EXTENSION=$(BINARY)$(EXTENSION)
|
||||||
|
|
||||||
all: cli
|
all: cli
|
||||||
|
Loading…
x
Reference in New Issue
Block a user