diff --git a/docker/Dockerfile b/docker/Dockerfile index 58a4e6ab55b..89fbe5a90b7 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:22.04 +FROM ubuntu:24.04 # Install build tools and dependencies RUN apt-get update \ @@ -40,23 +40,24 @@ RUN echo "Download and install Bazel" \ && chmod +x /usr/local/bin/bazel \ && : - -ARG USERNAME=user +# This username is hardcoded in several places, and should simply match whatever base image uses +ARG USERNAME=ubuntu ARG USER_UID=1000 ARG USER_GID=$USER_UID # Create docker user wuth sudo rights as passed in by the build command # This was modeled on https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user # On a Mac, USER_GID might already exist, so ignore it if it fails (--force) -RUN groupadd --force --gid $USER_GID $USERNAME \ - && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ +RUN groupmod --gid $USER_GID $USERNAME \ + && usermod --uid $USER_UID --gid $USER_GID $USERNAME \ + && chown -R $USER_UID:$USER_GID /home/$USERNAME \ && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ && chmod 0440 /etc/sudoers.d/$USERNAME # This allows users to `docker run` without specifying -u and -g USER $USERNAME -RUN pip install pre-commit +#RUN pip install pre-commit ENV RUSTUP_HOME=/home/$USERNAME/.cache/.rustup \ CARGO_HOME=/home/$USERNAME/.cache/.cargo \ diff --git a/docker/README.md b/docker/README.md index 5a090f86db6..62b9896716a 100644 --- a/docker/README.md +++ b/docker/README.md @@ -33,11 +33,11 @@ docker build \ ```bash # Run all build commands using the docker container. # You can also execute build commands from inside the docker container by starting it without the build command. -docker run --rm -it -v "$PWD:/app/" -v "$PWD/docker/.cache:/home/user/.cache" maplibre-native-image +docker run --rm -it -v "$PWD:/app/" -v "$PWD/docker/.cache:/home/ubuntu/.cache" maplibre-native-image ``` You can also use the container to run just one specific commands, e.g. `cmake` or `bazel`. Any downloaded dependencies will be cached in the `docker/.cache` directory. ```bash -docker run --rm -it -v "$PWD:/app/" -v "$PWD/docker/.cache:/home/user/.cache" maplibre-native-image cmake ... +docker run --rm -it -v "$PWD:/app/" -v "$PWD/docker/.cache:/home/ubuntu/.cache" maplibre-native-image cmake ... ``` diff --git a/docker/startup.sh b/docker/startup.sh index 3a60b8e63e0..9534d378dc6 100644 --- a/docker/startup.sh +++ b/docker/startup.sh @@ -6,7 +6,8 @@ if [ ! -d /app/.github ] || [ ! -d ~/.cache ]; then echo " From the root of this repo, run the following command." echo " You may add any command to perform in the container at the end of this command." echo " " - echo ' docker run --rm -it -v "$PWD:/app/" -v "$PWD/docker/.cache:/home/'"$USERNAME"'/.cache" maplibre-native-image' + # shellcheck disable=SC2016 + echo ' docker run --rm -it -v "$PWD:/app/" -v "$PWD/docker/.cache:'"$HOME"'/.cache" maplibre-native-image' exit 1 fi