Skip to content

Commit

Permalink
Updated docker support for source build.
Browse files Browse the repository at this point in the history
  • Loading branch information
WouterJansen committed Oct 3, 2024
1 parent fbf925e commit ff63b1b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 128 deletions.
25 changes: 15 additions & 10 deletions docker/Dockerfile_source
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@ ARG BASE_IMAGE=ghcr.io/epicgames/unreal-engine:dev-5.4.3
FROM $BASE_IMAGE

USER root
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --no-install-recommends \
RUN DEBIAN_FRONTEND=noninteractive apt-get update

RUN apt-get install -y --no-install-recommends \
python3 \
python3-pip \
rsync \
sudo \
wget \
x11-xserver-utils
wget \
sudo

RUN apt-get install -y --upgrade cmake

RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers && \
adduser ue5 sudo
RUN python3 -m pip install --upgrade pip && \
pip3 install cosysairsim

USER ue5
RUN cd /home/ue5 && \
USER ue4
RUN cd /home/ue4 && \
git clone --progress https://github.com/Cosys-Lab/Cosys-AirSim.git && \
cd AirSim && \
cd Cosys-AirSim && \
./setup.sh && \
./build.sh

WORKDIR /home/ue5
WORKDIR /home/ue4
59 changes: 3 additions & 56 deletions docker/run_airsim_image_source.sh
Original file line number Diff line number Diff line change
@@ -1,66 +1,13 @@
#!/bin/bash

# This is to determine Docker version for the command
version_less_than_equal_to() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" = "$1"; }

REQ_DOCKER_VERSION=19.03
docker_version=$(docker -v | cut -d ' ' -f3 | sed 's/,$//')

if version_less_than_equal_to $REQ_DOCKER_VERSION $docker_version; then
# Use the normal docker command
DOCKER_CMD="docker run --gpus all"
else
# Use nvidia-docker
DOCKER_CMD="nvidia-docker run --runtime=nvidia"
fi

# this block is for running X apps in docker
XAUTH=/tmp/.docker.xauth
if [ ! -f $XAUTH ]
then
xauth_list=$(xauth nlist :0 | sed -e 's/^..../ffff/')
if [ ! -z "$xauth_list" ]
then
echo $xauth_list | xauth -f $XAUTH nmerge -
else
touch $XAUTH
fi
chmod a+r $XAUTH
fi

DOCKER_IMAGE_NAME=$1

# now let's check if user specified an "-- headless" parameter in the end
# we'll set SDL_VIDEODRIVER_VALUE to '' if it wasn't specified, 'offscreen' if it was
SDL_VIDEODRIVER_VALUE='';
while [ -n "$1" ]; do
case "$1" in
--)
shift
break
;;
esac
shift
done

for param in $@; do
case "$param" in
headless) SDL_VIDEODRIVER_VALUE='offscreen' ;;
esac
done
DOCKER_CMD="docker run --gpus=all -v/tmp/.X11-unix:/tmp/.X11-unix:rw -e DISPLAY -v /home/$UID/.Xauthority:/home/ue4/.Xauthority \
-e XAUTHORITY=/home/ue4/.Xauthority "

# now, let's mount the user directory which points to the unreal binary (UNREAL_BINARY_PATH)
# set the environment varible SDL_VIDEODRIVER to SDL_VIDEODRIVER_VALUE
# and tell the docker container to execute UNREAL_BINARY_COMMAND
$DOCKER_CMD -it \
-v $(pwd)/settings.json:/home/airsim_user/Documents/AirSim/settings.json \
-e SDL_VIDEODRIVER=$SDL_VIDEODRIVER_VALUE \
-e SDL_HINT_CUDA_DEVICE='0' \
--net=host \
--env="DISPLAY=$DISPLAY" \
--env="QT_X11_NO_MITSHM=1" \
--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
-env="XAUTHORITY=$XAUTH" \
--volume="$XAUTH:$XAUTH" \
-v $(pwd)/settings.json:/home/ue4/Documents/AirSim/settings.json \
--rm \
$DOCKER_IMAGE_NAME
101 changes: 39 additions & 62 deletions docs/docker_ubuntu.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Cosys-AirSim on Docker in Linux
We've two options for docker. You can either build an image for running [airsim linux binaries](#binaries), or for compiling Unreal Engine + Cosys-AirSim [from source](#source).
We've two options for docker. You can either build an image for running [Cosys-AirSim binaries](#runtime-binaries), or for compiling Cosys-AirSim [from source](#source).

## Binaries
## Runtime Binaries

