RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
curl \
git \
git-lfs \
python3 \
python3-dev \
python3-pip \
shared-mime-info \
software-properties-common \
sudo \
tzdata \
unzip \
xdg-user-dirs \
zip &&\
rm -rf /var/lib/apt/lists/* &&echo''&&echo'RUN directive complete. Docker will now commit the filesystem layer to disk.'&&echo'Note that for large filesystem layers this can take quite some time.'&&echo'Performing filesystem layer commit...'&&echo''
# Install the X11 runtime libraries required by CEF so we can cook Unreal Engine projects that use the WebBrowserWidget plugin
# (Starting in Unreal Engine 5.0, we need these installed before creating an Installed Build to prevent cooking failures related to loading the Quixel Bridge plugin)
RUN apt-get update && apt-get install -y --no-install-recommends \
rm -rf /var/lib/apt/lists/* &&echo''&&echo'RUN directive complete. Docker will now commit the filesystem layer to disk.'&&echo'Note that for large filesystem layers this can take quite some time.'&&echo'Performing filesystem layer commit...'&&echo''
# Install the glibc DSO patch to improve Editor startup times
RUN add-apt-repository -y ppa:slonopotamus/glibc-dso &&\
apt-get update &&\
apt upgrade -y libc6 &&\
rm -rf /var/lib/apt/lists/* &&echo''&&echo'RUN directive complete. Docker will now commit the filesystem layer to disk.'&&echo'Note that for large filesystem layers this can take quite some time.'&&echo'Performing filesystem layer commit...'&&echo''
# Enable the glibc DSO patch
ENVGLIBC_TUNABLES=glibc.rtld.dynamic_sort=2
# Disable the default "lecture" message the first time a user runs a command using sudo
RUNecho'Defaults lecture="never"' >> /etc/sudoers &&echo''&&echo'RUN directive complete. Docker will now commit the filesystem layer to disk.'&&echo'Note that for large filesystem layers this can take quite some time.'&&echo'Performing filesystem layer commit...'&&echo''
# Unreal refuses to run as the root user, so create a non-root user with no password and allow them to run commands using sudo
usermod -a -G audio,video,sudo ue4 &&echo''&&echo'RUN directive complete. Docker will now commit the filesystem layer to disk.'&&echo'Note that for large filesystem layers this can take quite some time.'&&echo'Performing filesystem layer commit...'&&echo''
USERue4
# Enable Git Large File Storage (LFS) support
RUN git lfs install &&echo''&&echo'RUN directive complete. Docker will now commit the filesystem layer to disk.'&&echo'Note that for large filesystem layers this can take quite some time.'&&echo'Performing filesystem layer commit...'&&echo''
RUN chmod +x /tmp/git-credential-helper-secrets.sh &&echo''&&echo'RUN directive complete. Docker will now commit the filesystem layer to disk.'&&echo'Note that for large filesystem layers this can take quite some time.'&&echo'Performing filesystem layer commit...'&&echo''
# Clone the UE4 git repository using the build secret credentials
# (Note that we include the changelist override value here to ensure any cached source code is invalidated if
# the override is modified between runs, which is useful when testing preview versions of the Unreal Engine)
ARG CHANGELIST
RUN --mount=type=secret,id=username,uid=1000,required \
git checkout FETCH_HEAD &&echo''&&echo'RUN directive complete. Docker will now commit the filesystem layer to disk.'&&echo'Note that for large filesystem layers this can take quite some time.'&&echo'Performing filesystem layer commit...'&&echo''
# Run post-clone setup steps, ensuring our package lists are up to date since Setup.sh doesn't call `apt-get update`
# When running with BuildKit, we use a cache mount to cache the dependency data in `.git/ue4-gitdeps` across multiple build invocations
WORKDIR/home/ue4/UnrealEngine
RUN --mount=type=cache,target=/home/ue4/UnrealEngine/.git/ue4-gitdeps,uid=1000,gid=1000 sudo apt-get update &&\
./Setup.sh &&\
sudo rm -rf /var/lib/apt/lists/* &&echo''&&echo'RUN directive complete. Docker will now commit the filesystem layer to disk.'&&echo'Note that for large filesystem layers this can take quite some time.'&&echo'Performing filesystem layer commit...'&&echo''
FROMsourceasbuilder
# Set the changelist number in Build.version to ensure our Build ID is generated correctly
ARG CHANGELIST
COPY set-changelist.py /tmp/set-changelist.py
RUN python3 /tmp/set-changelist.py /home/ue4/UnrealEngine/Engine/Build/Build.version $CHANGELIST&&echo''&&echo'RUN directive complete. Docker will now commit the filesystem layer to disk.'&&echo'Note that for large filesystem layers this can take quite some time.'&&echo'Performing filesystem layer commit...'&&echo''
# Remove the .git directory to disable UBT `git status` calls and speed up the build process
RUN rm -rf /home/ue4/UnrealEngine/.git &&echo''&&echo'RUN directive complete. Docker will now commit the filesystem layer to disk.'&&echo'Note that for large filesystem layers this can take quite some time.'&&echo'Performing filesystem layer commit...'&&echo''
rm -R -f /home/ue4/UnrealEngine/LocalBuilds/InstalledDDC &&echo''&&echo'RUN directive complete. Docker will now commit the filesystem layer to disk.'&&echo'Note that for large filesystem layers this can take quite some time.'&&echo'Performing filesystem layer commit...'&&echo''
# Split out components (DDC, debug symbols, template projects) so they can be copied into the final container image as separate filesystem layers
COPY split-components.py /tmp/split-components.py
RUN python3 /tmp/split-components.py /home/ue4/UnrealEngine/LocalBuilds/Engine/Linux /home/ue4/UnrealEngine/Components &&echo''&&echo'RUN directive complete. Docker will now commit the filesystem layer to disk.'&&echo'Note that for large filesystem layers this can take quite some time.'&&echo'Performing filesystem layer commit...'&&echo''
# Copy the Installed Build into a clean image, discarding the source build
FROMprerequisitesasminimal
# Copy the Installed Build files from the builder image
# Perform first-run setup for Mono, UnrealBuildTool and AutomationTool, which makes it possible to build Unreal projects and plugins as users other than `ue4`
# (Note that this will only work with 4.26.0 and newer, older Engine versions will always require write access to `/home/ue4/UnrealEngine`)
# See the comments on this issue for details, including the need to ensure $HOME is set correctly: <https://github.com/adamrehn/ue4-docker/issues/141>
RUN ./Engine/Build/BatchFiles/Linux/Build.sh UnrealHeaderTool Linux Development -SkipBuild &&\
chmod a+rw ./Engine/Programs/AutomationTool/Saved &&echo''&&echo'RUN directive complete. Docker will now commit the filesystem layer to disk.'&&echo'Note that for large filesystem layers this can take quite some time.'&&echo'Performing filesystem layer commit...'&&echo''
# Enable Vulkan support for NVIDIA GPUs
USERroot
RUN apt-get update && apt-get install -y --no-install-recommends libvulkan1 &&\
}" > /etc/vulkan/icd.d/nvidia_icd.json && echo '' && echo 'RUN directive complete. Docker will now commit the filesystem layer to disk.' && echo 'Note that for large filesystem layers this can take quite some time.' && echo 'Performing filesystem layer commit...' && echo ''