(4-27) How to build Unreal project in a development container in docker in docker?

Hello,

there is documentation about building Unreal Engine 4 projects in a development container:

Container QuickStart

This works fine for me locally:

$ docker run \
    --rm -ti -v "$(pwd):/project" \
    ghcr.io/epicgames/unreal-engine:dev-4.27 \
    /home/ue4/UnrealEngine/Engine/Build/BatchFiles/RunUAT.sh \
    BuildCookRun \
    -utf8output -platform=Linux \
    -clientconfig=Shipping -serverconfig=Shipping \
    -project=/project/VR_Frontend.uproject \
    -noP4 \
    -nodebuginfo -allmaps \
    -cook \
    -build \
    -stage \
    -prereqs \
    -pak \
    -archive \
    -archivedirectory=/project/Packaged

However, when I run the same command in a job of a GitLab continuous integration pipeline on the same code in a Docker-in-Docker (dind) image, I cannot mount the volume:

$ docker run
      --rm \
      --volume $PROJECT_PATH:/home/ue4/UnrealEngine/VR_Frontend/ -w \
     /home/ue4/UnrealEngine/VR_Frontend/ -i \
      ghcr.io/epicgames/unreal-engine:dev-4.27 \
      ls -A /home/ue4/UnrealEngine/VR_Frontend
tmp.eMGbml

I have already tried specifying the --volumes-from command line flag, but that does not make a difference:

$ docker run \
    --rm \
    --volume $PROJECT_PATH:/home/ue4/UnrealEngine/VR_Frontend/ \
    -w /home/ue4/UnrealEngine/VR_Frontend/ \
    -i ghcr.io/epicgames/unreal-engine:dev-4.27 \
    ls -A
tmp.eMGbml

Please document a way to build unreal projects in GitLab CI using the development containers.

My current idea is to do it the other way around:

  • Make GitLab CI build a Dockerfile.
  • Base said Dockerfile on the development Unreal image
  • install git
  • clone my Unreal project content repository into the container
  • do not upload the image to the GitLab project registry
  • copy the compiled contents from the built docker image to the CI environment
  • configure GitLab CI to store the compiled contents as artifacts

This seems cumbersome. Is there a better way?

Another idea: Don’t mount, copy!

  • Start the Unreal development image with an entry point of sleep infinity.
  • Copy the Unreal application files to the image.
  • Run the BuildCookRun command on the image.
  • Copy the compiled files to the host.
  • Add the compiled files to GitLab’s artifacts.

I figured it out. Here is a job that can compile an Unreal project down to a Linux executable:

build-UE4.27:
  artifacts:
    paths:
      - archived/
    expire_in: never
  image: docker:latest
  stage: build
  services:
    - docker:dind
  before_script:
    - echo $GHCR_TOKEN | docker login ghcr.io -u ANONYMOUS --password-stdin
  script:
    - export CONTAINER_NAME=Container-for-job-$CI_JOB_ID
    - docker run --rm -d --name $CONTAINER_NAME ghcr.io/epicgames/unreal-engine:dev-4.27 sleep infinity
    - docker exec --interactive --user root $CONTAINER_NAME mkdir /project/
    - docker exec --interactive --user root $CONTAINER_NAME chown ue4:ue4 /project/
    - docker cp . $CONTAINER_NAME:/project/
    - docker exec
      -i
      --workdir /
      $CONTAINER_NAME
      /home/ue4/UnrealEngine/Engine/Build/BatchFiles/RunUAT.sh
        BuildCookRun
        -utf8output
        -platform=Linux
        -clientconfig=Shipping
        -serverconfig=Shipping
        -project=/project/VR_Frontend.uproject
        -noP4
        -nodebuginfo
        -allmaps
        -cook
        -build
        -stage
        -prereqs
        -pak
        -archive
        -archivedirectory=/project/archived
    - docker exec --interactive --user root $CONTAINER_NAME ls /project/archived
    - docker cp $CONTAINER_NAME:/project/archived archived/
    - docker rm --force $CONTAINER_NAME