diff --git a/.gitignore b/.gitignore index 7ceb7149d91..8e55d495342 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ Plugins !Unreal/CarlaUE4/Plugins Unreal/CarlaUE4/Plugins/Streetmap Unreal/CarlaUE4/Plugins/HoudiniEngine +build/ /ExportedMaps @@ -50,3 +51,6 @@ _out* _site core profiler.csv +.env +.venv +devcontainer.json diff --git a/CHANGELOG.md b/CHANGELOG.md index bb78367e65b..0e6ccc48946 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ ## Latest Changes + * Renamed Ubuntu 18-based Dockerfile to CarlaLegacy for clarity + * Created documentation for using devcontainers + * Ensured CARLA scripts consistently use python3 + * Replaced wget with curl for FBX SDK downloads + * Enabled mounting of UE4 from the host when running CARLA inside a container + * Added support for GUI inside containers with Ubuntu 22 image * Fixed waypoint.next and .previous causing loops when two opposite-direction lanes follow each other in the map. * Fixed a bug that caused navigation information not to be loaded when switching maps * Prevent from segfault on failing SignalReference identification when loading OpenDrive files diff --git a/Docs/build_docker.md b/Docs/build_docker.md index a276f724ab6..651e241cb4a 100644 --- a/Docs/build_docker.md +++ b/Docs/build_docker.md @@ -100,3 +100,15 @@ Any issues or doubts related with this topic can be posted in the CARLA forum. CARLA forum

