Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ deploy/
build/
helm/
toolbox/
!toolbox/fetch-vector-assets.sh
!toolbox/generate-vector-tiles.sh
!toolbox/prepare-osm-extract.sh
.git/
.github/
.vscode/
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ jobs:
app:
- name: maps-tile-uploader
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/riscv64
- name: maps-vector-uploader
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/riscv64
# Based on the Planetiler image which is only available for those platforms
- name: maps-vector-generator
platforms: linux/amd64,linux/arm64
- name: maps-tile-server
platforms: linux/amd64,linux/arm64
env:
Expand Down
133 changes: 133 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,136 @@ Changing PostgreSQL server settings restarts PostgreSQL which aborts a running
import, the import is then started again from scratch. `noSync: true`
additionally disables crash safety of PostgreSQL, a crash can then corrupt
the database which has to be imported again.

## Vector map (prototype)

`maps-vector-uploader` publishes a vector tiles based map: pre-generated
tiles split by zoom level (same `{z}/{x}/{y}` layout as the raster map),
styled and rendered in the browser with MapLibre GL JS.

Resulting cinode directory:

```text
/index.html MapLibre viewer
/overzoom.mjs client-side over-zoom for regions with lower max zoom
/style.json map style (OpenMapTiles schema, derived from OSM Bright
with OSM Carto-like colors, road widths and house numbers)
/maplibre/ MapLibre GL JS
/fonts/{fontstack}/{range}.pbf
/sprites/sprite*.{json,png}
/tiles/coverage.json per-zoom bounding rectangles of existing tiles
/tiles/{z}/{x}/{y}.pbf uncompressed Mapbox Vector Tiles
```

### 1. Generate tiles with Planetiler

