Skip to content

Commit 49d677b

Browse files
Rub21Rub21
and
Rub21
authored
CGIMAP container (#300)
* Add cgmap container * Correct the misspelled name * Add helm template for cgimap * Update cgimap dockerfile * Update tiler-imposm dockerfile * Update python * Update cgimap container * Update cgimap container * Update container for cgimap * Build cgimap image using multistage * Update cgimap config Update relese tag Pass env vars in web container for cgimap Update release tag Update tag name Update release tags * Update release tags * Add memcache server for cgimap * Update cgimap start and github action * Add --daemon for cgimap * Set empty values for planetFiles.image * Disable cgimap in chartpress * Use chartpress==2.3.0 * Add HorizontalPodAutoscaler for cgimap * Update web-api container * Fix apache config * Add PG password for tiler-db config as env var * Update cgimap dockerfile using code form original repo * Enable resources option for requests and limits - cgimap * Evaluate memoryUtilization for web container - autoscaling --------- Co-authored-by: Rub21 <[email protected]>
1 parent b33597b commit 49d677b

20 files changed

+699
-289
lines changed

.github/workflows/chartpress.yaml

+39-41
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,42 @@ jobs:
44
build:
55
runs-on: ubuntu-22.04
66
steps:
7-
- uses: actions/checkout@v3
8-
- name: Login to DockerHub
9-
uses: docker/login-action@v2
10-
with:
11-
username: ${{ secrets.DOCKER_USERNAME }}
12-
password: ${{ secrets.DOCKER_PASSWORD }}
13-
- name: Setup Python
14-
uses: actions/setup-python@v4
15-
with:
16-
python-version: '3.11'
17-
- name: Setup Git
18-
run: |
19-
git config --global user.email "[email protected]"
20-
git config --global user.name "Github Action"
21-
- name: Install Chartpress and Python modules
22-
run: |
23-
pip install -v chartpress six yq
24-
- name: Set env vars for publish charts
25-
run: |
26-
GIT_BRANCH_NAME=${GITHUB_BASE_REF:-${GITHUB_REF#refs/heads/}}
27-
GIT_BRANCH_NAME=${GIT_BRANCH_NAME/\//_}
28-
OSM_SEED_VERSION=$(yq -r .appVersion ./osm-seed/Chart.yaml)
29-
SHORT_GITHUB_SHA=${GITHUB_SHA::7}
30-
echo "GIT_BRANCH_NAME=$GIT_BRANCH_NAME" >> $GITHUB_ENV
31-
echo "OSM_SEED_VERSION=$OSM_SEED_VERSION" >> $GITHUB_ENV
32-
echo "SHORT_GITHUB_SHA=$SHORT_GITHUB_SHA" >> $GITHUB_ENV
33-
- name: Run Chartpress
34-
env:
35-
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
36-
GITHUB_EVENT_NAME: ${{ github.event_name }}
37-
run: |
38-
if [[ $GIT_BRANCH_NAME = "main" ]]
39-
then
40-
chartpress --push --publish-chart --tag ${OSM_SEED_VERSION}
41-
elif [[ $GIT_BRANCH_NAME = "develop" ]]
42-
then
43-
chartpress --push --publish-chart --tag ${OSM_SEED_VERSION}-dev.h$SHORT_GITHUB_SHA
44-
else
45-
chartpress --push --publish-chart
46-
fi
47-
7+
- uses: actions/checkout@v1
8+
- name: Login to DockerHub
9+
uses: docker/login-action@v1
10+
with:
11+
username: ${{ secrets.DOCKER_USERNAME }}
12+
password: ${{ secrets.DOCKER_PASSWORD }}
13+
- name: Setup python
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: '3.7'
17+
- name: Setup git
18+
run: git config --global user.email "[email protected]" && git config --global user.name "Github Action"
19+
- name: Install Chartpress and some python modules
20+
run: |
21+
pip install -v chartpress==2.3.0 && pip install six && pip install yq
22+
- name: Set env vars for publish charts
23+
run: |
24+
GIT_BRANCH_NAME=${GITHUB_BASE_REF:-${GITHUB_REF#refs/heads/}}
25+
GIT_BRANCH_NAME=${GIT_BRANCH_NAME/\//_}
26+
OSM_SEED_VERSION=$(yq -r .appVersion ./osm-seed/Chart.yaml)
27+
SHORT_GITHUB_SHA=${GITHUB_SHA::7}
28+
echo "GIT_BRANCH_NAME=$GIT_BRANCH_NAME" >> $GITHUB_ENV
29+
echo "OSM_SEED_VERSION=$OSM_SEED_VERSION" >> $GITHUB_ENV
30+
echo "SHORT_GITHUB_SHA=$SHORT_GITHUB_SHA" >> $GITHUB_ENV
31+
- name: Run Chartpress
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
34+
GITHUB_EVENT_NAME: ${{ github.event_name }}
35+
run: |
36+
if [[ $GIT_BRANCH_NAME = "main" ]]
37+
then
38+
chartpress --push --publish-chart --tag ${OSM_SEED_VERSION}
39+
elif [[ $GIT_BRANCH_NAME = "develop" ]]
40+
then
41+
chartpress --push --publish-chart --tag ${OSM_SEED_VERSION}-dev.h$SHORT_GITHUB_SHA
42+
else
43+
chartpress --push --publish-chart
44+
fi
45+

chartpress.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ charts:
3030
valuesPath: tilerServer.image
3131
tasking-manager-api:
3232
valuesPath: tmApi.image
33-
# tiler-visor:
34-
# valuesPath: tilerVisor.image
3533
nominatim:
3634
valuesPath: nominatimApi.image
3735
overpass-api:
@@ -48,4 +46,5 @@ charts:
4846
valuesPath: osmchaDb.image
4947
planet-files:
5048
valuesPath: planetFiles.image
51-
49+
# cgimap:
50+
# valuesPath: cgimap.image

compose/cgimap.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: '3'
2+
services:
3+
# #####################################################
4+
# ## cgmap section
5+
# #####################################################
6+
cgimap:
7+
image: osmseed-cgimap:v1
8+
build:
9+
context: ../images/cgimap
10+
dockerfile: Dockerfile
11+
ports:
12+
- '80:80'
13+
volumes:
14+
- ../data/cgimap-data:/apps/data/
15+
# command: >
16+
# /bin/bash -c " ./start.sh"
17+
env_file:
18+
- ../envs/.env.db

images/cgimap/Dockerfile

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
FROM debian:bookworm-slim AS builder
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
5+
RUN apt-get update -qq && \
6+
apt-get install -y gcc g++ make cmake \
7+
libfcgi-dev libxml2-dev libmemcached-dev libbrotli-dev \
8+
libboost-program-options-dev libcrypto++-dev libyajl-dev \
9+
libpqxx-dev zlib1g-dev libfmt-dev \
10+
postgresql-15 postgresql-server-dev-all dpkg-dev file ca-certificates git \
11+
--no-install-recommends && \
12+
apt-get clean && \
13+
rm -rf /var/lib/apt/lists/*
14+
15+
WORKDIR /app
16+
17+
# Clone application
18+
ENV CGIMAP_GITSHA=8ea707e10aeab5698e6859856111816d75354592
19+
RUN git clone https://github.com/zerebubuth/openstreetmap-cgimap.git /app \
20+
&& git checkout $CGIMAP_GITSHA
21+
22+
# Compile, install and remove source
23+
RUN mkdir build && cd build && \
24+
CXXFLAGS="-flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2" cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Release && \
25+
make -j${nproc} && \
26+
ctest --output-on-failure && \
27+
cmake --build . -t package
28+
29+
FROM debian:bookworm-slim
30+
31+
COPY --from=builder /app/build/*.deb /app_deb/
32+
33+
RUN apt-get update -qq && \
34+
apt install --no-install-recommends -y /app_deb/*.deb postgresql-client procps && \
35+
apt-get clean && \
36+
rm -rf /var/lib/apt/lists/*
37+
38+
RUN groupadd -g 61000 cgimap && \
39+
useradd -g 61000 -l -M -s /bin/false -u 61000 cgimap
40+
41+
EXPOSE 8000
42+
43+
COPY ./*.sh .
44+
45+
CMD ["/start.sh"]

images/cgimap/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# openstreetmap-cgimap
2+
3+
This container is built using the configuration from Zerebubuth's OpenStreetMap CGImap GitHub repository, with minor modifications.
4+
5+
6+
# Build and up
7+
8+
```sh
9+
docker compose -f compose/cgimap.yml build
10+
docker compose -f compose/cgimap.yml up
11+
```
12+
13+
Note: Ensure that you are running PostgreSQL on your local machine. For example:
14+
15+
16+
```sh
17+
kubectl port-forward staging-db-0 5432:5432
18+
```
19+
20+
Check results:
21+
22+
http://localhost/api/0.6/map?bbox=-77.09529161453248,-12.071898885565846,-77.077374458313,-12.066474684936727

images/cgimap/liveness.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
pgrep -f openstreetmap-cgimap > /dev/null
3+
cgimap_status=$?
4+
5+
# Check PostgreSQL connection
6+
PGPASSWORD="$POSTGRES_PASSWORD" psql -h "$POSTGRES_HOST" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "SELECT 1;" > /dev/null 2>&1
7+
postgres_status=$?
8+
9+
# Exit code logic
10+
if [ $cgimap_status -eq 0 ] && [ $postgres_status -eq 0 ]; then
11+
echo "cgimap and PostgreSQL are healthy"
12+
exit 0
13+
else
14+
[ $cgimap_status -ne 0 ] && echo "cgimap not running" >&2
15+
[ $postgres_status -ne 0 ] && echo "cannot connect to PostgreSQL" >&2
16+
exit 1
17+
fi

images/cgimap/start.sh

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
3+
export PGPASSWORD=$POSTGRES_PASSWORD
4+
export CGIMAP_HOST=$POSTGRES_HOST
5+
export CGIMAP_DBNAME=$POSTGRES_DB
6+
export CGIMAP_USERNAME=$POSTGRES_USER
7+
export CGIMAP_PASSWORD=$POSTGRES_PASSWORD
8+
export CGIMAP_OAUTH_HOST=$POSTGRES_HOST
9+
export CGIMAP_UPDATE_HOST=$POSTGRES_HOST
10+
# Export CGIMAP configuration
11+
export CGIMAP_LOGFILE="/var/www/log/cgimap.log"
12+
export CGIMAP_MEMCACHE=$MEMCACHE_SERVER
13+
# Average number of bytes/s to allow each client
14+
export CGIMAP_RATELIMIT="204800"
15+
# Maximum debt in MB to allow each client before rate limiting
16+
export CGIMAP_MAXDEBT="2048"
17+
export CGIMAP_MAP_AREA="0.25"
18+
export CGIMAP_MAP_NODES="100000"
19+
export CGIMAP_MAX_WAY_NODES="2000"
20+
export CGIMAP_MAX_RELATION_MEMBERS="32000"
21+
# export CGIMAP_RATELIMIT_UPLOAD="true"
22+
export CGIMAP_MODERATOR_RATELIMIT="1048576"
23+
export CGIMAP_MODERATOR_MAXDEBT="2048"
24+
25+
if [[ "$WEBSITE_STATUS" == "database_readonly" || "$WEBSITE_STATUS" == "api_readonly" ]]; then
26+
export CGIMAP_DISABLE_API_WRITE="true"
27+
fi
28+
29+
if [[ "$WEBSITE_STATUS" == "database_offline" || "$WEBSITE_STATUS" == "api_offline" ]]; then
30+
echo "Website is $WEBSITE_STATUS. No action required for cgimap service."
31+
else
32+
# PostgreSQL options to disable certain joins
33+
export PGOPTIONS="-c enable_mergejoin=false -c enable_hashjoin=false"
34+
# Display current PostgreSQL settings
35+
psql -h $POSTGRES_HOST -U $POSTGRES_USER -c "SHOW enable_mergejoin;"
36+
psql -h $POSTGRES_HOST -U $POSTGRES_USER -c "SHOW enable_hashjoin;"
37+
# Start the cgimap service
38+
/usr/local/bin/openstreetmap-cgimap --port=8000 --daemon --instances=10
39+
fi

images/tiler-imposm/Dockerfile

+19-6
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,26 @@ RUN apt-get install -y \
2222
software-properties-common && \
2323
rm -rf /var/lib/apt/lists/*
2424

25-
# # Install python
26-
RUN add-apt-repository ppa:deadsnakes/ppa && \
25+
# Install Python 3.6
26+
RUN apt-get update && \
27+
apt-get install -y software-properties-common && \
28+
add-apt-repository -y ppa:ubuntu-toolchain-r/test && \
2729
apt-get update && \
28-
apt-get install -y build-essential python3.6 python3.6-dev python3-pip && \
29-
rm -rf /var/lib/apt/lists/* && \
30-
python3 -m pip install pip --upgrade && \
31-
python3 -m pip install wheel
30+
apt-get install -y gcc-8 g++-8 && \
31+
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 100 && \
32+
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 100 && \
33+
apt-get install -y build-essential wget libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev && \
34+
wget https://www.python.org/ftp/python/3.6.15/Python-3.6.15.tgz && \
35+
tar xzf Python-3.6.15.tgz && \
36+
cd Python-3.6.15 && \
37+
./configure --enable-optimizations && \
38+
make altinstall && \
39+
cd .. && \
40+
rm -rf Python-3.6.15 Python-3.6.15.tgz && \
41+
apt-get install -y python3-pip && \
42+
python3.6 -m pip install pip --upgrade && \
43+
python3.6 -m pip install wheel && \
44+
rm -rf /var/lib/apt/lists/*
3245

3346
# Install postgresql-client
3447
RUN apt-get update && apt-get install -y postgresql-client && \

0 commit comments

Comments
 (0)