Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 0803a77

Browse files
chris-cronendeloof
authored andcommitted
Use docker build output for binaries
Signed-off-by: Christopher Crone <[email protected]>
1 parent 0d08d65 commit 0803a77

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

Dockerfile

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,34 @@ RUN go get -d gopkg.in/mjibson/esc.v0 && \
4343
rm -rf /go/src/* /go/pkg/* /go/bin/*
4444
COPY . .
4545

46-
FROM dev AS cross
46+
FROM scratch AS cli
47+
COPY --from=build /go/src/github.com/docker/cli/build/docker-linux-amd64 docker-linux
48+
COPY --from=build /go/src/github.com/docker/cli/build/docker-darwin-amd64 docker-darwin
49+
COPY --from=build /go/src/github.com/docker/cli/build/docker-windows-amd64 docker-windows.exe
50+
51+
FROM dev AS cross-build
4752
ARG TAG="unknown"
4853
RUN make TAG=${TAG} cross
4954

50-
FROM cross AS e2e-cross
55+
FROM scratch AS cross
56+
ARG PROJECT_PATH=/go/src/github.com/docker/app
57+
COPY --from=cross-build ${PROJECT_PATH}/bin/docker-app-linux docker-app-linux
58+
COPY --from=cross-build ${PROJECT_PATH}/bin/docker-app-darwin docker-app-darwin
59+
COPY --from=cross-build ${PROJECT_PATH}/bin/docker-app-windows.exe docker-app-windows.exe
60+
61+
FROM cross-build AS e2e-cross-build
5162
ARG TAG="unknown"
5263
# Run e2e tests
5364
RUN make TAG=${TAG} e2e-cross
65+
66+
FROM scratch AS e2e-cross
67+
ARG PROJECT_PATH=/go/src/github.com/docker/app
68+
COPY --from=e2e-cross-build ${PROJECT_PATH}/bin/docker-app-e2e-linux docker-app-e2e-linux
69+
COPY --from=e2e-cross-build ${PROJECT_PATH}/bin/docker-app-e2e-darwin docker-app-e2e-darwin
70+
COPY --from=e2e-cross-build ${PROJECT_PATH}/bin/docker-app-e2e-windows.exe docker-app-e2e-windows.exe
71+
COPY --from=e2e-cross-build /usr/local/bin/gotestsum-linux gotestsum-linux
72+
COPY --from=e2e-cross-build /usr/local/bin/gotestsum-darwin gotestsum-darwin
73+
COPY --from=e2e-cross-build /usr/local/bin/gotestsum-windows.exe gotestsum-windows.exe
74+
COPY --from=e2e-cross-build /usr/local/bin/test2json-linux test2json-linux
75+
COPY --from=e2e-cross-build /usr/local/bin/test2json-darwin test2json-darwin
76+
COPY --from=e2e-cross-build /usr/local/bin/test2json-windows.exe test2json-windows.exe

docker.Makefile

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,40 +37,19 @@ shell: build_dev_image ## run a shell in the docker build image
3737
docker run -ti --rm $(DEV_IMAGE_NAME) bash
3838

3939
cross: create_bin ## cross-compile binaries (linux, darwin, windows)
40-
docker build $(BUILD_ARGS) --target=cross -t $(CROSS_IMAGE_NAME) .
41-
docker create --name $(CROSS_CTNR_NAME) $(CROSS_IMAGE_NAME) noop
42-
docker cp $(CROSS_CTNR_NAME):$(PKG_PATH)/bin/$(BIN_NAME)-linux bin/$(BIN_NAME)-linux
43-
docker cp $(CROSS_CTNR_NAME):$(PKG_PATH)/bin/$(BIN_NAME)-darwin bin/$(BIN_NAME)-darwin
44-
docker cp $(CROSS_CTNR_NAME):$(PKG_PATH)/bin/$(BIN_NAME)-windows.exe bin/$(BIN_NAME)-windows.exe
45-
docker rm $(CROSS_CTNR_NAME)
40+
docker build $(BUILD_ARGS) --output type=local,dest=./bin/ --target=cross -t $(CROSS_IMAGE_NAME) .
4641
@$(call chmod,+x,bin/$(BIN_NAME)-linux)
4742
@$(call chmod,+x,bin/$(BIN_NAME)-darwin)
4843
@$(call chmod,+x,bin/$(BIN_NAME)-windows.exe)
4944

5045
cli-cross: create_bin
51-
docker build $(BUILD_ARGS) --target=build -t $(CLI_IMAGE_NAME) .
52-
docker create --name $(CLI_CNTR_NAME) $(CLI_IMAGE_NAME) noop
53-
docker cp $(CLI_CNTR_NAME):/go/src/github.com/docker/cli/build/docker-linux-amd64 bin/docker-linux
54-
docker cp $(CLI_CNTR_NAME):/go/src/github.com/docker/cli/build/docker-darwin-amd64 bin/docker-darwin
55-
docker cp $(CLI_CNTR_NAME):/go/src/github.com/docker/cli/build/docker-windows-amd64 bin/docker-windows.exe
56-
docker rm $(CLI_CNTR_NAME)
46+
docker build $(BUILD_ARGS) --output type=local,dest=./bin/ --target=cli -t $(CLI_IMAGE_NAME) .
5747
@$(call chmod,+x,bin/docker-linux)
5848
@$(call chmod,+x,bin/docker-darwin)
5949
@$(call chmod,+x,bin/docker-windows.exe)
6050

6151
e2e-cross: create_bin
62-
docker build $(BUILD_ARGS) --target=e2e-cross -t $(E2E_CROSS_IMAGE_NAME) .
63-
docker create --name $(E2E_CROSS_CTNR_NAME) $(E2E_CROSS_IMAGE_NAME) noop
64-
docker cp $(E2E_CROSS_CTNR_NAME):$(PKG_PATH)/bin/$(BIN_NAME)-e2e-linux bin/$(BIN_NAME)-e2e-linux
65-
docker cp $(E2E_CROSS_CTNR_NAME):$(PKG_PATH)/bin/$(BIN_NAME)-e2e-darwin bin/$(BIN_NAME)-e2e-darwin
66-
docker cp $(E2E_CROSS_CTNR_NAME):$(PKG_PATH)/bin/$(BIN_NAME)-e2e-windows.exe bin/$(BIN_NAME)-e2e-windows.exe
67-
docker cp $(E2E_CROSS_CTNR_NAME):/usr/local/bin/gotestsum-linux bin/gotestsum-linux
68-
docker cp $(E2E_CROSS_CTNR_NAME):/usr/local/bin/gotestsum-darwin bin/gotestsum-darwin
69-
docker cp $(E2E_CROSS_CTNR_NAME):/usr/local/bin/gotestsum-windows.exe bin/gotestsum-windows.exe
70-
docker cp $(E2E_CROSS_CTNR_NAME):/usr/local/bin/test2json-linux bin/test2json-linux
71-
docker cp $(E2E_CROSS_CTNR_NAME):/usr/local/bin/test2json-darwin bin/test2json-darwin
72-
docker cp $(E2E_CROSS_CTNR_NAME):/usr/local/bin/test2json-windows.exe bin/test2json-windows.exe
73-
docker rm $(E2E_CROSS_CTNR_NAME)
52+
docker build $(BUILD_ARGS) --output type=local,dest=./bin/ --target=e2e-cross -t $(E2E_CROSS_IMAGE_NAME) .
7453
@$(call chmod,+x,bin/$(BIN_NAME)-e2e-linux)
7554
@$(call chmod,+x,bin/$(BIN_NAME)-e2e-darwin)
7655
@$(call chmod,+x,bin/gotestsum-linux)

docs/yaml/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ RUN build/yaml-docs-generator \
1818
FROM scratch
1919
ARG PROJECT=github.com/docker/app
2020
ARG PROJECT_PATH=/go/src/${PROJECT}
21-
ENV PROJECT_PATH=${PROJECT_PATH}
2221
# CMD cannot be nil so we set it to empty string
2322
CMD [""]
2423
COPY --from=base ${PROJECT_PATH}/docs/reference /docs/reference

0 commit comments

Comments
 (0)