Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Commit

Permalink
Use docker build output for binaries
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Crone <christopher.crone@docker.com>
  • Loading branch information
chris-crone authored and ndeloof committed Oct 28, 2019
1 parent 0d08d65 commit 0803a77
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
27 changes: 25 additions & 2 deletions Dockerfile
Expand Up @@ -43,11 +43,34 @@ RUN go get -d gopkg.in/mjibson/esc.v0 && \
rm -rf /go/src/* /go/pkg/* /go/bin/*
COPY . .

FROM dev AS cross
FROM scratch AS cli
COPY --from=build /go/src/github.com/docker/cli/build/docker-linux-amd64 docker-linux
COPY --from=build /go/src/github.com/docker/cli/build/docker-darwin-amd64 docker-darwin
COPY --from=build /go/src/github.com/docker/cli/build/docker-windows-amd64 docker-windows.exe

FROM dev AS cross-build
ARG TAG="unknown"
RUN make TAG=${TAG} cross

FROM cross AS e2e-cross
FROM scratch AS cross
ARG PROJECT_PATH=/go/src/github.com/docker/app
COPY --from=cross-build ${PROJECT_PATH}/bin/docker-app-linux docker-app-linux
COPY --from=cross-build ${PROJECT_PATH}/bin/docker-app-darwin docker-app-darwin
COPY --from=cross-build ${PROJECT_PATH}/bin/docker-app-windows.exe docker-app-windows.exe

FROM cross-build AS e2e-cross-build
ARG TAG="unknown"
# Run e2e tests
RUN make TAG=${TAG} e2e-cross

FROM scratch AS e2e-cross
ARG PROJECT_PATH=/go/src/github.com/docker/app
COPY --from=e2e-cross-build ${PROJECT_PATH}/bin/docker-app-e2e-linux docker-app-e2e-linux
COPY --from=e2e-cross-build ${PROJECT_PATH}/bin/docker-app-e2e-darwin docker-app-e2e-darwin
COPY --from=e2e-cross-build ${PROJECT_PATH}/bin/docker-app-e2e-windows.exe docker-app-e2e-windows.exe
COPY --from=e2e-cross-build /usr/local/bin/gotestsum-linux gotestsum-linux
COPY --from=e2e-cross-build /usr/local/bin/gotestsum-darwin gotestsum-darwin
COPY --from=e2e-cross-build /usr/local/bin/gotestsum-windows.exe gotestsum-windows.exe
COPY --from=e2e-cross-build /usr/local/bin/test2json-linux test2json-linux
COPY --from=e2e-cross-build /usr/local/bin/test2json-darwin test2json-darwin
COPY --from=e2e-cross-build /usr/local/bin/test2json-windows.exe test2json-windows.exe
27 changes: 3 additions & 24 deletions docker.Makefile
Expand Up @@ -37,40 +37,19 @@ shell: build_dev_image ## run a shell in the docker build image
docker run -ti --rm $(DEV_IMAGE_NAME) bash

cross: create_bin ## cross-compile binaries (linux, darwin, windows)
docker build $(BUILD_ARGS) --target=cross -t $(CROSS_IMAGE_NAME) .
docker create --name $(CROSS_CTNR_NAME) $(CROSS_IMAGE_NAME) noop
docker cp $(CROSS_CTNR_NAME):$(PKG_PATH)/bin/$(BIN_NAME)-linux bin/$(BIN_NAME)-linux
docker cp $(CROSS_CTNR_NAME):$(PKG_PATH)/bin/$(BIN_NAME)-darwin bin/$(BIN_NAME)-darwin
docker cp $(CROSS_CTNR_NAME):$(PKG_PATH)/bin/$(BIN_NAME)-windows.exe bin/$(BIN_NAME)-windows.exe
docker rm $(CROSS_CTNR_NAME)
docker build $(BUILD_ARGS) --output type=local,dest=./bin/ --target=cross -t $(CROSS_IMAGE_NAME) .
@$(call chmod,+x,bin/$(BIN_NAME)-linux)
@$(call chmod,+x,bin/$(BIN_NAME)-darwin)
@$(call chmod,+x,bin/$(BIN_NAME)-windows.exe)

cli-cross: create_bin
docker build $(BUILD_ARGS) --target=build -t $(CLI_IMAGE_NAME) .
docker create --name $(CLI_CNTR_NAME) $(CLI_IMAGE_NAME) noop
docker cp $(CLI_CNTR_NAME):/go/src/github.com/docker/cli/build/docker-linux-amd64 bin/docker-linux
docker cp $(CLI_CNTR_NAME):/go/src/github.com/docker/cli/build/docker-darwin-amd64 bin/docker-darwin
docker cp $(CLI_CNTR_NAME):/go/src/github.com/docker/cli/build/docker-windows-amd64 bin/docker-windows.exe
docker rm $(CLI_CNTR_NAME)
docker build $(BUILD_ARGS) --output type=local,dest=./bin/ --target=cli -t $(CLI_IMAGE_NAME) .
@$(call chmod,+x,bin/docker-linux)
@$(call chmod,+x,bin/docker-darwin)
@$(call chmod,+x,bin/docker-windows.exe)

e2e-cross: create_bin
docker build $(BUILD_ARGS) --target=e2e-cross -t $(E2E_CROSS_IMAGE_NAME) .
docker create --name $(E2E_CROSS_CTNR_NAME) $(E2E_CROSS_IMAGE_NAME) noop
docker cp $(E2E_CROSS_CTNR_NAME):$(PKG_PATH)/bin/$(BIN_NAME)-e2e-linux bin/$(BIN_NAME)-e2e-linux
docker cp $(E2E_CROSS_CTNR_NAME):$(PKG_PATH)/bin/$(BIN_NAME)-e2e-darwin bin/$(BIN_NAME)-e2e-darwin
docker cp $(E2E_CROSS_CTNR_NAME):$(PKG_PATH)/bin/$(BIN_NAME)-e2e-windows.exe bin/$(BIN_NAME)-e2e-windows.exe
docker cp $(E2E_CROSS_CTNR_NAME):/usr/local/bin/gotestsum-linux bin/gotestsum-linux
docker cp $(E2E_CROSS_CTNR_NAME):/usr/local/bin/gotestsum-darwin bin/gotestsum-darwin
docker cp $(E2E_CROSS_CTNR_NAME):/usr/local/bin/gotestsum-windows.exe bin/gotestsum-windows.exe
docker cp $(E2E_CROSS_CTNR_NAME):/usr/local/bin/test2json-linux bin/test2json-linux
docker cp $(E2E_CROSS_CTNR_NAME):/usr/local/bin/test2json-darwin bin/test2json-darwin
docker cp $(E2E_CROSS_CTNR_NAME):/usr/local/bin/test2json-windows.exe bin/test2json-windows.exe
docker rm $(E2E_CROSS_CTNR_NAME)
docker build $(BUILD_ARGS) --output type=local,dest=./bin/ --target=e2e-cross -t $(E2E_CROSS_IMAGE_NAME) .
@$(call chmod,+x,bin/$(BIN_NAME)-e2e-linux)
@$(call chmod,+x,bin/$(BIN_NAME)-e2e-darwin)
@$(call chmod,+x,bin/gotestsum-linux)
Expand Down
1 change: 0 additions & 1 deletion docs/yaml/Dockerfile
Expand Up @@ -18,7 +18,6 @@ RUN build/yaml-docs-generator \
FROM scratch
ARG PROJECT=github.com/docker/app
ARG PROJECT_PATH=/go/src/${PROJECT}
ENV PROJECT_PATH=${PROJECT_PATH}
# CMD cannot be nil so we set it to empty string
CMD [""]
COPY --from=base ${PROJECT_PATH}/docs/reference /docs/reference
Expand Down

0 comments on commit 0803a77

Please sign in to comment.