Skip to content

Commit

Permalink
Copy netapi32.dll from servercore image in nano-based Windows image (
Browse files Browse the repository at this point in the history
…#9006)

To fix the following failure:
```
panic: Failed to load netapi32.dll: The specified module could not be found.

goroutine 1 [running]:
syscall.(*LazyProc).mustFind(...)
	c:/go/src/syscall/dll_windows.go:320
syscall.(*LazyProc).Addr(...)
	c:/go/src/syscall/dll_windows.go:327
syscall.NetGetJoinInformation(0x0, 0xc00061fa48, 0xc00061fa44, 0x16, 0xc0000c96e0)
	c:/go/src/syscall/zsyscall_windows.go:1804 +0x107
os/user.isDomainJoined(0xc00061faa0, 0xf3624e, 0x0)
	c:/go/src/os/user/lookup_windows.go:18 +0x5a
os/user.lookupFullName(0xc000063b30, 0xc, 0xc000259bc0, 0x16, 0xc0000c96e0, 0x23, 0x16, 0xc0000c96e0, 0x23, 0x1)
	c:/go/src/os/user/lookup_windows.go:51 +0x2d
os/user.newUser(0xc000063ad0, 0xc, 0xc000063b10, 0xc, 0xc0000c9680, 0x1f, 0xc000259bc0, 0x16, 0xc000063b30, 0xc, ...)
	c:/go/src/os/user/lookup_windows.go:181 +0xd4
os/user.current(0x0, 0x0, 0x0)
	c:/go/src/os/user/lookup_windows.go:225 +0x2d8
os/user.Current.func1()
	c:/go/src/os/user/lookup.go:15 +0x29
sync.(*Once).doSlow(0x593ff00, 0x40b75b0)
	c:/go/src/sync/once.go:66 +0xf7
sync.(*Once).Do(...)
	c:/go/src/sync/once.go:57
os/user.Current(0xc0002599c0, 0x1b, 0x3f56005)
	c:/go/src/os/user/lookup.go:15 +0x105
github.com/golang/glog.init.1()
	C:/gomodcache/github.com/golang/[email protected]/gomodcache/github.com/golang/[email protected]/glog_file.go:63 +0x4b
```

This ugly hack is needed because the [bump of github.com/dgraph-io/ristretto from 0.0.3 to 0.1.0][1]
[introduced a new dependency to `glog`][2] which is triggering the following issue with
the Windows nano docker image: [3]

Once [3] is solved, this hack can be reverted.

[1] #8500
[2] dgraph-io/ristretto#263
[3] microsoft/Windows-Containers#72
  • Loading branch information
L3n41c authored Aug 31, 2021
1 parent fd9e691 commit 89b2770
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 4 additions & 4 deletions .gitlab/image_build/docker_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
needs: ["windows_msi_and_bosh_zip_x64-a7", "build_windows_container_entrypoint"]
variables:
AGENT_ZIP: "datadog-agent-7*-x86_64.zip"
BUILD_ARG: "--build-arg BASE_IMAGE=mcr.microsoft.com/powershell:nanoserver-${VARIANT} --build-arg WITH_JMX=${WITH_JMX} --build-arg VARIANT=${VARIANT}"
BUILD_ARG: "--build-arg BASE_IMAGE=mcr.microsoft.com/powershell:nanoserver-${VARIANT} --build-arg NETAPI32_IMAGE=mcr.microsoft.com/powershell:windowsservercore-${VARIANT} --build-arg WITH_JMX=${WITH_JMX} --build-arg VARIANT=${VARIANT}"
TARGET_TAG: "${IMAGE}:v${CI_PIPELINE_ID}-${CI_COMMIT_SHORT_SHA}${TAG_SUFFIX}-win${VARIANT}-amd64"

.docker_build_agent6_windows_common:
Expand All @@ -77,21 +77,21 @@
needs: ["windows_msi_x64-a6", "build_windows_container_entrypoint"]
variables:
AGENT_ZIP: "datadog-agent-6*-x86_64.zip"
BUILD_ARG: "--build-arg BASE_IMAGE=mcr.microsoft.com/powershell:nanoserver-${VARIANT} --build-arg WITH_JMX=${WITH_JMX} --build-arg VARIANT=${VARIANT}"
BUILD_ARG: "--build-arg BASE_IMAGE=mcr.microsoft.com/powershell:nanoserver-${VARIANT} --build-arg NETAPI32_IMAGE=mcr.microsoft.com/powershell:windowsservercore-${VARIANT} --build-arg WITH_JMX=${WITH_JMX} --build-arg VARIANT=${VARIANT}"
TARGET_TAG: "${IMAGE}:v${CI_PIPELINE_ID}-${CI_COMMIT_SHORT_SHA}${TAG_SUFFIX}-win${VARIANT}-amd64"

.docker_build_agent6_windows_servercore_common:
extends:
- .docker_build_agent6_windows_common
variables:
BUILD_ARG: "--build-arg BASE_IMAGE=mcr.microsoft.com/powershell:windowsservercore-${VARIANT} --build-arg WITH_JMX=${WITH_JMX} --build-arg VARIANT=${VARIANT}"
BUILD_ARG: "--build-arg BASE_IMAGE=mcr.microsoft.com/powershell:windowsservercore-${VARIANT} --build-arg NETAPI32_IMAGE=mcr.microsoft.com/powershell:windowsservercore-${VARIANT} --build-arg WITH_JMX=${WITH_JMX} --build-arg VARIANT=${VARIANT}"
TARGET_TAG: "${IMAGE}:v${CI_PIPELINE_ID}-${CI_COMMIT_SHORT_SHA}${TAG_SUFFIX}-win${VARIANT}-servercore-amd64"

.docker_build_agent7_windows_servercore_common:
extends:
- .docker_build_agent7_windows_common
variables:
BUILD_ARG: "--build-arg BASE_IMAGE=mcr.microsoft.com/powershell:windowsservercore-${VARIANT} --build-arg WITH_JMX=${WITH_JMX} --build-arg VARIANT=${VARIANT}"
BUILD_ARG: "--build-arg BASE_IMAGE=mcr.microsoft.com/powershell:windowsservercore-${VARIANT} --build-arg NETAPI32_IMAGE=mcr.microsoft.com/powershell:windowsservercore-${VARIANT} --build-arg WITH_JMX=${WITH_JMX} --build-arg VARIANT=${VARIANT}"
TARGET_TAG: "${IMAGE}:v${CI_PIPELINE_ID}-${CI_COMMIT_SHORT_SHA}${TAG_SUFFIX}-win${VARIANT}-servercore-amd64"

include:
Expand Down
14 changes: 13 additions & 1 deletion Dockerfiles/agent/windows/amd64/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
ARG BASE_IMAGE=mcr.microsoft.com/powershell:lts-windowsservercore-1809
FROM ${BASE_IMAGE}
ARG NETAPI32_IMAGE=mcr.microsoft.com/powershell:lts-windowsservercore-1809

FROM ${NETAPI32_IMAGE} AS netapi32

FROM ${BASE_IMAGE} AS final
# This "copy netapi32.dll" hack can be reverted once https://github.com/microsoft/Windows-Containers/issues/72 is fixed.
COPY --from=netapi32 /Windows/System32/netapi32.dll /netapi32.dll

ARG WITH_JMX="false"
ARG VARIANT="unknown"
Expand All @@ -10,6 +16,12 @@ USER ContainerAdministrator

SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop';"]

RUN if (-not (Test-Path /Windows/System32/netapi32.dll)) { \
Move-Item /netapi32.dll -Destination /Windows/System32/netapi32.dll \
} else { \
Remove-Item /netapi32.dll \
}

COPY datadog-agent-latest.amd64.zip install.ps1 ./
RUN . ./install.ps1

Expand Down

0 comments on commit 89b2770

Please sign in to comment.