use go-winres for cross to create Windows resources

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2022-04-14 19:52:23 +02:00
parent 61404de7df
commit fd2143e0b0
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
20 changed files with 163 additions and 143 deletions

View file

@ -2,5 +2,6 @@
.go-pkg-cache .go-pkg-cache
.gopath .gopath
bundles bundles
cli/winresources/**/winres.json
cli/winresources/**/*.syso
vendor/pkg vendor/pkg

View file

@ -74,7 +74,6 @@ jobs:
run: | run: |
platform=${{ matrix.platform }} platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
mkdir -p autogen
- -
name: Set up Docker Buildx name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1 uses: docker/setup-buildx-action@v1

2
.gitignore vendored
View file

@ -15,6 +15,8 @@ test.main
.go-pkg-cache/ .go-pkg-cache/
autogen/ autogen/
bundles/ bundles/
cli/winresources/**/winres.json
cli/winresources/**/*.syso
cmd/dockerd/dockerd cmd/dockerd/dockerd
contrib/builder/rpm/*/changelog contrib/builder/rpm/*/changelog
vendor/pkg/ vendor/pkg/

View file

@ -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}" \ GOBIN=/build/ GO111MODULE=on go install "github.com/pelletier/go-toml/cmd/tomll@${GOTOML_VERSION}" \
&& /build/tomll --help && /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 FROM dev-base AS containerd
ARG DEBIAN_FRONTEND ARG DEBIAN_FRONTEND
RUN --mount=type=cache,sharing=locked,id=moby-containerd-aptlib,target=/var/lib/apt \ 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=frozen-images /build/ /docker-frozen-images
COPY --from=swagger /build/ /usr/local/bin/ COPY --from=swagger /build/ /usr/local/bin/
COPY --from=tomll /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=tini /build/ /usr/local/bin/
COPY --from=registry /build/ /usr/local/bin/ COPY --from=registry /build/ /usr/local/bin/
COPY --from=criu /build/ /usr/local/bin/ COPY --from=criu /build/ /usr/local/bin/
@ -346,34 +355,42 @@ ARG PRODUCT
ENV PRODUCT=${PRODUCT} ENV PRODUCT=${PRODUCT}
ARG DEFAULT_PRODUCT_LICENSE ARG DEFAULT_PRODUCT_LICENSE
ENV DEFAULT_PRODUCT_LICENSE=${DEFAULT_PRODUCT_LICENSE} ENV DEFAULT_PRODUCT_LICENSE=${DEFAULT_PRODUCT_LICENSE}
ARG PACKAGER_NAME
ENV PACKAGER_NAME=${PACKAGER_NAME}
ARG DOCKER_BUILDTAGS ARG DOCKER_BUILDTAGS
ENV DOCKER_BUILDTAGS="${DOCKER_BUILDTAGS}" ENV DOCKER_BUILDTAGS="${DOCKER_BUILDTAGS}"
ENV PREFIX=/build ENV PREFIX=/build
# TODO: This is here because hack/make.sh binary copies these extras binaries # TODO: This is here because hack/make.sh binary copies these extras binaries
# from $PATH into the bundles dir. # from $PATH into the bundles dir.
# It would be nice to handle this in a different way. # It would be nice to handle this in a different way.
COPY --from=tini /build/ /usr/local/bin/ COPY --from=tini /build/ /usr/local/bin/
COPY --from=runc /build/ /usr/local/bin/ COPY --from=runc /build/ /usr/local/bin/
COPY --from=containerd /build/ /usr/local/bin/ COPY --from=containerd /build/ /usr/local/bin/
COPY --from=rootlesskit /build/ /usr/local/bin/ COPY --from=rootlesskit /build/ /usr/local/bin/
COPY --from=vpnkit /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 WORKDIR /go/src/github.com/docker/docker
FROM binary-base AS build-binary FROM binary-base AS build-binary
RUN --mount=type=cache,target=/root/.cache/go-build \ RUN --mount=type=cache,target=/root/.cache \
--mount=type=bind,target=/go/src/github.com/docker/docker \ --mount=type=bind,target=.,ro \
--mount=type=tmpfs,target=cli/winresources/dockerd \
--mount=type=tmpfs,target=cli/winresources/docker-proxy \
hack/make.sh binary hack/make.sh binary
FROM binary-base AS build-dynbinary FROM binary-base AS build-dynbinary
RUN --mount=type=cache,target=/root/.cache/go-build \ RUN --mount=type=cache,target=/root/.cache \
--mount=type=bind,target=/go/src/github.com/docker/docker \ --mount=type=bind,target=.,ro \
--mount=type=tmpfs,target=cli/winresources/dockerd \
--mount=type=tmpfs,target=cli/winresources/docker-proxy \
hack/make.sh dynbinary hack/make.sh dynbinary
FROM binary-base AS build-cross FROM binary-base AS build-cross
ARG DOCKER_CROSSPLATFORMS ARG DOCKER_CROSSPLATFORMS
RUN --mount=type=cache,target=/root/.cache/go-build \ RUN --mount=type=cache,target=/root/.cache \
--mount=type=bind,target=/go/src/github.com/docker/docker \ --mount=type=bind,target=.,ro \
--mount=type=tmpfs,target=/go/src/github.com/docker/docker/autogen \ --mount=type=tmpfs,target=cli/winresources/dockerd \
--mount=type=tmpfs,target=cli/winresources/docker-proxy \
hack/make.sh cross hack/make.sh cross
FROM scratch AS binary FROM scratch AS binary