+ +--- + +## Devcontainer: Ubuntu 22.04 based image + +_These instructions have been tested in **Ubuntu 24.04**._ + +The following documentation is intended to explain how to build a Docker image that uses **Ubuntu 22.04** to compile Carla. + +- [CARLA Docker Dev Environment (Ubuntu 22.04)](./build_docker_ubuntu22.md) + +--- \ No newline at end of file diff --git a/Docs/build_docker_ubuntu22.md b/Docs/build_docker_ubuntu22.md new file mode 100644 index 00000000000..cb3830f4e21 --- /dev/null +++ b/Docs/build_docker_ubuntu22.md @@ -0,0 +1,246 @@ +# CARLA Docker Dev Environment (Ubuntu 22.04) + +This repository provides **two** distinct Docker-based approaches for building and running **CARLA (version UE4)** on **Ubuntu Jammy (22.04)**: + +1. **Monolithic** + - Bundles Unreal Engine (UE4) and CARLA into a single Docker image. + - Requires a lengthy build process and produces a large final image (often 100+ GB). + - Creates a fully self-contained environment with everything compiled inside Docker. + +2. **Lightweight Devcontainer** + - Installs only the dependencies (plus NVIDIA support) required to compile and run CARLA. + - Requires mounting an existing **UE4** build from the host into the container (see [Build UE4 for Devcontainer Option](#build-ue4-prerequisite-for-lightweight--devcontainer)). + - Much faster to build but relies on a locally compiled Unreal Engine folder. + +Your choice between **monolithic** and **lightweight** depends primarily on disk space, build times, and whether you prefer a fully self-contained environment (monolithic) or a setup that reuses a locally compiled Unreal Engine (lightweight). + +--- + +## Overview + +Two main scripts in the `Scripts/` directory manage building and launching the Docker containers: + +1. **`run_container.sh`** + - Detects **monolithic** or **lightweight** mode via the `--monolith` (or `-m`) argument. + - If `--monolith` is present, uses `carla-ue4.dockerfile` (monolithic). Otherwise, defaults to `carla.dockerfile` (lightweight). + +2. **`build_image.sh`** + - Generally called indirectly by `run_container.sh`. + - Checks whether `--monolith` was provided and chooses the corresponding Dockerfile. + - Handles Epic credentials (from a `.env` file) needed for cloning and building Unreal Engine in the monolithic mode. + +--- + +## Dockerfiles in `Util/Docker/` + +### `carla.dockerfile` (Lightweight / Devcontainer) + +- Installs only CARLA dependencies, plus NVIDIA GPU support. +- **Excludes** Unreal Engine; instead, a precompiled UE4 folder (matching Carla’s requirements) must be mounted from the host via `UE4_ROOT`. +- Ideal for developers who already have a compatible UE4 build and want faster builds with smaller images. + +### `carla-ue4.dockerfile` (Monolithic) + +- Clones Unreal Engine from Epic’s private GitHub (requires valid Epic credentials). **If you don't have this set up, please follow [this guide](https://www.unrealengine.com/en-US/ue4-on-github) before going any further**. +- Compiles UE4 and then CARLA within a single Docker image, which may exceed 100 GB and take multiple hours to build. +- The image **retains** the `Dist/` directory, enabling you to run or extract the packaged CARLA binaries without additional scripts like `docker_tools.py` in comparison to `CarlaLegacy.Dockefile`. Although this makes the final image large, modern hardware generally has sufficient resources (e.g., larger SSDs, more RAM) to handle this scale. It also eliminates the need to repeatedly rebuild or rely on external tooling. + +You can extract the CARLA package from a monolithic image using a simple Docker command sequence (replacing `0.9.15.2` with your CARLA version): + +```bash +docker create --name temp_container carla-0.9.15.2-ue4-jammy-dev +docker cp temp_container:/workspaces/carla-0.9.15.2/Dist/CARLA_$(docker run --rm carla-0.9.15.2-ue4-jammy-dev ls /workspaces/carla-0.9.15.2/Dist | grep CARLA_).tar.gz . +docker rm temp_container +``` + +If disk usage is a concern and you do not need the final packaged artifacts, you can comment out `make build.utils` and `make package` in `carla-ue4.dockerfile`, or switch to the lightweight approach. + +--- + +## Build UE4 (Prerequisite for Lightweight / Devcontainer) + +> Note: Ensure your GitHub account is linked to Epic’s UnrealEngine repository before attempting to clone. + +If you plan to use the **lightweight** approach, you need a **compiled** Unreal Engine folder on your host that matches CARLA’s requirements (usually UE4.26). You have the 2 following uptions + +### Option 1: Build Natively + +Follow CARLA official documentation: [Unreal Engine - Linux Build](https://carla.readthedocs.io/en/latest/build_linux/#:~:text=wheel%20auditwheel%3D%3D4.0.0-,Unreal%20Engine,-Starting%20with%20version) + +### Option 2: Build UE4 in Build Container + + +The following steps outline a general workflow for building UE4 inside a Docker container. For detailed instructions, refer to `Engine/Documentation/Docker/run_with_docker.md` in the cloned repository: + +```bash +# Example of cloning a custom CarlaUnrealEngine repository +git clone git@github.com:wambitz/CarlaUnrealEngine.git CarlaUE4 + +cd CarlaUE4 +Scripts/run_container.sh + +# Inside the container follow official UE4.26 build steps: +./Setup.sh +./GenerateProjectFiles.sh +make + +# Exit container +exit +``` + +These commands generate the required Unreal Engine binaries and store them persistently on your host. You can later reuse them for the CARLA devcontainer. To verify a successful compilation, run the following command inside (or optionally outside) the container: + +```bash +Engine/Binaries/Linux/UE4Editor +``` +--- + +## Scripts Usage + +### 1. Lightweight Mode + +This mode relies on a **locally compiled** Unreal Engine folder. You mount that folder into the container for building CARLA. + +```bash +# 1) Set UE4_ROOT to your existing UE4 folder on the host: +export UE4_ROOT=/absolute/path/to/UnrealEngine_4.26 + +# 2) Run the container WITHOUT the --monolith flag: +./Scripts/run_container.sh + +# 3) Once inside the container, build CARLA as usual: +./Update.sh +make PythonAPI +make CarlaUE4Editor + +# Optionally build for distribution: +make build.utils +make package +``` + +- **Result**: + - Uses **`carla.dockerfile`** (lightweight). + - Mounts your host’s `$UE4_ROOT` folder into `/opt/UE4.26` inside the container. + - Expects a fully compiled UE4 on the host. See [Build UE4 for Devcontainer Option](#build-ue4-prerequisite-for-lightweight--devcontainer) for more details. + +### 2. Monolithic Mode + +In this mode, Docker clones and builds Unreal Engine, then compiles CARLA within the same image. + +```bash +# 1) Create a .env file with your Epic credentials at the repo root: +# EPIC_USER=YourGitHubUsername +# EPIC_PASS=YourGitHubToken + +# 2) Run the container WITH the --monolith flag: +./Scripts/run_container.sh --monolith +``` + +- **Result**: + - Uses **`carla-ue4-monolith.dockerfile`**. + - Builds UE4 and CARLA in one Docker image (commonly exceeding 200 GB). + - Takes significant time (hours) on most hardware. + +--- + + + +## Using a Devcontainer for CARLA Server/Client Development + +You can use a **Visual Studio Code devcontainer** with the lightweight approach. This setup mounts your host’s directories (including UE4) into a Docker environment. Note that the monolithic image is less suited to devcontainers since it stores everything inside the image. + +Create `.devcontainer/devcontainer.json` in your CARLA repository: + +```jsonc +{ + "name": "CARLA UE4 Dev (jammy)", + "image": "carla-ue4-jammy-dev", + + "initializeCommand": "./Scripts/build_image.sh", + + // We do NOT need to set "remoteUser" if the Dockerfile's default user is already correct + // but you can if you want to be explicit. Also "updateRemoteUserUID" can be false, since + // our Dockerfile already set the user to our exact UID/GID. + "updateRemoteUserUID": false, + + "customizations": { + "vscode": { + "settings": { + "terminal.integrated.shell.linux": "bash" + }, + "extensions": [ + "ms-vscode.cpptools" + ] + } + }, + + "postStartCommand": "bash", + + // NOTE1: DO NOT pass --user here (we want the Dockerfile default user, not an override) + // NOTE2: Make sure /usr/share/vulkan/icd.d/nvidia_icd.json exist in the host + // NOTE3: Ensure UE4_ROOT environment variable is defined in host + "runArgs": [ + "--rm", + "--name", "carla-ue4-jammy-devcontainer", + "--hostname", "carla-devcontainer", + "--env", "DISPLAY=${localEnv:DISPLAY}", + "--volume", "/tmp/.X11-unix:/tmp/.X11-unix", + "--volume", "/usr/share/vulkan/icd.d/nvidia_icd.json:/usr/share/vulkan/icd.d/nvidia_icd.json", + "--volume", "${localEnv:UE4_ROOT}:/opt/UE4.26", + "--gpus", "all" + ] +} +``` + +### Important Devcontainer Notes + +1. **GPU Access**: Install and configure the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html). +2. **X11 Forwarding**: Ensure `/tmp/.X11-unix` is accessible and `DISPLAY` is set properly on your host. +3. **UE4_ROOT Environment Variable**: Must be defined on your host so the devcontainer can mount the UE4 directory. +4. **Vulkan Support**: `/usr/share/vulkan/icd.d/nvidia_icd.json` must be exist in your host so the devcontainer can mount the vulkan configuration. + +--- + +## Tips & Caveats + +- **NVIDIA GPU** + For hardware acceleration, install the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html). + +- **Disk Space** + The monolithic image can exceed **200 GB** (e.g., ~221 GB in some builds). Ensure you have enough space before choosing this route. + +- **Build Times** + - Monolithic mode: ~2 hours on a high-end workstation (e.g., Intel Core i9-14900KF, 64 GB RAM, RTX 4090). + - Lightweight mode: Much faster since it reuses a local UE4 build. + +- **Volumes** + For lightweight mode, `$UE4_ROOT` must point to a fully compiled UE4. If incorrect or missing, builds will fail. + +- **Epic Credentials** + In monolithic mode, store `EPIC_USER` and `EPIC_PASS` in a `.env` file in the project root. + +- **Running Binaries on the Host** + **Do not** run `make launch` or `make launch-only` on your host after building in the container, because internal container paths (e.g., `/opt/UE4.26`) do not match your host environment. + If you need host access to CARLA binaries, first build a shipping package (`make build.utils && make package`), then run them from the resulting files in `Dist/` on the host. + +- **Mount Directory** + Avoid modifying `/workspaces` if you’re using VS Code devcontainers, as it might force a rebuild. The container’s internal paths often differ from the host, making direct host launches problematic. + + +- **`Dist` Folder Handling** + Monolithic mode leaves `Dist` in place to facilitate direct usage. If you need a smaller image, remove or adjust `make build.utils` and `make package`. + +--- + +## Known Issues + +1. **Truncated Output in `./Update.sh`** + Sometimes, `./Update.sh` in the CARLA repository may truncate logs. A workaround is redirecting the output to a file and tailing it. + +2. **Audio Support** + ALSA or PulseAudio are not pre-configured, so audio features might not work by default. + +3. **UE4Editor Rebuilds** + In some cases, once `UE4Editor` (built in UE4.26) is opened or used to build CARLA, it may refuse to open again without a rebuild. Errors about missing plugins can occur, a scenario also observed in local (non-Docker) setups. The workaround is to rebuild from the repository using the container or a devcontainer, or carefully adjust configuration files. + +--- \ No newline at end of file diff --git a/Docs/build_docker_unreal.md b/Docs/build_docker_unreal.md index b15f3dc5874..0eb5a72e763 100644 --- a/Docs/build_docker_unreal.md +++ b/Docs/build_docker_unreal.md @@ -63,13 +63,13 @@ __2. Build the final CARLA image.__ The following command will use the image created in the previous step to build the final CARLA image based on the current master branch (latest release) of the CARLA repository: ```sh -docker build -t carla -f Carla.Dockerfile . +docker build -t carla -f CarlaLegacy.Dockerfile . ``` If you would like to build a specific branch or tag of the CARLA repository, run the following command: ```sh -docker build -t carla -f Carla.Dockerfile . --build-arg GIT_BRANCH= +docker build -t carla -f CarlaLegacy.Dockerfile . --build-arg GIT_BRANCH= ``` --- diff --git a/README.md b/README.md index 38417d809e8..9d7cd0c33d6 100644 --- a/README.md +++ b/README.md @@ -146,4 +146,4 @@ CARLA uses one dependency as part of the Chrono integration: CARLA uses the Autodesk FBX SDK for converting FBX to OBJ in the import process of maps. This step is optional, and the SDK is located [here](https://www.autodesk.com/developer-network/platform-technologies/fbx-sdk-2020-0) -This software contains Autodesk® FBX® code developed by Autodesk, Inc. Copyright 2020 Autodesk, Inc. All rights, reserved. Such code is provided "as is" and Autodesk, Inc. disclaims any and all warranties, whether express or implied, including without limitation the implied warranties of merchantability, fitness for a particular purpose or non-infringement of third party rights. In no event shall Autodesk, Inc. be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of such code." +This software contains Autodesk® FBX® code developed by Autodesk, Inc. Copyright 2020 Autodesk, Inc. All rights, reserved. Such code is provided "as is" and Autodesk, Inc. disclaims any and all warranties, whether express or implied, including without limitation the implied warranties of merchantability, fitness for a particular purpose or non-infringement of third party rights. In no event shall Autodesk, Inc. be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of such code." \ No newline at end of file diff --git a/Scripts/build_image.sh b/Scripts/build_image.sh new file mode 100755 index 00000000000..af905df0eef --- /dev/null +++ b/Scripts/build_image.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash +set -e + +############################################################################### +# Usage: +# ./build_image.sh [--monolith] +# +# If --monolith is supplied, it will: +# - Use: carla-ue4.dockerfile +# - Tag: carla-ue4-jammy-dev +# - Pass EPIC creds as needed +# +# Otherwise (default/lightweight): +# - Use: carla.dockerfile +# - Tag: carla-ue4-jammy-dev +############################################################################### + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" +PROJECT_NAME="$(basename "$PROJECT_ROOT")" +DOCKERFILES_DIR="${PROJECT_ROOT}/Util/Docker" + +MONOLITH=0 +if [[ "$1" == "--monolith" || "$1" == "-m" ]]; then + MONOLITH=1 + echo "[INFO] Monolithic build enabled." +fi + +if [ $MONOLITH -eq 1 ]; then + DOCKERFILE="carla-ue4-monolith.dockerfile" + IMAGE_NAME="carla-ue4-jammy-monolith" +else + DOCKERFILE="carla-ue4.dockerfile" + IMAGE_NAME="carla-ue4-jammy-dev" +fi + +# ------------------------------------------------------------------------------ +# Load .env file for EPIC_USER, EPIC_PASS, etc. +# (Optional for the lightweight version, but mandatory for monolith.) +# ------------------------------------------------------------------------------ +if [ -f "${PROJECT_ROOT}/.env" ]; then + # shellcheck disable=SC2046 + export $(grep -v '^#' "${PROJECT_ROOT}/.env" | xargs) +else + echo "[WARN]: .env file not found in ${PROJECT_ROOT}." + echo "If you are building the monolithic version, you need EPIC credentials!" +fi + +if [ $MONOLITH -eq 1 ]; then + # Ensure credentials are loaded for UE4 + if [ -z "${EPIC_USER}" ] || [ -z "${EPIC_PASS}" ]; then + echo "[ERROR]: EPIC_USER or EPIC_PASS not set in the .env file. Aborting monolithic build." + exit 1 + fi +fi + +# ------------------------------------------------------------------------------ +# Build the Docker image +# ------------------------------------------------------------------------------ +echo "[INFO] Building Docker image '${IMAGE_NAME}' using Dockerfile '${DOCKERFILE}'" + +# We always build in the project root so Docker sees the Dockerfile paths +docker build \ + -f "${DOCKERFILES_DIR}/${DOCKERFILE}" \ + -t "${IMAGE_NAME}" \ + --build-arg EPIC_USER="${EPIC_USER:-}" \ + --build-arg EPIC_PASS="${EPIC_PASS:-}" \ + --build-arg USERNAME="$(whoami)" \ + --build-arg USER_UID="$(id -u)" \ + --build-arg USER_GID="$(id -g)" \ + --build-arg PROJECT_NAME="${PROJECT_NAME}" \ + "${PROJECT_ROOT}" diff --git a/Scripts/run_container.sh b/Scripts/run_container.sh new file mode 100755 index 00000000000..bdaf1eff2c0 --- /dev/null +++ b/Scripts/run_container.sh @@ -0,0 +1,107 @@ +#!/usr/bin/env bash +set -e + +############################################################################### +# Usage: +# ./run_container.sh [--monolith] +# +# If --monolith is supplied, the script uses: +# - Dockerfile: carla-ue4.dockerfile +# - Image Name: carla-ue4-jammy-dev +# - Container: carla-ue4-jammy-devcontainer +# - Hostname: carla-ue4-devcontainer +# - Extra volume for UE4 root +# +# Otherwise, it defaults to the lightweight version: +# - Dockerfile: carla.dockerfile +# - Image Name: carla-jammy-dev +# - Container: carla-jammy-devcontainer +# - Hostname: carla-devcontainer +# - Mounts UE4_ROOT:/opt/UE4.26 (external UE4 path) for building CARLA without +# baking UE4 into the container. +############################################################################### + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_DIR="$(dirname "$SCRIPT_DIR")" +PROJECT_NAME="$(basename "$PROJECT_DIR")" + +# ------------------------------------------------------------------------------ +# Parse Argument +# ------------------------------------------------------------------------------ +MONOLITH=0 +if [[ "$1" == "--monolith" || "$1" == "-m" ]]; then + MONOLITH=1 + echo "[INFO] Monolithic mode enabled." +else + echo "[INFO] Using default (lightweight) mode." +fi + +# ------------------------------------------------------------------------------ +# Select image, container names, and Dockerfile +# ------------------------------------------------------------------------------ +if [ $MONOLITH -eq 1 ]; then + DOCKERFILE="carla-ue4-monolith.dockerfile" + IMAGE_NAME="carla-ue4-jammy-monolith" + CONTAINER_NAME="carla-ue4-jammy-monolith" + HOSTNAME="carla-ue4-monolith" +else + DOCKERFILE="carla-ue4.dockerfile" + IMAGE_NAME="carla-ue4-jammy-dev" + CONTAINER_NAME="carla-ue4-jammy-devcontainer" + HOSTNAME="carla-ue4-devcontainer" +fi + +# ------------------------------------------------------------------------------ +# Docker / NVIDIA checks +# ------------------------------------------------------------------------------ +if ! command -v docker &> /dev/null; then + echo "Docker is not installed. Please install Docker and try again." + exit 1 +fi + + if ! docker info | grep -q "Runtimes:.*nvidia"; then + echo "[WARN] NVIDIA Container Toolkit is not installed or configured." + echo "GPU acceleration may not work." + echo "Refer to: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html" +fi + +# ------------------------------------------------------------------------------ +# Build the Docker image (this calls our new combined build script) +# ------------------------------------------------------------------------------ +echo "[INFO] Building Docker image: $IMAGE_NAME" +bash "$SCRIPT_DIR/build_image.sh" $([ $MONOLITH -eq 1 ] && echo "--monolith") + +# ------------------------------------------------------------------------------ +# X11 / GPU Setup +# ------------------------------------------------------------------------------ +DISPLAY="${DISPLAY:-:0}" +X11_SOCKET="/tmp/.X11-unix" +NVIDIA_ICD="/usr/share/vulkan/icd.d/nvidia_icd.json" + +# ------------------------------------------------------------------------------ +# If using the LIGHTWEIGHT container, ensure UE4_ROOT is defined +# ------------------------------------------------------------------------------ +if [ $MONOLITH -eq 0 ]; then + if [ -z "${UE4_ROOT}" ]; then + echo "[ERROR] \$UE4_ROOT is not set. Please export UE4_ROOT=/absolute/path/to/UE4.26 first." + echo "Example: export UE4_ROOT=\"/home/username/UnrealEngine_4.26\"" + exit 1 + fi +fi + +# ------------------------------------------------------------------------------ +# Start the Docker container +# ------------------------------------------------------------------------------ +echo "[INFO] Starting Docker container..." + +docker run -it --rm \ + --name "${CONTAINER_NAME}" \ + --hostname "${HOSTNAME}" \ + --env "DISPLAY=${DISPLAY}" \ + --volume "${X11_SOCKET}:${X11_SOCKET}" \ + --volume "${NVIDIA_ICD}:${NVIDIA_ICD}" \ + --gpus all \ + $([ $MONOLITH -eq 0 ] && echo "--volume ${PROJECT_DIR}:/workspaces/${PROJECT_NAME}") \ + $([ $MONOLITH -eq 0 ] && echo "--volume ${UE4_ROOT}:/opt/UE4.26") \ + "${IMAGE_NAME}" \ + bash diff --git a/Unreal/CarlaUE4/Plugins/CarlaTools/CarlaTools.uplugin b/Unreal/CarlaUE4/Plugins/CarlaTools/CarlaTools.uplugin index fc641e357d5..62a776d13ba 100644 --- a/Unreal/CarlaUE4/Plugins/CarlaTools/CarlaTools.uplugin +++ b/Unreal/CarlaUE4/Plugins/CarlaTools/CarlaTools.uplugin @@ -38,7 +38,7 @@ "Name": "ProceduralMeshComponent", "Enabled": true }, - { + { "Name": "StreetMap", "Enabled": true } diff --git a/Util/BuildTools/BuildCarlaUE4.sh b/Util/BuildTools/BuildCarlaUE4.sh index 4db570edb15..201c41682df 100755 --- a/Util/BuildTools/BuildCarlaUE4.sh +++ b/Util/BuildTools/BuildCarlaUE4.sh @@ -144,10 +144,10 @@ if ${BUILD_CARLAUE4} ; then OPTIONAL_MODULES_TEXT="" if ${USE_CARSIM} ; then - python ${PWD}/../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject" -e + python3 ${PWD}/../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject" -e OPTIONAL_MODULES_TEXT="CarSim ON"$'\n'"${OPTIONAL_MODULES_TEXT}" else - python ${PWD}/../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject" + python3 ${PWD}/../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject" OPTIONAL_MODULES_TEXT="CarSim OFF"$'\n'"${OPTIONAL_MODULES_TEXT}" fi if ${USE_CHRONO} ; then diff --git a/Util/BuildTools/BuildUtilsDocker.sh b/Util/BuildTools/BuildUtilsDocker.sh index 2c85a7b053c..9d2888afab3 100755 --- a/Util/BuildTools/BuildUtilsDocker.sh +++ b/Util/BuildTools/BuildUtilsDocker.sh @@ -17,7 +17,7 @@ FBXSDK_URL=https://www.autodesk.com/content/dam/autodesk/www/adn/fbx/2020-0-1/${ if [ ! -d "${FBX2OBJ_DEP_FOLDER}" ]; then log "Downloading FBX SDK..." - wget -c "${FBXSDK_URL}" -P "${CARLA_DOCKER_UTILS_FOLDER}" --user-agent="Mozilla" + curl -L -o "${CARLA_DOCKER_UTILS_FOLDER}/${LIB_NAME}.tar.gz" -H "User-Agent: Mozilla/5.0" "${FBXSDK_URL}" echo "Unpacking..." mkdir -p "${FBX2OBJ_DEP_FOLDER}" @@ -38,6 +38,7 @@ pushd "${FBX2OBJ_BUILD_FOLDER}" >/dev/null cmake -G "Ninja" \ -DCMAKE_CXX_FLAGS="-fPIC -std=c++14" \ + -DCMAKE_EXE_LINKER_FLAGS="-Wl,-rpath,/usr/lib/x86_64-linux-gnu -Wl,-rpath-link,/usr/lib/x86_64-linux-gnu" \ .. # copy the shared object 'libfbxsdk.so' to 'dist' folder diff --git a/Util/BuildTools/Package.sh b/Util/BuildTools/Package.sh index 0be72293a26..67b4395f21d 100755 --- a/Util/BuildTools/Package.sh +++ b/Util/BuildTools/Package.sh @@ -110,10 +110,10 @@ if ${DO_CARLA_RELEASE} ; then pushd "${CARLAUE4_ROOT_FOLDER}" >/dev/null if ${USE_CARSIM} ; then - python ${PWD}/../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject" -e + python3 ${PWD}/../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject" -e echo "CarSim ON" > ${PWD}/Config/CarSimConfig.ini else - python ${PWD}/../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject" + python3 ${PWD}/../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject" echo "CarSim OFF" > ${PWD}/Config/CarSimConfig.ini fi diff --git a/Util/Docker/Carla.Dockerfile b/Util/Docker/CarlaLegacy.Dockerfile similarity index 100% rename from Util/Docker/Carla.Dockerfile rename to Util/Docker/CarlaLegacy.Dockerfile diff --git a/Util/Docker/README.md b/Util/Docker/README.md index 88bbfc9952a..d11eab2f619 100644 --- a/Util/Docker/README.md +++ b/Util/Docker/README.md @@ -1,4 +1,4 @@ -# Building Carla in a Docker +# Building Carla in a Docker Ubuntu 18.04 Image _These instructions have been tested in **Ubuntu 16.04**._ @@ -65,7 +65,7 @@ docker build -t carla-prerequisites -f Prerequisites.Dockerfile . Finally create the actual Carla image, it will search for `carla-prerequisites:latest`: ``` -docker build -t carla -f Carla.Dockerfile . +docker build -t carla -f CarlaLegacy.Dockerfile . ``` --- @@ -75,7 +75,7 @@ docker build -t carla -f Carla.Dockerfile . You can use a specific repository **branch** or **tag** from our repository, using: ``` -docker build -t carla -f Carla.Dockerfile . --build-arg GIT_BRANCH=branch_name +docker build -t carla -f CarlaLegacy.Dockerfile . --build-arg GIT_BRANCH=branch_name ``` Clean up the intermediate images from the build (keep the ue4-source image so you can use it for full rebuilds) @@ -102,3 +102,12 @@ Or you can use it to cook assets (like new maps and meshes), ready to be consume ``` The needed files and hierarchy to import assets is explained [here](https://carla.readthedocs.io/en/latest/export_import_dist/). + +# Building Carla in a Docker Ubuntu 22.04 Image + +_These instructions have been tested in **Ubuntu 24.04**._ + +The following documentation is intended to explain how to build a Docker image that uses **Ubuntu 22.04** to compile Carla. + +- [CARLA Docker Dev Environment (Ubuntu 22.04)](../../Docs/build_docker_ubuntu22.md) + diff --git a/Util/Docker/carla-ue4.dockerfile b/Util/Docker/carla-ue4.dockerfile new file mode 100644 index 00000000000..39c10c205a3 --- /dev/null +++ b/Util/Docker/carla-ue4.dockerfile @@ -0,0 +1,131 @@ +FROM ubuntu:22.04 + +# ------------------------------------------------------------------------------ +# Build arguments for user/group +# ------------------------------------------------------------------------------ +ARG USERNAME=carla +ARG USER_ID=1000 +ARG GROUP_ID=1000 +ARG PROJECT_NAME="carla-ue4-dev" + +# ------------------------------------------------------------------------------ +# Set environment variables for NVIDIA support +# ------------------------------------------------------------------------------ +ENV NVIDIA_DRIVER_CAPABILITIES=all +ENV NVIDIA_VISIBLE_DEVICES=all + +# ------------------------------------------------------------------------------ +# Set the XDG_RUNTIME_DIR environment variable for ./Setup.sh +# ------------------------------------------------------------------------------ +ENV XDG_RUNTIME_DIR=/run/user/1000 + +# ------------------------------------------------------------------------------ +# Explicitly tell Vulkan to use NVIDIA's ICD +# ------------------------------------------------------------------------------ +ENV VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/nvidia_icd.json + +# ------------------------------------------------------------------------------ +# Create the UE4 directory env variable (if needed later) +# ------------------------------------------------------------------------------ +ENV UE4_ROOT="/opt/UE4.26" + +# ------------------------------------------------------------------------------ +# Create or rename user/group "$USERNAME" +# so that we end up with: +# - group "$USERNAME" at GID=$GROUP_ID +# - user "$USERNAME" at UID=$USER_ID +# ------------------------------------------------------------------------------ +RUN if [ -z "$(getent group $GROUP_ID)" ]; then \ + groupadd -g $GROUP_ID "$USERNAME"; \ + else \ + existing_group="$(getent group $GROUP_ID | cut -d: -f1)"; \ + if [ "$existing_group" != "$USERNAME" ]; then \ + groupmod -n "$USERNAME" "$existing_group"; \ + fi; \ + fi && \ + if [ -z "$(getent passwd $USER_ID)" ]; then \ + useradd -m -u $USER_ID -g $GROUP_ID "$USERNAME"; \ + else \ + existing_user="$(getent passwd $USER_ID | cut -d: -f1)"; \ + if [ "$existing_user" != "$USERNAME" ]; then \ + usermod -l "$USERNAME" -d /home/"$USERNAME" -m "$existing_user"; \ + fi; \ + fi + +# ------------------------------------------------------------------------------ +# Install Unreal Engine dependencies for GUI support in containers +# ------------------------------------------------------------------------------ +RUN apt-get update && \ + apt-get install -y \ + ca-certificates \ + xdg-user-dirs \ + xdg-utils \ + sudo \ + libvulkan1 \ + mesa-vulkan-drivers \ + libsdl2-dev \ + vulkan-tools + # (optional) vulkan-tools -> useful for debugging + +# ------------------------------------------------------------------------------ +# Install CARLA build dependencies (make PythonAPI, make CarlaUE4Editor) +# ------------------------------------------------------------------------------ +RUN apt-get install -y \ + git \ + curl \ + wget \ + build-essential \ + cmake \ + ninja-build \ + python3 \ + python3-dev \ + python3-setuptools \ + python3-distro \ + python3-wheel \ + libtiff5-dev \ + libjpeg-dev \ + autoconf \ + rsync \ + unzip + +# ------------------------------------------------------------------------------ +# (Optional) Install CARLA build packaging depenencies(make build.utils) +# ------------------------------------------------------------------------------ +RUN apt-get install -y \ + libxml2-dev + +# ------------------------------------------------------------------------------ +# Cleanup +# ------------------------------------------------------------------------------ +RUN rm -rf /var/lib/apt/lists/* + +# ------------------------------------------------------------------------------ +# Optionally add passwordless sudo for $USERNAME +# ------------------------------------------------------------------------------ +RUN echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers + +# ------------------------------------------------------------------------------ +# Use sed to uncomment the force_color_prompt line in ~/.bashrc +# ------------------------------------------------------------------------------ +RUN sed -i 's/#force_color_prompt=yes/force_color_prompt=yes/g' /home/$USERNAME/.bashrc + +# ------------------------------------------------------------------------------ +# Create the repo mount directory with the right ownership +# ------------------------------------------------------------------------------ +RUN mkdir -p /workspaces/$PROJECT_NAME && \ + chown -R $USERNAME:$USERNAME /workspaces + +# ------------------------------------------------------------------------------ +# Switch to "$USERNAME" by default and set working directory +# ------------------------------------------------------------------------------ +USER $USERNAME + +# ------------------------------------------------------------------------------ +# Set repo working directory +# ------------------------------------------------------------------------------ +WORKDIR /workspaces/${PROJECT_NAME} + +# ------------------------------------------------------------------------------ +# Entry point +# ------------------------------------------------------------------------------ +CMD ["/bin/bash"] diff --git a/Util/DockerUtils/dist/build.sh b/Util/DockerUtils/dist/build.sh index 3da0868ec12..4d3d9ed2a58 100644 --- a/Util/DockerUtils/dist/build.sh +++ b/Util/DockerUtils/dist/build.sh @@ -18,11 +18,11 @@ fi # check if the XODR file exist if [ -f "$1.xodr" ]; then # parse openDRIVE crosswalks (generate crosswalks.obj) - python get_xodr_crosswalks.py -f "$1.xodr" + python3 get_xodr_crosswalks.py -f "$1.xodr" else if [ -f "$2.xodr" ]; then # parse openDRIVE crosswalks (generate crosswalks.obj) - python get_xodr_crosswalks.py -f "$2.xodr" + python3 get_xodr_crosswalks.py -f "$2.xodr" else echo "XODR file doesn't exist, ignoring crosswalks from openDRIVE" fi @@ -31,7 +31,7 @@ fi # check if the 'crosswalks.obj' file exist if [ -f "crosswalks.obj" ]; then # join both OBJ - python addOBJ.py "$1.obj" crosswalks.obj + python3 addOBJ.py "$1.obj" crosswalks.obj fi if [ -f "$1.obj" ]; then