Merge pull request #2696 from thaJeztah/multistage_dockerfile

Refactor / cleanup Dockerfile.dev
This commit is contained in:
Silvin Lubecki 2020-09-08 11:07:25 +02:00 committed by GitHub
commit ad16982544
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 31 deletions

View File

@ -6,7 +6,6 @@
# Overridable env vars # Overridable env vars
DOCKER_CLI_MOUNTS ?= -v "$(CURDIR)":/go/src/github.com/docker/cli DOCKER_CLI_MOUNTS ?= -v "$(CURDIR)":/go/src/github.com/docker/cli
DOCKER_CLI_SHELL ?= ash
DOCKER_CLI_CONTAINER_NAME ?= DOCKER_CLI_CONTAINER_NAME ?=
DOCKER_CLI_GO_BUILD_CACHE ?= y DOCKER_CLI_GO_BUILD_CACHE ?= y
@ -101,8 +100,8 @@ plugins-osx: build_cross_image ## build the example CLI plugins for macOS
.PHONY: dev .PHONY: dev
dev: build_docker_image ## start a build container in interactive mode for in-container development dev: build_docker_image ## start a build container in interactive mode for in-container development
$(DOCKER_RUN) -it \ $(DOCKER_RUN) -it \
-v /var/run/docker.sock:/var/run/docker.sock \ --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
$(DEV_DOCKER_IMAGE_NAME) $(DOCKER_CLI_SHELL) $(DEV_DOCKER_IMAGE_NAME)
shell: dev ## alias for dev shell: dev ## alias for dev
@ -146,15 +145,15 @@ test-e2e: test-e2e-non-experimental test-e2e-experimental test-e2e-connhelper-ss
.PHONY: test-e2e-experimental .PHONY: test-e2e-experimental
test-e2e-experimental: build_e2e_image # run experimental e2e tests test-e2e-experimental: build_e2e_image # run experimental e2e tests
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock $(ENVVARS) -e DOCKERD_EXPERIMENTAL=1 $(E2E_IMAGE_NAME) docker run --rm --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock $(ENVVARS) -e DOCKERD_EXPERIMENTAL=1 $(E2E_IMAGE_NAME)
.PHONY: test-e2e-non-experimental .PHONY: test-e2e-non-experimental
test-e2e-non-experimental: build_e2e_image # run non-experimental e2e tests test-e2e-non-experimental: build_e2e_image # run non-experimental e2e tests
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock $(ENVVARS) -e TEST_ENGINE_VERSION=$(E2E_ENGINE_VERSION) $(E2E_IMAGE_NAME) docker run --rm --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock $(ENVVARS) -e TEST_ENGINE_VERSION=$(E2E_ENGINE_VERSION) $(E2E_IMAGE_NAME)
.PHONY: test-e2e-connhelper-ssh .PHONY: test-e2e-connhelper-ssh
test-e2e-connhelper-ssh: build_e2e_image # run experimental SSH-connection helper e2e tests test-e2e-connhelper-ssh: build_e2e_image # run experimental SSH-connection helper e2e tests
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock $(ENVVARS) -e DOCKERD_EXPERIMENTAL=1 -e TEST_CONNHELPER=ssh $(E2E_IMAGE_NAME) docker run --rm --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock $(ENVVARS) -e DOCKERD_EXPERIMENTAL=1 -e TEST_CONNHELPER=ssh $(E2E_IMAGE_NAME)
.PHONY: help .PHONY: help
help: ## print this help help: ## print this help

View File

@ -1,33 +1,46 @@
# syntax=docker/dockerfile:1.1.7-experimental
ARG GO_VERSION=1.13.15 ARG GO_VERSION=1.13.15
FROM golang:${GO_VERSION}-alpine FROM golang:${GO_VERSION}-alpine AS golang
ENV CGO_ENABLED=0
RUN apk add --no-cache bash build-base ca-certificates coreutils curl git FROM golang AS esc
ARG ESC_VERSION=v0.2.0
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=tmpfs,target=/go/src/ \
GO111MODULE=on go get github.com/mjibson/esc@${ESC_VERSION}
# v0.1.1 FROM golang AS gotestsum
ARG VNDR_SHA=85886e1ac99b8d96590e6e0d9f075dc7a711d132 ARG GOTESTSUM_VERSION=v0.4.0
RUN go get -d github.com/LK4D4/vndr && \ RUN --mount=type=cache,target=/root/.cache/go-build \
cd /go/src/github.com/LK4D4/vndr && \ --mount=type=cache,target=/go/pkg/mod \
git checkout -q "$VNDR_SHA" && \ --mount=type=tmpfs,target=/go/src/ \
go build -v -o /usr/bin/vndr . && \ GO111MODULE=on go get gotest.tools/gotestsum@${GOTESTSUM_VERSION}
rm -rf /go/src/* /go/pkg/* /go/bin/*
# v0.2.0 FROM golang AS vndr
ARG ESC_SHA=0ea7db170df78dcddf3e223365f444163147fe89 ARG VNDR_VERSION=v0.1.1
RUN go get -d github.com/mjibson/esc && \ RUN --mount=type=cache,target=/root/.cache/go-build \
cd /go/src/github.com/mjibson/esc && \ --mount=type=cache,target=/go/pkg/mod \
git checkout -q "$ESC_SHA" && \ --mount=type=tmpfs,target=/go/src/ \
go build -v -o /usr/bin/esc . && \ GO111MODULE=on go get github.com/LK4D4/vndr@${VNDR_VERSION}
rm -rf /go/src/* /go/pkg/* /go/bin/*
ARG GOTESTSUM_VERSION=0.4.0 FROM golang AS dev
RUN curl -Ls https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_linux_amd64.tar.gz -o gotestsum.tar.gz && \ RUN apk add --no-cache \
tar -xf gotestsum.tar.gz gotestsum -C /usr/bin && \ bash \
rm gotestsum.tar.gz build-base \
ca-certificates \
coreutils \
curl \
git
CMD bash
ENV DISABLE_WARN_OUTSIDE_CONTAINER=1
ENV PATH=$PATH:/go/src/github.com/docker/cli/build
COPY --from=esc /go/bin/* /go/bin/
COPY --from=vndr /go/bin/* /go/bin/
COPY --from=gotestsum /go/bin/* /go/bin/
ENV CGO_ENABLED=0 \
PATH=$PATH:/go/src/github.com/docker/cli/build \
DISABLE_WARN_OUTSIDE_CONTAINER=1
WORKDIR /go/src/github.com/docker/cli WORKDIR /go/src/github.com/docker/cli
CMD sh COPY . .
COPY . .