[Planetiler](https://github.com/onthegomap/planetiler) builds OpenMapTiles-schema
tiles straight from an `.osm.pbf` file (no database). Tiles must be written as
plain files and **without gzip** (the cinode proxy does not set
`Content-Encoding`).

Low zoom levels for the whole world (Natural Earth + water polygons):

```bash
java -Xmx6g -jar planetiler.jar --area=luxembourg --bounds=world --download \
--output="tiles-world?format=files" --tile_compression=none --maxzoom=6
```

Detailed region(s):

```bash
java -Xmx6g -jar planetiler.jar --area=luxembourg --download \
--output="tiles-luxembourg?format=files" --tile_compression=none --maxzoom=14
```

### 2. Fetch client-side assets

```bash
toolbox/fetch-vector-assets.sh assets
```

### 3. Upload to cinode

```bash
CINODE_DATASTORE=<datastore> \
CINODE_MAPTILES_NEW_WRITERINFO=1 \
CINODE_VECTOR_TILES_DIRS=tiles-world:tiles-luxembourg \
CINODE_VECTOR_ASSETS_DIR=assets \
go run ./cmd/maps-vector-uploader
```

Tiles from later directories override earlier ones. Use
`CINODE_MAPTILES_WRITERINFO=<writer info>` instead of
`CINODE_MAPTILES_NEW_WRITERINFO` to update an existing map. Unchanged tiles
produce the same blobs, so an update only stores what actually changed.

### Different max zoom per region

MapLibre supports a single max zoom per source. When a tile doesn't exist
(e.g. z10 outside of detailed regions), `overzoom.mjs` fetches the closest
existing ancestor tile (using `tiles/coverage.json` to skip non-existing ones)
and rescales its geometry on the client. Above the highest generated zoom
(14), MapLibre over-zooms natively.

### Running in Kubernetes

The `osm-machinery` helm chart generates either map type, selected with
`mapType`:

* `raster` (default) - PostgreSQL + tile server, uploaded by
`maps-tile-uploader`,
* `vector` - a single CronJob running the steps one after another:
downloading extracts (`pbf` + `poly`) of enabled regions and merging them
into one extract with osmium, generating tiles with Planetiler (low zoom
levels for the whole world, then all regions at once, limited to their
polygons) and uploading them with `maps-vector-uploader`, plus an
optional viewer (cinode web proxy). Merging the extracts first makes tiles
along borders of neighbouring regions contain data of all of them.
Everything runs in the `maps-vector-generator` image. Requires
`postgres.enabled=false`.

See `vectorMap` in [values.yaml](helm/osm-machinery/values.yaml) for all
options. By default the map is stored in a local datastore on the data
volume and the map link is created on the first run; use
`vectorMap.datastore` and `vectorMap.writerInfo` to publish to a real
datastore.

## Local testing in minikube

`toolbox/minikube-test.sh` starts minikube (if needed), builds images
from the working tree, loads them into minikube and deploys the chart with
one of the presets from [toolbox/minikube](toolbox/minikube):

```bash
# Raster map (default)
toolbox/minikube-test.sh

# Vector map of Luxembourg - quick test, a few minutes
toolbox/minikube-test.sh vector-luxembourg

# Vector map of Poland - realistic dataset, ~30 min, needs a bigger minikube
MINIKUBE_MEMORY=10g toolbox/minikube-test.sh vector-poland

# Vector map of two neighbouring regions (Lubuskie, Brandenburg) - checks
# that tiles along the border contain data of both, ~10 min
toolbox/minikube-test.sh vector-border
```

For vector presets the map generation starts right away.
`toolbox/minikube-view.sh` follows it and, once the first upload is done,
serves the map on <http://localhost:8080/>:

```bash
toolbox/minikube-view.sh

# Also reachable from other devices in the local network, e.g. a phone
ADDRESS=0.0.0.0 toolbox/minikube-view.sh
```

Running `minikube-test.sh` again deploys the current code and starts a new
generation, the same map link is updated. Downloaded data is kept on the
data volume, which also holds the map link and is kept when the release
is removed. To start from scratch remove the release
(`helm uninstall cinode-maps --kube-context minikube`) and the volume
(`minikube kubectl -- delete pvc cinode-maps-vector-data`) or the whole
minikube (`minikube delete`).
59 changes: 59 additions & 0 deletions build/docker/Dockerfile.maps-vector-generator
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# syntax=docker/dockerfile:1
# Complete vector map pipeline in one image: Planetiler generating the tiles,
# maps-vector-uploader with the viewer assets publishing them to cinode
ARG GO_VERSION=1.27

# Base image with go compiler and tested source code
FROM --platform=$BUILDPLATFORM docker.io/library/golang:${GO_VERSION} AS build

# Compile and test with non-root user
RUN useradd -ms /bin/bash go
USER go
RUN git config --global --add safe.directory /home/go/app

# Fetch and verify dependencies
WORKDIR /home/go/app
COPY go.mod go.sum ./
RUN go mod download -x
RUN go mod verify

# Bring in and test the source code
COPY . .

# Build binary
ENV CGO_ENABLED=0
ARG TARGETOS TARGETARCH TARGETVARIANT
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOARM=${TARGETVARIANT#v} \
go build \
-v \
-ldflags="-w -s" \
-o "/home/go/maps-vector-uploader" \
"./cmd/maps-vector-uploader"

# Client-side assets of the map viewer (MapLibre GL JS, fonts, sprites),
# they are platform-independent so are fetched once on the build platform
FROM --platform=$BUILDPLATFORM docker.io/library/node:22-bookworm AS assets
RUN apt-get update \
&& apt-get install -y --no-install-recommends unzip \
&& rm -rf /var/lib/apt/lists/*
COPY toolbox/fetch-vector-assets.sh /usr/local/bin/fetch-vector-assets.sh
RUN fetch-vector-assets.sh /assets

FROM ghcr.io/onthegomap/planetiler:0.10.2
# osmium merges OSM extracts of neighbouring regions
RUN apt-get update \
&& apt-get install -y --no-install-recommends osmium-tool \
&& rm -rf /var/lib/apt/lists/*
COPY --from=build /home/go/maps-vector-uploader /usr/local/bin/maps-vector-uploader
COPY --from=assets /assets /usr/share/maps-vector-uploader/assets
COPY --chmod=755 toolbox/prepare-osm-extract.sh /usr/local/bin/prepare-osm-extract
COPY --chmod=755 toolbox/generate-vector-tiles.sh /usr/local/bin/generate-vector-tiles
ENV CINODE_VECTOR_ASSETS_DIR=/usr/share/maps-vector-uploader/assets
# Generated files are owned by the default non-root user
USER ubuntu:ubuntu
# Steps are run as commands, e.g.:
# prepare-osm-extract <name> <pbf-url> <poly-url> [<pbf-url> <poly-url>...]
# generate-vector-tiles <name> <osm-file> <min-zoom> <max-zoom> [planetiler args...]
# maps-vector-uploader
ENTRYPOINT []
CMD [ "/bin/bash" ]
52 changes: 52 additions & 0 deletions build/docker/Dockerfile.maps-vector-uploader
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# syntax=docker/dockerfile:1
ARG GO_VERSION=1.27

# Base image with go compiler and tested source code
FROM --platform=$BUILDPLATFORM docker.io/library/golang:${GO_VERSION} AS build

# Compile and test with non-root user
RUN useradd -ms /bin/bash go
USER go
RUN git config --global --add safe.directory /home/go/app

# Fetch and verify dependencies
WORKDIR /home/go/app
COPY go.mod go.sum ./
RUN go mod download -x
RUN go mod verify

# Bring in and test the source code
COPY . .
# RUN go vet -v ./...
# RUN go test -v ./...

# Build binary
ENV CGO_ENABLED=0
ARG TARGETOS TARGETARCH TARGETVARIANT APP_NAME
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOARM=${TARGETVARIANT#v} \
go build \
-v \
-ldflags="-w -s" \
-o "/home/go/maps-vector-uploader" \
"./cmd/maps-vector-uploader"

# Client-side assets of the map viewer (MapLibre GL JS, fonts, sprites),
# they are platform-independent so are fetched once on the build platform
FROM --platform=$BUILDPLATFORM docker.io/library/node:22-bookworm AS assets
RUN apt-get update \
&& apt-get install -y --no-install-recommends unzip \
&& rm -rf /var/lib/apt/lists/*
COPY toolbox/fetch-vector-assets.sh /usr/local/bin/fetch-vector-assets.sh
RUN fetch-vector-assets.sh /assets

# Force distroless base to use current platform (most likely linux/amd64)
# which is needed since distroless/static is not available for linux/arm/v6
FROM --platform=$BUILDPLATFORM gcr.io/distroless/static AS distroless

FROM scratch
COPY --from=distroless / /
COPY --from=build /home/go/maps-vector-uploader /usr/sbin/maps-vector-uploader
COPY --from=assets /assets /usr/share/maps-vector-uploader/assets
ENV CINODE_VECTOR_ASSETS_DIR=/usr/share/maps-vector-uploader/assets
USER nonroot:nonroot
ENTRYPOINT [ "/usr/sbin/maps-vector-uploader" ]
Loading
Loading