Skip to content

Commit

Permalink
Set up Bazelisk in Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik committed Jul 22, 2024
1 parent 89a860d commit ce24ab8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
Empty file added .docker_cache/empty_file
Empty file.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ __generated__
cache.sqlite
cache.sqlite-journal
out.png
.docker_cache/
24 changes: 13 additions & 11 deletions platform/linux/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
FROM ubuntu:22.04

# When running docker with -u flag, the user should exist in the container to avoid various warnings
RUN groupadd -f user && useradd -m -g user user

# Install build tools and dependencies
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
apt-transport-https \
curl \
gnupg \
&& curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor >bazel-archive-keyring.gpg \
&& mv bazel-archive-keyring.gpg /usr/share/keyrings \
&& echo "deb [arch=amd64 signed-by=/usr/share/keyrings/bazel-archive-keyring.gpg] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
bazel \
build-essential \
libsqlite3-dev \
libcurl4-openssl-dev \
libglfw3-dev \
libuv1-dev \
Expand All @@ -28,6 +21,15 @@ RUN apt-get update \
cmake \
ccache \
ninja-build \
pkg-config
pkg-config \
&& : # end of the RUN cmd - easier to keep a colon at the end of the list, than to keep the backslashes in check

# This could also be `.../releases/latest/download/bazelisk-linux-amd64` for the latest version, but for predictability better hardcode it
RUN curl -fsSL https://github.com/bazelbuild/bazelisk/releases/download/v1.20.0/bazelisk-linux-amd64 -o /usr/local/bin/bazel \
&& chmod +x /usr/local/bin/bazel \
&& :

# When running docker with -u flag, the user should exist in the container to avoid various warnings
RUN groupadd -f user && useradd -m -g user user

WORKDIR /code
WORKDIR /app
12 changes: 7 additions & 5 deletions platform/linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cd maplibre-native

```bash
# Install build tools
apt install clang cmake ccache ninja-build pkg-config
apt install build-essential clang cmake ccache ninja-build pkg-config

# Install system dependencies
apt install libcurl4-openssl-dev libglfw3-dev libuv1-dev libpng-dev libicu-dev libjpeg-turbo8-dev libwebp-dev xvfb
Expand All @@ -26,18 +26,20 @@ Optional: `libsqlite3-dev` (also available as vendored dependency).

### Building with Docker

You can use a Docker container to build MapLibre Native. A `Dockerfile` that installes the required dependencies when the image is built is provided in this directory.
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
docker build -t maplibre-native-image -f platform/linux/Dockerfile .
docker build \
-t maplibre-native-image \
-f platform/linux/Dockerfile .

# Run docker image as the current user.
# This ensures that the files created in the container are owned by the current user.
docker run --rm -it -v "$PWD:/code/" -u $(id -u):$(id -g) maplibre-native-image ___any_build_command___
docker run --rm -it -v "$PWD:/app/" -v "$PWD/.docker_cache:/home/user/.cache" -u $(id -u):$(id -g) maplibre-native-image ___any_build_command___

# You can also execute build commands from inside the docker container by starting it without parameters:
docker run --rm -it -v "$PWD:/code/" -u $(id -u):$(id -g) maplibre-native-image
docker run --rm -it -v "$PWD:/app/" -v "$PWD/.docker_cache:/home/user/.cache" -u $(id -u):$(id -g) maplibre-native-image
```

You can safely ignore this type of message and a missing username. It happens if your linux user was not the first one created on the system.
Expand Down

0 comments on commit ce24ab8

Please sign in to comment.