Skip to content

Commit 64ea750

Browse files
authored
Fix #241: avoid copying DLL files that already exist under Windows (#242)
1 parent a6f15bf commit 64ea750

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

ue4docker/dockerfiles/ue4-build-prerequisites/windows/Dockerfile

+16-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ ARG DLLSRCIMAGE
44

55
FROM ${DLLSRCIMAGE} as dlls
66

7-
FROM ${BASEIMAGE} as prerequisites
7+
FROM ${BASEIMAGE} as deduplication
88
SHELL ["cmd", "/S", "/C"]
99

10+
{% if not disable_labels %}
11+
# Add a sentinel label so we can easily identify all derived images, including intermediate images
12+
LABEL com.adamrehn.ue4-docker.sentinel="1"
13+
{% endif %}
14+
1015
# Gather the system DLLs that we need from the full Windows base image
1116
COPY --from=dlls `
1217
C:\Windows\System32\avicap32.dll `
@@ -29,7 +34,16 @@ COPY --from=dlls `
2934
C:\Windows\System32\opengl32.dll `
3035
C:\Windows\System32\ResampleDMO.dll `
3136
C:\Windows\System32\ResourcePolicyClient.dll `
32-
C:\Windows\System32\
37+
C:\GatheredDLLs\
38+
39+
# Remove any DLL files that already exist in the target base image, to avoid permission errors when attempting to overwrite existing files with a COPY directive
40+
COPY remove-duplicate-dlls.ps1 C:\remove-duplicate-dlls.ps1
41+
RUN powershell -ExecutionPolicy Bypass -File C:\remove-duplicate-dlls.ps1
42+
43+
# Copy the DLL files into a clean image
44+
FROM ${BASEIMAGE} as prerequisites
45+
SHELL ["cmd", "/S", "/C"]
46+
COPY --from=deduplication C:\GatheredDlls\ C:\Windows\System32\
3347

3448
{% if not disable_labels %}
3549
# Add a sentinel label so we can easily identify all derived images, including intermediate images
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
$dlls = (Get-ChildItem "C:\GatheredDLLs\*.dll")
2+
foreach ($dll in $dlls)
3+
{
4+
$filename = $dll.Name
5+
$existing = (Get-ChildItem "C:\Windows\System32\${filename}" -ErrorAction SilentlyContinue)
6+
if ($existing)
7+
{
8+
[Console]::Error.WriteLine("${filename} already exists in System32 in the target base image, excluding it from the list of DLL files to copy.")
9+
Remove-Item $dll
10+
}
11+
}

0 commit comments

Comments
 (0)