Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CGIMAP container #300

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
6 changes: 3 additions & 3 deletions chartpress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ charts:
valuesPath: tilerServer.image
tasking-manager-api:
valuesPath: tmApi.image
# tiler-visor:
# valuesPath: tilerVisor.image
nominatim:
valuesPath: nominatimApi.image
overpass-api:
Expand All @@ -48,4 +46,6 @@ charts:
valuesPath: osmchaDb.image
planet-files:
valuesPath: planetFiles.image

cgimap:
valuesPath: cgimap.image

18 changes: 18 additions & 0 deletions compose/cgimap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3'
services:
# #####################################################
# ## cgmap section
# #####################################################
cgimap:
image: osmseed-cgimap:v1
build:
context: ../images/cgimap
dockerfile: Dockerfile
ports:
- '80:80'
volumes:
- ../data/cgimap-data:/apps/data/
# command: >
# /bin/bash -c " ./start.sh"
env_file:
- ../envs/.env.db
27 changes: 27 additions & 0 deletions images/cgimap/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM ruby:3.3.0 AS builder
ENV DEBIAN_FRONTEND=noninteractive
ENV workdir=/var/www
ENV CGIMAP_GITSHA=8ea707e10aeab5698e6859856111816d75354592
RUN apt-get update && apt-get install -y \
build-essential cmake git-core curl file \
libxml2-dev libpqxx-dev libfcgi-dev zlib1g-dev libbrotli-dev \
libboost-program-options-dev libfmt-dev libmemcached-dev libcrypto++-dev \
libargon2-dev libyajl-dev libapache2-mod-fcgid \
&& rm -rf /var/lib/apt/lists/*
ENV cgimap=/tmp/openstreetmap-cgimap
RUN git clone -b master https://github.com/zerebubuth/openstreetmap-cgimap.git $cgimap \
&& cd $cgimap \
&& git checkout $CGIMAP_GITSHA \
&& mkdir build && cd build && cmake .. && cmake --build .

FROM ruby:3.3.0
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
libxml2 libpqxx-6.4 libfcgi zlib1g libbrotli1 \
libboost-program-options1.74.0 libfmt-dev libmemcached11 libcrypto++8 \
libargon2-1 libyajl2 libapache2-mod-fcgid \
&& rm -rf /var/lib/apt/lists/*

COPY --from=builder /tmp/openstreetmap-cgimap/build/openstreetmap-cgimap /usr/local/bin/openstreetmap-cgimap
RUN echo "/usr/local/lib" > /etc/ld.so.conf.d/local_libs.conf && ldconfig
CMD ["openstreetmap-cgimap"]
22 changes: 22 additions & 0 deletions images/cgimap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# openstreetmap-cgimap

This container is built using the configuration from Zerebubuth's OpenStreetMap CGImap GitHub repository, with minor modifications.


# Build and up

```sh
docker compose -f compose/cgimap.yml build
docker compose -f compose/cgimap.yml up
```

Note: Ensure that you are running PostgreSQL on your local machine. For example:


```sh
kubectl port-forward staging-db-0 5432:5432
```

Check results:

http://localhost/api/0.6/map?bbox=-77.09529161453248,-12.071898885565846,-77.077374458313,-12.066474684936727
39 changes: 39 additions & 0 deletions images/cgimap/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

export PGPASSWORD=$POSTGRES_PASSWORD
export CGIMAP_HOST=$POSTGRES_HOST
export CGIMAP_DBNAME=$POSTGRES_DB
export CGIMAP_USERNAME=$POSTGRES_USER
export CGIMAP_PASSWORD=$POSTGRES_PASSWORD
export CGIMAP_OAUTH_HOST=$POSTGRES_HOST
export CGIMAP_UPDATE_HOST=$POSTGRES_HOST
# Export CGIMAP configuration
export CGIMAP_LOGFILE="/var/www/log/cgimap.log"
export CGIMAP_MEMCACHE=$OPENSTREETMAP_MEMCACHE_SERVERS
# Average number of bytes/s to allow each client
export CGIMAP_RATELIMIT="204800"
# Maximum debt in MB to allow each client before rate limiting
export CGIMAP_MAXDEBT="2048"
export CGIMAP_MAP_AREA="0.25"
export CGIMAP_MAP_NODES="100000"
export CGIMAP_MAX_WAY_NODES="2000"
export CGIMAP_MAX_RELATION_MEMBERS="32000"
# export CGIMAP_RATELIMIT_UPLOAD="true"
export CGIMAP_MODERATOR_RATELIMIT="1048576"
export CGIMAP_MODERATOR_MAXDEBT="2048"

if [[ "$WEBSITE_STATUS" == "database_readonly" || "$WEBSITE_STATUS" == "api_readonly" ]]; then
export CGIMAP_DISABLE_API_WRITE="true"
fi

if [[ "$WEBSITE_STATUS" == "database_offline" || "$WEBSITE_STATUS" == "api_offline" ]]; then
echo "Website is $WEBSITE_STATUS. No action required for cgimap service."
else
# PostgreSQL options to disable certain joins
export PGOPTIONS="-c enable_mergejoin=false -c enable_hashjoin=false"
# Display current PostgreSQL settings
psql -h $POSTGRES_HOST -U $POSTGRES_USER -c "SHOW enable_mergejoin;"
psql -h $POSTGRES_HOST -U $POSTGRES_USER -c "SHOW enable_hashjoin;"
# Start the cgimap service
/usr/local/bin/openstreetmap-cgimap --port=8000 --daemon --instances=10
fi
25 changes: 19 additions & 6 deletions images/tiler-imposm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,26 @@ RUN apt-get install -y \
software-properties-common && \
rm -rf /var/lib/apt/lists/*

# # Install python
RUN add-apt-repository ppa:deadsnakes/ppa && \
# Install Python 3.6
RUN apt-get update && \
apt-get install -y software-properties-common && \
add-apt-repository -y ppa:ubuntu-toolchain-r/test && \
apt-get update && \
apt-get install -y build-essential python3.6 python3.6-dev python3-pip && \
rm -rf /var/lib/apt/lists/* && \
python3 -m pip install pip --upgrade && \
python3 -m pip install wheel
apt-get install -y gcc-8 g++-8 && \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 100 && \
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 100 && \
apt-get install -y build-essential wget libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev && \
wget https://www.python.org/ftp/python/3.6.15/Python-3.6.15.tgz && \
tar xzf Python-3.6.15.tgz && \
cd Python-3.6.15 && \
./configure --enable-optimizations && \
make altinstall && \
cd .. && \
rm -rf Python-3.6.15 Python-3.6.15.tgz && \
apt-get install -y python3-pip && \
python3.6 -m pip install pip --upgrade && \
python3.6 -m pip install wheel && \
rm -rf /var/lib/apt/lists/*

# Install postgresql-client
RUN apt-get update && apt-get install -y postgresql-client && \
Expand Down
66 changes: 66 additions & 0 deletions osm-seed/templates/cgimap/cgimap-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{{- if .Values.cgimap.enabled -}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}-cgimap-deployment
labels:
app: {{ template "osm-seed.name" . }}
component: cgimap-deployment
environment: {{ .Values.environment }}
release: {{ .Release.Name }}
spec:
replicas: {{ .Values.cgimap.replicaCount }}
selector:
matchLabels:
app: {{ template "osm-seed.name" . }}
release: {{ .Release.Name }}
run: {{ .Release.Name }}-cgimap-deployment
template:
metadata:
labels:
app: {{ template "osm-seed.name" . }}
release: {{ .Release.Name }}
run: {{ .Release.Name }}-cgimap-deployment
spec:
containers:
- name: {{ .Chart.Name }}-cgimap
image: "{{ .Values.cgimap.image.name }}:{{ .Values.cgimap.image.tag }}"
ports:
- name: http
containerPort: 8000
protocol: TCP
livenessProbe:
exec:
command:
- /bin/bash
- -c
- /liveness.sh
initialDelaySeconds: 30
timeoutSeconds: 5
periodSeconds: 10
failureThreshold: 3
{{- if .Values.cgimap.resources.enabled }}
resources:
requests:
memory: {{ .Values.cgimap.resources.requests.memory }}
cpu: {{ .Values.cgimap.resources.requests.cpu }}
limits:
memory: {{ .Values.cgimap.resources.limits.memory }}
cpu: {{ .Values.cgimap.resources.limits.cpu }}
{{- end }}
env:
- name: POSTGRES_HOST
value: {{ .Release.Name }}-db
- name: POSTGRES_DB
value: {{ .Values.db.env.POSTGRES_DB }}
- name: PGPASSWORD
value: {{ quote .Values.db.env.POSTGRES_PASSWORD }}
- name: POSTGRES_PASSWORD
value: {{ quote .Values.db.env.POSTGRES_PASSWORD }}
- name: POSTGRES_USER
value: {{ .Values.db.env.POSTGRES_USER }}
{{- if .Values.cgimap.nodeSelector.enabled }}
nodeSelector:
{{ .Values.cgimap.nodeSelector.label_key }} : {{ .Values.cgimap.nodeSelector.label_value }}
{{- end }}
{{- end }}
37 changes: 37 additions & 0 deletions osm-seed/templates/cgimap/cgimap-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{- if .Values.cgimap.enabled -}}
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}-cgimap-service
labels:
app: {{ template "osm-seed.name" . }}
component: cgimap-service
environment: {{ .Values.environment }}
release: {{ .Release.Name }}
annotations:
{{- if and (eq .Values.serviceType "LoadBalancer") .Values.AWS_SSL_ARN }}
service.beta.kubernetes.io/aws-load-balancer-ssl-cert: {{ .Values.AWS_SSL_ARN }}
service.beta.kubernetes.io/aws-load-balancer-backend-protocol: http
service.beta.kubernetes.io/aws-load-balancer-ssl-ports: https
{{- end }}
{{- if eq .Values.serviceType "ClusterIP" }}
kubernetes.io/ingress.class: nginx
cert-manager.io/cluster-issuer: letsencrypt-prod-issuer
{{- else }}
fake.annotation: fake
{{- end }}
{{- with .Values.cgimap.serviceAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
type: {{ .Values.serviceType }}
ports:
- port: 80
targetPort: http
protocol: TCP
name: http
selector:
app: {{ template "osm-seed.name" . }}
release: {{ .Release.Name }}
run: {{ .Release.Name }}-cgimap-deployment
{{- end }}
12 changes: 12 additions & 0 deletions osm-seed/templates/web/web-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ spec:
value: {{ .Values.web.env.RAILS_STORAGE_REGION | quote }}
- name: RAILS_STORAGE_BUCKET
value: {{ .Values.web.env.RAILS_STORAGE_BUCKET | quote }}
# Cgimap run in external container
{{- if and .Values.web.env.EXTERNAL .Values.cgimap.enabled }}
- name: CGIMAP_URL
value: {{ .Release.Name }}-cgimap-service
- name: CGIMAP_PORT
value: {{ quote 80 }}
{{- else }}
- name: CGIMAP_URL
value: "127.0.0.1"
- name: CGIMAP_PORT
value: {{ quote 8000 }}
{{- end }}
volumeMounts:
- mountPath: /dev/shm
name: shared-memory
Expand Down
Loading
Loading