View file

@ -85,7 +85,8 @@ DOCKER_ENVS := \
-e VERSION \ -e VERSION \
-e PLATFORM \ -e PLATFORM \
-e DEFAULT_PRODUCT_LICENSE \ -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 # 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` # to allow `make BIND_DIR=. shell` or `make BIND_DIR= test`
@ -158,7 +159,7 @@ ifdef DOCKER_CROSSPLATFORMS
BUILD_CROSS = --build-arg CROSS=true BUILD_CROSS = --build-arg CROSS=true
endif 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 default: binary

View file

View file

@ -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

View file

Before

Width:  |  Height:  |  Size: 100 KiB

After

Width:  |  Height:  |  Size: 100 KiB

View file

@ -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

Binary file not shown.

View file

@ -0,0 +1,5 @@
//go:generate go-winres make --arch=386,amd64,arm,arm64 --in=../../cli/winresources/docker-proxy/winres.json --out=../../cli/winresources/docker-proxy/resource
package main
import _ "github.com/docker/docker/cli/winresources/docker-proxy"

View file

@ -0,0 +1,5 @@
//go:generate go-winres make --arch=386,amd64,arm,arm64 --in=../../cli/winresources/dockerd/winres.json --out=../../cli/winresources/dockerd/resource
package main
import _ "github.com/docker/docker/cli/winresources/dockerd"

View file

@ -7,9 +7,3 @@ module github.com/docker/docker
go 1.17 go 1.17
EOF EOF
cat > "${ROOTDIR}/hack/make/.resources-windows/go.mod" << EOF
module github.com/docker/docker/autogen/winresources/dockerd
go 1.17
EOF

View file

@ -1,7 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
rm -rf autogen/*
source hack/dockerfile/install/runc.installer source hack/dockerfile/install/runc.installer
source hack/dockerfile/install/tini.installer source hack/dockerfile/install/tini.installer
source hack/dockerfile/install/containerd.installer source hack/dockerfile/install/containerd.installer
@ -18,45 +16,12 @@ LDFLAGS="${LDFLAGS} \
# Compile the Windows resources into the sources # Compile the Windows resources into the sources
if [ "$(go env GOOS)" = "windows" ]; then if [ "$(go env GOOS)" = "windows" ]; then
mkdir -p autogen/winresources/tmp autogen/winresources/dockerd if [ ! -x "$(command -v go-winres)" ]; then
cp hack/make/.resources-windows/resources.go autogen/winresources/dockerd/ >&2 echo "go-winres not found, skipping manifesting binary"
else
if [ "$(go env GOHOSTOS)" == "windows" ]; then (
WINDRES=windres . hack/make/.mkwinres
WINDMC=windmc go generate -v "${GO_PACKAGE}"
else )
# Cross compiling fi
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
fi fi

85
hack/make/.mkwinres Normal file
View file

@ -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

View file

@ -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

View file

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<description>Docker</description>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
</application>
</compatibility>
</assembly>

View file

@ -1,4 +0,0 @@
#define DOCKER_NAME "Docker Engine"
#include "common.rc"
#include "event_messages.rc"

View file

@ -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