From 4d59d5def99741b278f02105811a288f24986e8a Mon Sep 17 00:00:00 2001 From: Dogan Ulus Date: Sun, 30 Jun 2024 17:23:39 +0300 Subject: [PATCH] Update Carla server --- .github/workflows/carlasim-release.yml | 75 ------------------- carlasim/release/Dockerfile | 35 --------- carlasim/server/Dockerfile | 99 +++++++++++++------------- carlasim/server/carla.sh | 45 ++++++++++++ carlasim/server/entrypoint.sh | 2 - carlasim/server/supervisord.conf | 16 ----- 6 files changed, 93 insertions(+), 179 deletions(-) delete mode 100644 .github/workflows/carlasim-release.yml delete mode 100644 carlasim/release/Dockerfile create mode 100644 carlasim/server/carla.sh delete mode 100644 carlasim/server/entrypoint.sh delete mode 100644 carlasim/server/supervisord.conf diff --git a/.github/workflows/carlasim-release.yml b/.github/workflows/carlasim-release.yml deleted file mode 100644 index b92c9d0..0000000 --- a/.github/workflows/carlasim-release.yml +++ /dev/null @@ -1,75 +0,0 @@ -name: Build CarlaSim release container images -on: - workflow_dispatch: - push: - paths: - - carlasim/release/Dockerfile - - .github/workflows/carlasim-release.yml # Self-trigger - -env: - REGISTRY: ghcr.io - IMAGE_NAME: bounverif/carla - CARLA_VERSION: 0.9.15 - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - release-container-build: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - name: Free disk space (Ubuntu) - uses: jlumbroso/free-disk-space@main - with: - # this might remove tools that are actually needed, - # if set to "true" but frees about 6 GB - tool-cache: true - - # all of these default to true, but feel free to set to - # "false" if necessary for your workflow - android: true - dotnet: true - haskell: true - large-packages: true - docker-images: true - swap-storage: true - - - name: Checkout repository - uses: actions/checkout@v4 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Log in to the registry - uses: docker/login-action@v3 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push container image - uses: docker/build-push-action@v5 - with: - context: carlasim/release - target: carla-release - build-args: | - "CARLA_VERSION=${{ env.CARLA_VERSION }}" - tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:release-${{ env.CARLA_VERSION }} - push: true - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Build and push extended image - uses: docker/build-push-action@v5 - with: - context: carlasim/release - target: carla-release-extra - build-args: | - "CARLA_VERSION=${{ env.CARLA_VERSION }}" - tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:release-extra-${{ env.CARLA_VERSION }} - push: true - cache-from: type=gha - cache-to: type=gha,mode=max diff --git a/carlasim/release/Dockerfile b/carlasim/release/Dockerfile deleted file mode 100644 index 70f479f..0000000 --- a/carlasim/release/Dockerfile +++ /dev/null @@ -1,35 +0,0 @@ -FROM docker.io/library/ubuntu:22.04 as carla-release - -ARG CARLA_VERSION=0.9.15 -ARG CARLA_RELEASE_SERVER=https://carla-releases.s3.us-east-005.backblazeb2.com/Linux -ARG CARLA_RELEASE_TAR=CARLA_${CARLA_VERSION}.tar.gz -ARG CARLA_RELEASE_URL=${CARLA_RELEASE_SERVER}/${CARLA_RELEASE_TAR} -ARG CARLA_ADDITIONAL_MAPS_TAR=AdditionalMaps_${CARLA_VERSION}.tar.gz -ARG CARLA_ADDITIONAL_MAPS_URL=${CARLA_RELEASE_SERVER}/${CARLA_ADDITIONAL_MAPS_TAR} - -ENV DEBIAN_FRONTEND=noninteractive -ENV PIP_NO_CACHE_DIR=true -ENV PIP_DISABLE_PIP_VERSION_CHECK=true -ENV PIP_BREAK_SYSTEM_PACKAGES=true - -ENV CARLA_VERSION=${CARLA_VERSION} -ENV CARLA_RELEASE_URL=${CARLA_RELEASE_URL} -ENV CARLA_ADDITIONAL_MAPS_URL=${CARLA_ADDITIONAL_MAPS_URL} - -# Install core packages required to download files from external servers -RUN apt-get update && apt-get -y install --no-install-recommends \ - tar \ - curl \ - wget \ - zip \ - unzip \ - gnupg2 \ - software-properties-common \ - && apt-get autoremove -y && apt-get clean -y - -RUN mkdir -p /carla_release && \ - wget -qO- ${CARLA_RELEASE_URL} | tar xz -C /carla_release - -FROM carla-release as carla-release-extra - -RUN wget -qO- ${CARLA_ADDITIONAL_MAPS_URL} | tar xz --keep-newer-files -C /carla_release diff --git a/carlasim/server/Dockerfile b/carlasim/server/Dockerfile index 47b0f46..13a82c9 100644 --- a/carlasim/server/Dockerfile +++ b/carlasim/server/Dockerfile @@ -1,17 +1,35 @@ -ARG CARLA_VERSION=0.9.15 -FROM ghcr.io/bounverif/carla:release-${CARLA_VERSION} as carla-release - -FROM docker.io/library/ubuntu:22.04 as carla-server - -ARG USER=bounverif -ARG USERGROUP=${USER} -ARG UID=1000 -ARG GID=${UID} +FROM nvidia/opengl:1.2-glvnd-runtime-ubuntu22.04 AS carla-server ARG CARLA_VERSION=0.9.15 -ENV CARLA_VERSION=${CARLA_VERSION} +ARG CARLA_RELEASE_SERVER=https://carla-releases.s3.us-east-005.backblazeb2.com/Linux +ARG CARLA_RELEASE_TAR=CARLA_${CARLA_VERSION}.tar.gz +ARG CARLA_RELEASE_URL=${CARLA_RELEASE_SERVER}/${CARLA_RELEASE_TAR} +ARG CARLA_ADDITIONAL_MAPS_TAR=AdditionalMaps_${CARLA_VERSION}.tar.gz +ARG CARLA_ADDITIONAL_MAPS_URL=${CARLA_RELEASE_SERVER}/${CARLA_ADDITIONAL_MAPS_TAR} -RUN apt-get update && apt-get -y install --no-install-recommends \ +ENV CARLA_VERSION=${CARLA_VERSION} +ENV CARLA_RELEASE_URL=${CARLA_RELEASE_URL} +ENV CARLA_ADDITIONAL_MAPS_URL=${CARLA_ADDITIONAL_MAPS_URL} + +RUN set -eux; \ + apt-get update; \ + apt-get -y install --no-install-recommends \ + tar \ + wget \ + gnupg2 \ + software-properties-common \ + ; \ + apt-get autoremove -y && apt-get clean -y + +RUN mkdir -p /opt/carla-simulator; \ + wget -qO- ${CARLA_RELEASE_URL} | tar xz --no-same-owner --no-same-permissions --mode 755 -C /opt/carla-simulator + +RUN wget -qO- ${CARLA_ADDITIONAL_MAPS_URL} | tar xz --keep-newer-files --no-same-owner --no-same-permissions --mode 0755 -C /opt/carla-simulator + +RUN set -eux; \ + apt-get update; \ + apt-get -qy install --no-install-recommends -o Dpkg::Options::="--force-confold" \ + sudo \ supervisor \ python3 \ python3-pip \ @@ -20,53 +38,32 @@ RUN apt-get update && apt-get -y install --no-install-recommends \ libegl1 \ libvulkan1 \ vulkan-tools \ + valgrind \ libomp5 \ xdg-user-dirs \ - && apt-get autoremove -y && apt-get clean -y - -COPY --chown=root:root --chmod=755 --from=carla-release /carla_release /opt/carla-simulator/ -COPY --chown=root:root --chmod=755 supervisord.conf /etc/supervisord.conf -COPY --chown=root:root --chmod=755 entrypoint.sh /etc/entrypoint.sh - -RUN groupadd ${USERGROUP} -g ${GID} && useradd -ms /bin/bash ${USER} -g ${USERGROUP} -u ${UID} -G sudo - -USER ${USER} -WORKDIR ${HOME} - -RUN python3 -m pip install --user carla==${CARLA_VERSION} - -ENV DISPLAY :0 -ENV NVIDIA_VISIBLE_DEVICES all -ENV NVIDIA_DRIVER_CAPABILITIES all -ENV XDG_RUNTIME_DIR /run/user/${UID} -ENV SDL_VIDEODRIVER=x11 - -ENV CARLA_SERVER_ARGS="-RenderOffScreen -ResX=1 -ResY=1 -nosound -quality-level=Low" -ENV CARLA_SERVER_MAP="Town05" - -ENTRYPOINT ["/usr/bin/supervisord"] - -EXPOSE 2000 2001 2002 - - - - - + ; \ + apt-get autoremove -y && apt-get clean -y +COPY --chown=root:root --chmod=0755 carla.sh /etc/carla/carla.sh +ARG USER=bounverif +ARG USERGROUP=${USER} +ARG UID=1000 +ARG GID=${UID} +RUN groupadd ${USERGROUP} -g ${GID}; \ + useradd -ms /bin/bash ${USER} -g ${USERGROUP} -u ${UID} -G sudo,video; \ + printf "${USER} ALL= NOPASSWD: ALL\\n" >> /etc/sudoers +USER ${USER} +WORKDIR /home/${USER} -FROM docker.io/library/ubuntu:22.04 as carla-client +ENV DISPLAY=:0 +ENV XDG_RUNTIME_DIR=/run/user/${UID} -ARG CARLA_VERSION=0.9.15 -ENV CARLA_VERSION=${CARLA_VERSION} +RUN python3 -m pip install --user carla==${CARLA_VERSION} -RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install \ - python3 \ - python3-pip \ - && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* +ENTRYPOINT ["/bin/bash", "-c"] +CMD ["/etc/carla/carla.sh"] -RUN python3 -m pip install --upgrade pip && \ - python3 -m pip install numpy pygame carla==${CARLA_VERSION} +EXPOSE 2000 2001 2002 \ No newline at end of file diff --git a/carlasim/server/carla.sh b/carlasim/server/carla.sh new file mode 100644 index 0000000..8c93e29 --- /dev/null +++ b/carlasim/server/carla.sh @@ -0,0 +1,45 @@ + #!/bin/bash +# set -x + +# Set the default values of the environment variables used by the script +CARLA_SERVER_RENDERING=${CARLA_SERVER_RENDERING:-"OFFSCREEN"} +CARLA_SERVER_NO_SOUND=${CARLA_SERVER_NO_SOUND:-"true"} +CARLA_SERVER_FRAME_PER_SECOND=${CARLA_SERVER_FRAME_PER_SECOND:-25} +CARLA_SERVER_QUALITY_LEVEL=${CARLA_SERVER_QUALITY_LEVEL:-"Low"} +CARLA_SERVER_RPC_PORT=${CARLA_SERVER_RPC_PORT:-"2000"} +CARLA_SERVER_STREAMING_PORT=${CARLA_SERVER_STREAMING_PORT:-"2001"} +CARLA_SERVER_ADDITIONAL_ARGS=${CARLA_SERVER_ADDITIONAL_ARGS:-""} + +CARLA_SERVER_ARGS=${CARLA_SERVER_ARGS:-"-fps=${CARLA_SERVER_FRAME_PER_SECOND}"} + +gpu_count=$(/usr/bin/nvidia-smi -L | grep -i GPU | wc -l) +echo "$gpu_count NVIDIA GPU(s) found" + +if [ "$gpu_count" -eq 0 ] && [ "$CARLA_SERVER_RENDERING" != "NONE" ]; then + echo "No NVIDIA GPU found, switching to CPU rendering" + CARLA_SERVER_RENDERING="NONE" +fi + +if [ "$CARLA_SERVER_RENDERING" = "NONE" ]; then + CARLA_SERVER_RENDERING_ARGS="-nullrhi" + echo "No rendering mode selected" +elif [ "$CARLA_SERVER_RENDERING" = "OFFSCREEN" ]; then + CARLA_SERVER_RENDERING_ARGS="-RenderOffScreen -ResX=1 -ResY=1 -quality-level=${CARLA_SERVER_QUALITY_LEVEL}" + echo "Offscreen rendering mode selected" +elif [ "$CARLA_SERVER_RENDERING" = "SERVER" ]; then + CARLA_SERVER_RENDERING_ARGS="-quality-level=${CARLA_SERVER_QUALITY_LEVEL}" + echo "Server rendering mode selected" +fi + +CARLA_SERVER_ARGS="${CARLA_SERVER_ARGS} ${CARLA_SERVER_RENDERING_ARGS}" + +if [ "$CARLA_SERVER_NO_SOUND" ]; then + CARLA_SERVER_ARGS="${CARLA_SERVER_ARGS} -nosound" +fi + +if [ "$CARLA_SERVER_ADDITIONAL_ARGS" ]; then + CARLA_SERVER_ARGS="${CARLA_SERVER_ARGS} ${CARLA_SERVER_ADDITIONAL_ARGS}" +fi + +echo "Starting CarlaUE4 with ${CARLA_SERVER_ARGS}" +exec /opt/carla-simulator/CarlaUE4/Binaries/Linux/CarlaUE4-Linux-Shipping ${CARLA_SERVER_ARGS} diff --git a/carlasim/server/entrypoint.sh b/carlasim/server/entrypoint.sh deleted file mode 100644 index e48f9af..0000000 --- a/carlasim/server/entrypoint.sh +++ /dev/null @@ -1,2 +0,0 @@ - #!/bin/bash -/opt/carla-simulator/CarlaUE4/Binaries/Linux/CarlaUE4-Linux-Shipping ${CARLA_SERVER_ARGS} \ No newline at end of file diff --git a/carlasim/server/supervisord.conf b/carlasim/server/supervisord.conf deleted file mode 100644 index a812a88..0000000 --- a/carlasim/server/supervisord.conf +++ /dev/null @@ -1,16 +0,0 @@ -[supervisord] -user=bounverif -nodaemon=true -loglevel=info -logfile=/tmp/supervisord.log -pidfile=/tmp/supervisord.pid - -[program:entrypoint] -command=/etc/entrypoint.sh -logfile=/tmp/entrypoint.log -pidfile=/tmp/entrypoint.pid -stopsignal=INT -autostart=true -# autorestart=true -redirect_stderr=true -priority=1