From fd2143e0b086931d3b5432f167a795fb4201e440 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Thu, 14 Apr 2022 19:52:23 +0200 Subject: [PATCH] use go-winres for cross to create Windows resources Signed-off-by: CrazyMax --- .dockerignore | 3 +- .github/workflows/ci.yml | 1 - .gitignore | 2 + Dockerfile | 41 ++++++--- Makefile | 5 +- cli/winresources/README.md | 0 cli/winresources/docker-proxy/winresources.go | 12 +++ .../winresources/docker.ico | Bin cli/winresources/dockerd/winresources.go | 12 +++ cli/winresources/event_messages.bin | Bin 0 -> 256 bytes .../winresources}/event_messages.mc | 0 cmd/docker-proxy/genwinres_windows.go | 5 ++ cmd/dockerd/genwinres_windows.go | 5 ++ hack/go-mod-prepare.sh | 6 -- hack/make/.go-autogen | 51 ++--------- hack/make/.mkwinres | 85 ++++++++++++++++++ hack/make/.resources-windows/common.rc | 38 -------- .../.resources-windows/dockerd.exe.manifest | 18 ---- hack/make/.resources-windows/dockerd.rc | 4 - hack/make/.resources-windows/resources.go | 18 ---- 20 files changed, 163 insertions(+), 143 deletions(-) create mode 100644 cli/winresources/README.md create mode 100644 cli/winresources/docker-proxy/winresources.go rename hack/make/.resources-windows/dockerd.ico => cli/winresources/docker.ico (100%) create mode 100644 cli/winresources/dockerd/winresources.go create mode 100644 cli/winresources/event_messages.bin rename {hack/make/.resources-windows => cli/winresources}/event_messages.mc (100%) create mode 100644 cmd/docker-proxy/genwinres_windows.go create mode 100644 cmd/dockerd/genwinres_windows.go create mode 100644 hack/make/.mkwinres delete mode 100644 hack/make/.resources-windows/common.rc delete mode 100644 hack/make/.resources-windows/dockerd.exe.manifest delete mode 100644 hack/make/.resources-windows/dockerd.rc delete mode 100644 hack/make/.resources-windows/resources.go diff --git a/.dockerignore b/.dockerignore index a8eeb4b41f..2a8bcd5a54 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,5 +2,6 @@ .go-pkg-cache .gopath bundles +cli/winresources/**/winres.json +cli/winresources/**/*.syso vendor/pkg - diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3035410c72..6645cb7b4a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,7 +74,6 @@ jobs: run: | platform=${{ matrix.platform }} echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV - mkdir -p autogen - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 diff --git a/.gitignore b/.gitignore index c2c287498a..18acfe87de 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,8 @@ test.main .go-pkg-cache/ autogen/ bundles/ +cli/winresources/**/winres.json +cli/winresources/**/*.syso cmd/dockerd/dockerd contrib/builder/rpm/*/changelog vendor/pkg/ diff --git a/Dockerfile b/Dockerfile index 87bc2e9e42..a0d4a94b7e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -161,6 +161,14 @@ RUN --mount=type=cache,target=/root/.cache/go-build \ GOBIN=/build/ GO111MODULE=on go install "github.com/pelletier/go-toml/cmd/tomll@${GOTOML_VERSION}" \ && /build/tomll --help +FROM base AS gowinres +# GOWINRES_VERSION defines go-winres tool version +ARG GOWINRES_VERSION=v0.2.3 +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg/mod \ + GOBIN=/build/ GO111MODULE=on go install "github.com/tc-hib/go-winres@${GOWINRES_VERSION}" \ + && /build/go-winres --help + FROM dev-base AS containerd ARG DEBIAN_FRONTEND RUN --mount=type=cache,sharing=locked,id=moby-containerd-aptlib,target=/var/lib/apt \ @@ -301,6 +309,7 @@ COPY --from=dockercli /build/ /usr/local/cli COPY --from=frozen-images /build/ /docker-frozen-images COPY --from=swagger /build/ /usr/local/bin/ COPY --from=tomll /build/ /usr/local/bin/ +COPY --from=gowinres /build/ /usr/local/bin/ COPY --from=tini /build/ /usr/local/bin/ COPY --from=registry /build/ /usr/local/bin/ COPY --from=criu /build/ /usr/local/bin/ @@ -346,34 +355,42 @@ ARG PRODUCT ENV PRODUCT=${PRODUCT} ARG DEFAULT_PRODUCT_LICENSE ENV DEFAULT_PRODUCT_LICENSE=${DEFAULT_PRODUCT_LICENSE} +ARG PACKAGER_NAME +ENV PACKAGER_NAME=${PACKAGER_NAME} ARG DOCKER_BUILDTAGS ENV DOCKER_BUILDTAGS="${DOCKER_BUILDTAGS}" ENV PREFIX=/build # TODO: This is here because hack/make.sh binary copies these extras binaries # from $PATH into the bundles dir. # It would be nice to handle this in a different way. -COPY --from=tini /build/ /usr/local/bin/ -COPY --from=runc /build/ /usr/local/bin/ -COPY --from=containerd /build/ /usr/local/bin/ -COPY --from=rootlesskit /build/ /usr/local/bin/ -COPY --from=vpnkit /build/ /usr/local/bin/ +COPY --from=tini /build/ /usr/local/bin/ +COPY --from=runc /build/ /usr/local/bin/ +COPY --from=containerd /build/ /usr/local/bin/ +COPY --from=rootlesskit /build/ /usr/local/bin/ +COPY --from=vpnkit /build/ /usr/local/bin/ +COPY --from=gowinres /build/ /usr/local/bin/ WORKDIR /go/src/github.com/docker/docker FROM binary-base AS build-binary -RUN --mount=type=cache,target=/root/.cache/go-build \ - --mount=type=bind,target=/go/src/github.com/docker/docker \ +RUN --mount=type=cache,target=/root/.cache \ + --mount=type=bind,target=.,ro \ + --mount=type=tmpfs,target=cli/winresources/dockerd \ + --mount=type=tmpfs,target=cli/winresources/docker-proxy \ hack/make.sh binary FROM binary-base AS build-dynbinary -RUN --mount=type=cache,target=/root/.cache/go-build \ - --mount=type=bind,target=/go/src/github.com/docker/docker \ +RUN --mount=type=cache,target=/root/.cache \ + --mount=type=bind,target=.,ro \ + --mount=type=tmpfs,target=cli/winresources/dockerd \ + --mount=type=tmpfs,target=cli/winresources/docker-proxy \ hack/make.sh dynbinary FROM binary-base AS build-cross ARG DOCKER_CROSSPLATFORMS -RUN --mount=type=cache,target=/root/.cache/go-build \ - --mount=type=bind,target=/go/src/github.com/docker/docker \ - --mount=type=tmpfs,target=/go/src/github.com/docker/docker/autogen \ +RUN --mount=type=cache,target=/root/.cache \ + --mount=type=bind,target=.,ro \ + --mount=type=tmpfs,target=cli/winresources/dockerd \ + --mount=type=tmpfs,target=cli/winresources/docker-proxy \ hack/make.sh cross FROM scratch AS binary diff --git a/Makefile b/Makefile index 4dd3677934..a4ff173782 100644 --- a/Makefile +++ b/Makefile @@ -85,7 +85,8 @@ DOCKER_ENVS := \ -e VERSION \ -e PLATFORM \ -e DEFAULT_PRODUCT_LICENSE \ - -e PRODUCT + -e PRODUCT \ + -e PACKAGER_NAME # note: we _cannot_ add "-e DOCKER_BUILDTAGS" here because even if it's unset in the shell, that would shadow the "ENV DOCKER_BUILDTAGS" set in our Dockerfile, which is very important for our official builds # to allow `make BIND_DIR=. shell` or `make BIND_DIR= test` @@ -158,7 +159,7 @@ ifdef DOCKER_CROSSPLATFORMS BUILD_CROSS = --build-arg CROSS=true endif -VERSION_AUTOGEN_ARGS = --build-arg VERSION --build-arg DOCKER_GITCOMMIT --build-arg PRODUCT --build-arg PLATFORM --build-arg DEFAULT_PRODUCT_LICENSE +VERSION_AUTOGEN_ARGS = --build-arg VERSION --build-arg DOCKER_GITCOMMIT --build-arg PRODUCT --build-arg PLATFORM --build-arg DEFAULT_PRODUCT_LICENSE --build-arg PACKAGER_NAME default: binary diff --git a/cli/winresources/README.md b/cli/winresources/README.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cli/winresources/docker-proxy/winresources.go b/cli/winresources/docker-proxy/winresources.go new file mode 100644 index 0000000000..856ded949f --- /dev/null +++ b/cli/winresources/docker-proxy/winresources.go @@ -0,0 +1,12 @@ +// Package winresources is used to embed Windows resources into docker-proxy.exe. +// +// These resources are used to provide: +// * Version information +// * An icon +// * A Windows manifest declaring Windows version support +// * Events message table +// +// The resource object files are generated when building with go-winres +// in hack/make/.go-autogen and are located in cli/winresources. +// This occurs automatically when you cross build against Windows OS. +package winresources diff --git a/hack/make/.resources-windows/dockerd.ico b/cli/winresources/docker.ico similarity index 100% rename from hack/make/.resources-windows/dockerd.ico rename to cli/winresources/docker.ico diff --git a/cli/winresources/dockerd/winresources.go b/cli/winresources/dockerd/winresources.go new file mode 100644 index 0000000000..b71057bafe --- /dev/null +++ b/cli/winresources/dockerd/winresources.go @@ -0,0 +1,12 @@ +// Package winresources is used to embed Windows resources into dockerd.exe. +// +// These resources are used to provide: +// * Version information +// * An icon +// * A Windows manifest declaring Windows version support +// * Events message table +// +// The resource object files are generated when building with go-winres +// in hack/make/.go-autogen and are located in cli/winresources. +// This occurs automatically when you cross build against Windows OS. +package winresources diff --git a/cli/winresources/event_messages.bin b/cli/winresources/event_messages.bin new file mode 100644 index 0000000000000000000000000000000000000000..8ca3c81969aa72f7e44e1744824ad9eddb87340c GIT binary patch literal 256 zcmZQ#U|?VbViq8l0b*_-<^$pyAm#zes4^HbZ~@seKz0g4Dnk-ODMLDg6@vm?1|nC$ zkjRk7kjapYMJ^2}R|3R2XmS!z^A#APfu "${ROOTDIR}/hack/make/.resources-windows/go.mod" << EOF -module github.com/docker/docker/autogen/winresources/dockerd - -go 1.17 -EOF diff --git a/hack/make/.go-autogen b/hack/make/.go-autogen index 5fe33555a5..bd6215f6a3 100644 --- a/hack/make/.go-autogen +++ b/hack/make/.go-autogen @@ -1,7 +1,5 @@ #!/usr/bin/env bash -rm -rf autogen/* - source hack/dockerfile/install/runc.installer source hack/dockerfile/install/tini.installer source hack/dockerfile/install/containerd.installer @@ -18,45 +16,12 @@ LDFLAGS="${LDFLAGS} \ # Compile the Windows resources into the sources if [ "$(go env GOOS)" = "windows" ]; then - mkdir -p autogen/winresources/tmp autogen/winresources/dockerd - cp hack/make/.resources-windows/resources.go autogen/winresources/dockerd/ - - if [ "$(go env GOHOSTOS)" == "windows" ]; then - WINDRES=windres - WINDMC=windmc - else - # Cross compiling - WINDRES=x86_64-w64-mingw32-windres - WINDMC=x86_64-w64-mingw32-windmc - fi - - # Generate a Windows file version of the form major,minor,patch,build (with any part optional) - if [ ! -v VERSION_QUAD ]; then - VERSION_QUAD=$(echo -n $VERSION | sed -re 's/^([0-9.]*).*$/\1/' | tr . ,) - fi - - # Pass version and commit information into the resource compiler - defs= - [ ! -z $VERSION ] && defs="$defs -D DOCKER_VERSION=\"$VERSION\"" - [ ! -z $VERSION_QUAD ] && defs="$defs -D DOCKER_VERSION_QUAD=$VERSION_QUAD" - [ ! -z $GITCOMMIT ] && defs="$defs -D DOCKER_COMMIT=\"$GITCOMMIT\"" - - function makeres { - ${WINDRES} \ - -i hack/make/.resources-windows/$1 \ - -o $3 \ - -F $2 \ - --use-temp-file \ - -I autogen/winresources/tmp \ - $defs - } - - ${WINDMC} \ - hack/make/.resources-windows/event_messages.mc \ - -h autogen/winresources/tmp \ - -r autogen/winresources/tmp - - makeres dockerd.rc pe-x86-64 autogen/winresources/dockerd/rsrc_amd64.syso - - rm -r autogen/winresources/tmp + if [ ! -x "$(command -v go-winres)" ]; then + >&2 echo "go-winres not found, skipping manifesting binary" + else + ( + . hack/make/.mkwinres + go generate -v "${GO_PACKAGE}" + ) + fi fi diff --git a/hack/make/.mkwinres b/hack/make/.mkwinres new file mode 100644 index 0000000000..d2465e11e4 --- /dev/null +++ b/hack/make/.mkwinres @@ -0,0 +1,85 @@ +#!/usr/bin/env sh + +quadVersionNum() { + num=$(echo "${1:-0}" | cut -d. -f"$2") + if [ "$num" != "0" ]; then + echo "${num#0}" + else + echo "$num" + fi +} + +# Create version quad for Windows of the form major.minor.patch.build +VERSION_QUAD=$(printf "%s" "$VERSION" | sed -re 's/^([0-9.]*).*$/\1/' | sed -re 's/\.$//' | sed -re 's/^[0-9]+$/\0\.0/' | sed -re 's/^[0-9]+\.[0-9]+$/\0\.0/' | sed -re 's/^[0-9]+\.[0-9]+\.[0-9]+$/\0\.0/') + +# Generate winres.json to be able to create a syso file which contains +# Microsoft Windows Version Information and an icon using go-winres. +# https://docs.microsoft.com/en-us/windows/win32/menurc/stringfileinfo-block +# https://github.com/tc-hib/go-winres#json-format +cat > "./cli/winresources/${BINARY_SHORT_NAME}/winres.json" << EOL +{ + "RT_GROUP_ICON": { + "#1": { + "0409": "../../winresources/docker.ico" + } + }, + "RT_MANIFEST": { + "#1": { + "0409": { + "identity": {}, + "description": "Docker Engine", + "minimum-os": "vista", + "execution-level": "", + "ui-access": false, + "auto-elevate": false, + "dpi-awareness": "unaware", + "disable-theming": false, + "disable-window-filtering": false, + "high-resolution-scrolling-aware": false, + "ultra-high-resolution-scrolling-aware": false, + "long-path-aware": false, + "printer-driver-isolation": false, + "gdi-scaling": false, + "segment-heap": false, + "use-common-controls-v6": false + } + } + }, + "RT_MESSAGETABLE": { + "#1": { + "0409": "../../winresources/event_messages.bin" + } + }, + "RT_VERSION": { + "#1": { + "0409": { + "fixed": { + "file_version": "$(quadVersionNum "$VERSION_QUAD" 1).$(quadVersionNum "$VERSION_QUAD" 2).$(quadVersionNum "$VERSION_QUAD" 3).$(quadVersionNum "$VERSION_QUAD" 4)", + "product_version": "$(quadVersionNum "$VERSION_QUAD" 1).$(quadVersionNum "$VERSION_QUAD" 2).$(quadVersionNum "$VERSION_QUAD" 3).$(quadVersionNum "$VERSION_QUAD" 4)", + "type": "Unknown" + }, + "info": { + "0000": { + "CompanyName": "${PACKAGER_NAME}", + "FileVersion": "${VERSION}", + "LegalCopyright": "Copyright © 2015-$(date +'%Y') Docker Inc.", + "OriginalFileName": "$(basename "${BINARY_FULLNAME}")", + "ProductName": "${PRODUCT}", + "ProductVersion": "${VERSION}", + "SpecialBuild": "${GITCOMMIT}" + } + } + } + } + } +} +EOL +( + set -x + cat "./cli/winresources/${BINARY_SHORT_NAME}/winres.json" +) + +# Create winresources package stub if removed while using tmpfs in Dockerfile +if [ ! -f "./cli/winresources/${BINARY_SHORT_NAME}/winresources.go" ]; then + echo "package winresources" > "./cli/winresources/${BINARY_SHORT_NAME}/winresources.go" +fi diff --git a/hack/make/.resources-windows/common.rc b/hack/make/.resources-windows/common.rc deleted file mode 100644 index 3524d9bf48..0000000000 --- a/hack/make/.resources-windows/common.rc +++ /dev/null @@ -1,38 +0,0 @@ -// Application icon -1 ICON "dockerd.ico" - -// Windows executable manifest -1 24 /* RT_MANIFEST */ "dockerd.exe.manifest" - -// Version information -1 VERSIONINFO - -#ifdef DOCKER_VERSION_QUAD -FILEVERSION DOCKER_VERSION_QUAD -PRODUCTVERSION DOCKER_VERSION_QUAD -#endif - -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "000004B0" - BEGIN - VALUE "ProductName", DOCKER_NAME - -#ifdef DOCKER_VERSION - VALUE "FileVersion", DOCKER_VERSION - VALUE "ProductVersion", DOCKER_VERSION -#endif - -#ifdef DOCKER_COMMIT - VALUE "OriginalFileName", DOCKER_COMMIT -#endif - - END - END - - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0000, 0x04B0 - END -END diff --git a/hack/make/.resources-windows/dockerd.exe.manifest b/hack/make/.resources-windows/dockerd.exe.manifest deleted file mode 100644 index 674bc9422b..0000000000 --- a/hack/make/.resources-windows/dockerd.exe.manifest +++ /dev/null @@ -1,18 +0,0 @@ - - - Docker - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/hack/make/.resources-windows/dockerd.rc b/hack/make/.resources-windows/dockerd.rc deleted file mode 100644 index e77fc17519..0000000000 --- a/hack/make/.resources-windows/dockerd.rc +++ /dev/null @@ -1,4 +0,0 @@ -#define DOCKER_NAME "Docker Engine" - -#include "common.rc" -#include "event_messages.rc" diff --git a/hack/make/.resources-windows/resources.go b/hack/make/.resources-windows/resources.go deleted file mode 100644 index 3ade4eadd9..0000000000 --- a/hack/make/.resources-windows/resources.go +++ /dev/null @@ -1,18 +0,0 @@ -/* - -Package winresources is used to embed Windows resources into dockerd.exe. -These resources are used to provide - - * Version information - * An icon - * A Windows manifest declaring Windows version support - -The resource object files are generated in hack/make/.go-autogen from -source files in hack/make/.resources-windows. This occurs automatically -when you run hack/make.sh. - -These object files are picked up automatically by go build when this package -is included. - -*/ -package winresources