From daa5c7db51a1e61ed07451a5e8d7046e4aa795de Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 24 Jul 2024 11:24:12 -0400 Subject: [PATCH] Move docker files to /docker --- .../npm_translate_lock_LTE4Nzc1MDcwNjU= | 6 +-- {platform/linux => docker}/Dockerfile | 2 +- .../linux => docker}/Dockerfile.dockerignore | 0 docker/README.md | 39 +++++++++++++++++++ {platform/linux => docker}/startup.sh | 0 platform/linux/README.md | 24 +----------- 6 files changed, 44 insertions(+), 27 deletions(-) rename {platform/linux => docker}/Dockerfile (95%) rename {platform/linux => docker}/Dockerfile.dockerignore (100%) create mode 100644 docker/README.md rename {platform/linux => docker}/startup.sh (100%) diff --git a/.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU= b/.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU= index 99b2490ac37..d330048e844 100755 --- a/.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU= +++ b/.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU= @@ -1,7 +1,5 @@ # @generated # Input hashes for repository rule npm_translate_lock(name = "npm", pnpm_lock = "//:pnpm-lock.yaml"). # This file should be checked into version control along with the pnpm-lock.yaml file. -.npmrc=-592547263 -pnpm-lock.yaml=104874376 -package-lock.json=-1109603374 -package.json=752745807 +pnpm-lock.yaml=322447152 +package.json=1512585561 diff --git a/platform/linux/Dockerfile b/docker/Dockerfile similarity index 95% rename from platform/linux/Dockerfile rename to docker/Dockerfile index fbe785de980..8bc737daf6d 100644 --- a/platform/linux/Dockerfile +++ b/docker/Dockerfile @@ -36,7 +36,7 @@ ARG USERNAME=user ARG USER_UID=1000 ARG USER_GID=$USER_UID -# Create docker user as passed in by the build command +# 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 RUN groupadd --gid $USER_GID $USERNAME \ && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ diff --git a/platform/linux/Dockerfile.dockerignore b/docker/Dockerfile.dockerignore similarity index 100% rename from platform/linux/Dockerfile.dockerignore rename to docker/Dockerfile.dockerignore diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 00000000000..3dea9513c26 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,39 @@ +# Linux + +These steps will allow you to compile code as described [platform/linux/README.md](../platform/linux/README.md) using a docker container. All the steps should be executed from the root of the repository. + +ATTENTION: You cannot build MapLibre native using both Docker and host methods at the same time. If you want to switch, you need to clean the repository first, e.g. by using this command: + +```bash +git clean -dxfi -e .idea -e .clwb -e .vscode +``` + +### Build Docker Image + +You must build your own docker image, specific with your user and group IDs to ensure file permissions stay correct. + +```bash +# Build docker image from the repo __root__ +# Specifying USER_ID and GROUP_ID allows container to create files with the same owner as the host user, +# and avoids having to pass -u $(id -u):$(id -g) to docker run. +docker build \ + -t maplibre-native-image \ + --build-arg USER_ID=$(id -u) \ + --build-arg GROUP_ID=$(id -g) \ + -f platform/linux/Dockerfile \ + platform/linux +``` + +## Run Docker Container + +```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 +``` + +You can also run any command inside the container, for example: + +```bash +docker run --rm -it -v "$PWD:/app/" -v "$PWD/.docker_cache:/home/user/.cache" maplibre-native-image cmake ... +``` diff --git a/platform/linux/startup.sh b/docker/startup.sh similarity index 100% rename from platform/linux/startup.sh rename to docker/startup.sh diff --git a/platform/linux/README.md b/platform/linux/README.md index 8d6b87463c3..4258295986a 100644 --- a/platform/linux/README.md +++ b/platform/linux/README.md @@ -26,23 +26,7 @@ Optional: `libsqlite3-dev` (also available as vendored dependency). ### Building with Docker -You can use a Docker container to build MapLibre Native. Note that you cannot build using both Docker and host methods at the same time. If you want to switch, you need to clean the repository first, e.g. by using `git clean -dxfi -e .idea -e .clwb -e .vscode` - -```bash -# Build docker image from the repo root -# Specifying USER_ID and GROUP_ID allows container to create files with the same owner as the host user, -# and avoids having to pass -u $(id -u):$(id -g) to docker run. -docker build \ - -t maplibre-native-image \ - --build-arg USER_ID=$(id -u) \ - --build-arg GROUP_ID=$(id -g) \ - -f platform/linux/Dockerfile \ - platform/linux - -# 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 ___any_build_command___ -``` +See instructions in [docker/README.md](../../docker/README.md) to build docker container ## Build @@ -59,16 +43,12 @@ Running `mbgl-render --style https://raw.githubusercontent.com/maplibre/demotile ![Sample image of world from mbgl-render command](/misc/sample-maplibre-style-mbgl-render-out.png) -### Outside of Docker - -Render output image using default MapLibre demo tiles server. You can run this binary on your host machine even if you built it inside a Docker container. - ```bash ./build/bin/mbgl-render --style https://raw.githubusercontent.com/maplibre/demotiles/gh-pages/style.json --output out.png xdg-open out.png ``` -### Inside Docker +### Headless rendering If you run `mbgl-render` inside a Docker or on a remote headless server, you will likely get this error because there is no X server running in the container.