#### Requirements:
- [Follow this guide for preparing setting up your GitHub access, installing Docker and authenticating with the GitHub Container Registry.](https://dev.epicgames.com/documentation/en-us/unreal-engine/quick-start-guide-for-using-container-images-in-unreal-engine).
- [And this guide for installing Nvidia Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html).

#### Build the docker image
- Below are the default arguments.
`--base_image`: This is image over which we'll install airsim. We've tested only the official Unreal Engine runtime container, more info can be found [here](https://dev.epicgames.com/documentation/en-us/unreal-engine/overview-of-containers-in-unreal-engine). Change the base image at your own risk.
`--base_image`: This is image over which we'll run a runtime packaged binary. We've tested only the official Unreal Engine runtime container, more info can be found [here](https://dev.epicgames.com/documentation/en-us/unreal-engine/overview-of-containers-in-unreal-engine). Change the base image at your own risk.
`--target_image` is the desired name of your docker image.
Defaults to `airsim_binary` with same tag as the base image.

Expand Down Expand Up @@ -56,76 +56,61 @@ xhost +local:docker

## Source
#### Requirements:
- [Follow this guide](https://dev.epicgames.com/documentation/en-us/unreal-engine/quick-start-guide-for-using-container-images-in-unreal-engine).


#### Build Unreal Engine inside docker:
- To get access to Unreal Engine's source code, register on Epic Games' website and link it to your github account, as explained in the `Required Steps` section [here](https://docs.unrealengine.com/en-us/Platforms/Linux/BeginnerLinuxDeveloper/SettingUpAnUnrealWorkflow).

Note that you don't need to do `Step 2: Downloading UE4 on Linux`!

- Build unreal engine 4.19.2 docker image. We're going to use CUDA 10.0 in our example.
`$ ue4-docker build 4.19.2 --cuda=10.0 --no-full`
- [optional] `$ ue4-docker clean` to free up some space. [Details here](https://docs.adamrehn.com/ue4-docker/commands/clean)
- `ue4-docker` supports all CUDA version listed on NVIDIA's cudagl dockerhub [here](https://hub.docker.com/r/nvidia/cudagl/).
- Please see [this page](https://docs.adamrehn.com/ue4-docker/building-images/advanced-build-options) for advanced configurations using `ue4-docker`

- Disk space:
- The unreal images and containers can take up a lot of space, especially if you try more than one version.
- Here's a list of useful links to monitor space used by docker and clean up intermediate builds:
- [Large container images primer](https://docs.adamrehn.com/ue4-docker/read-these-first/large-container-images-primer)
- [`docker system df`](https://docs.docker.com/engine/reference/commandline/system_df/)
- [`docker container prune`](https://docs.docker.com/engine/reference/commandline/container_prune/)
- [`docker image prune`](https://docs.docker.com/engine/reference/commandline/image_prune/)
- [`docker system prune`](https://docs.docker.com/engine/reference/commandline/system_prune/)

#### Building Colosseum inside UE4 docker container:
* Build Colosseum docker image (which lays over the unreal image we just built)
Below are the default arguments.
- `--base_image`: This is image over which we'll install airsim. We've tested on `adamrehn/ue4-engine:4.19.2-cudagl10.0`. See [ue4-docker](https://docs.adamrehn.com/ue4-docker/building-images/available-container-images) for other versions.
- `--target_image` is the desired name of your docker image.
- [Follow this guide for preparing setting up your GitHub access, installing Docker and authenticating with the GitHub Container Registry.](https://dev.epicgames.com/documentation/en-us/unreal-engine/quick-start-guide-for-using-container-images-in-unreal-engine).
- [And this guide for installing Nvidia Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html).

#### Building Cosys-AirSim inside UE5 dev docker container:
- Below are the default arguments.
`--base_image`: This is image over which we'll install Cosys-AirSim. We've tested only the official Unreal Engine dev container, more info can be found [here](https://dev.epicgames.com/documentation/en-us/unreal-engine/overview-of-containers-in-unreal-engine). Change the base image at your own risk. This image includes everything needed and includes a pre-installed Unreal Engine and editor.
`--target_image` is the desired name of your docker image.
Defaults to `airsim_source` with same tag as the base image

```bash
$ cd Airsim/docker;
$ python build_airsim_image.py \
--source \
----base_image adamrehn/ue4-engine:4.19.2-cudagl10.0 \
--target_image=airsim_source:4.19.2-cudagl10.0
----base_image ghcr.io/epicgames/unreal-engine:dev-5.4.3 \
--target_image=airsim_source:dev-5.4.3
```

#### Running Colosseum container
#### Running Cosys-AirSim container
* Run the airsim source image we built by:

```bash
./run_airsim_image_source.sh airsim_source:4.19.2-cudagl10.0
xhost +local:docker
./run_airsim_image_source.sh airsim_source:dev-5.4.3
```

Syntax is `./run_airsim_image_source.sh DOCKER_IMAGE_NAME -- headless`
`-- headless`: suffix this to run in optional headless mode.
Syntax is `./run_airsim_image_source.sh DOCKER_IMAGE_NAME`
Do not forget to run the xhost command first to bind the X11 to docker.

* Inside the container, you can see `UnrealEngine` and `Colosseum` under `/home/ue4`.
* Inside the container, you can see `UnrealEngine` and `Cosys-AirSim` under `/home/ue4`.
* Start unreal engine inside the container:
`ue4@HOSTMACHINE:~$ /home/ue4/UnrealEngine/Engine/Binaries/Linux/UE4Editor`
`/home/ue4/UnrealEngine/Engine/Binaries/Linux/UnrealEditor`
* [Specifying an airsim settings.json](#specifying-settingsjson)
* Continue with [Colosseum's Linux docs](build_linux.md#build-unreal-environment).
* Continue with [Cosys-AirSims's Linux docs](build_linux.md#build-unreal-environment).
For example start the Blocks environment in the container run (This will first copy the plugin and afterwards start open the project with the Unreal Editor):
```bash
/home/ue4/Cosys-AirSim/Unreal/Environments/Blocks/update_from_git.sh
/home/ue4/UnrealEngine/Engine/Binaries/Linux/UnrealEditor /home/ue4/Cosys-AirSim/Unreal/Environments/Blocks/Blocks.uproject
```

#### [Misc] Packaging Unreal Environments in `airsim_source` containers
#### Packaging Unreal Environments in `airsim_source` containers
* Let's take the Blocks environment as an example.
In the following script, specify the full path to your unreal uproject file by `project` and the directory where you want the binaries to be placed by `archivedirectory`

```bash
$ /home/ue4/UnrealEngine/Engine/Build/BatchFiles/RunUAT.sh BuildCookRun -platform=Linux -clientconfig=Shipping -serverconfig=Shipping -noP4 -cook -allmaps -build -stage -prereqs -pak -archive \
-archivedirectory=/home/ue4/Binaries/BlocksV2/ \
-project=/home/ue4/Colosseum/Unreal/Environments/BlocksV2/BlocksV2.uproject
/home/ue4/UnrealEngine/Engine/Build/BatchFiles/RunUAT.sh BuildCookRun -platform=Linux -clientconfig=Development -serverconfig=Development -noP4 -cook -allmaps -build -stage -prereqs -pak -archive \
-archivedirectory=/home/ue4/Binaries/Blocks/ \
-project=/home/ue4/Cosys-AirSim/Unreal/Environments/Blocks/Blocks.uproject
```

This would create a Blocks binary in `/home/ue4/Binaries/BlocksV2/`.
You can test it by running `/home/ue4/Binaries/BlocksV2/LinuxNoEditor/BlocksV2.sh -windowed`
This would create a Blocks binary in `/home/ue4/Binaries/Blocks/`.
You can test it by running `/home/ue4/Binaries/Blocks/LinuxNoEditor/Blocks.sh -windowed`

## Specifying settings.json
#### `airsim_binary` docker image:
- We're mapping the host machine's `PATH/TO/Airsim/docker/settings.json` to the docker container's `/home/airsim_user/Documents/airsim/settings.json`.
- We're mapping the host machine's `PATH/TO/Airsim/settings.json` to the docker container's `/home/airsim_user/Documents/airsim/settings.json`.
- Hence, we can load any settings file by simply modifying `PATH_TO_YOUR/settings.json` by modifying the following snippets in [`run_airsim_image_binary.sh`](https://github.com/Cosys-Lab/Cosys-AirSim/blob/main/docker/run_airsim_image_binary.sh) to link `$PATH_TO_YOUR` to the correct folder.

```sh
Expand All @@ -139,20 +124,12 @@ $DOCKER_IMAGE_NAME \

#### `airsim_source` docker image:

* We're mapping the host machine's `PATH/TO/Cosys-AirSim/docker/settings.json` to the docker container's `/home/airsim_user/Documents/airsim/settings.json`.
* We're mapping the host machine's `PATH/TO/Cosys-AirSim/settings.json` to the docker container's `/home/ue4/Documents/airsim/settings.json`.
* Hence, we can load any settings file by simply modifying `PATH_TO_YOUR/settings.json` by modifying the following snippets in [`run_airsim_image_source.sh`](https://github.com/Cosys-Lab/Cosys-AirSim/blob/main/docker/run_airsim_image_source.sh):

```bash
nvidia-docker run --runtime=nvidia -it \
-v $(pwd)/settings.json:/home/airsim_user/Documents/airsim/settings.json \
-e SDL_VIDEODRIVER=$SDL_VIDEODRIVER_VALUE \
-e SDL_HINT_CUDA_DEVICE='0' \
--net=host \
--env="DISPLAY=$DISPLAY" \
--env="QT_X11_NO_MITSHM=1" \
--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
-env="XAUTHORITY=$XAUTH" \
--volume="$XAUTH:$XAUTH" \
--rm \
$DOCKER_IMAGE_NAME
```
```sh
$DOCKER_CMD -it \
-v $PATH_TO_YOUR/settings.json:/home/ue4/Documents/AirSim/settings.json \
--rm \
$DOCKER_IMAGE_NAME
```

0 comments on commit ff63b1b

Please sign in to comment.