Skip to content

Commit 6a853cb

Browse files
authored
Merge pull request #1 from danceb/main
Make QGIS Server URL configurable via ENV and read project names from database
2 parents 41fcf2c + 60a970d commit 6a853cb

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

Dockerfile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM alpine:3.21
22

3-
RUN apk add --no-cache curl cronie
3+
RUN apk add --no-cache curl cronie postgresql-client
44

55
WORKDIR /app
66
COPY qgs_cache_preseed.sh /app/qgs_cache_preseed.sh
@@ -17,6 +17,14 @@ ENV FCGI_INSTANCES=10
1717
# The sleep interval in seconds between sending requests
1818
ENV SLEEP_INTERVAL=1
1919

20+
# The default URL of the QGIS server to send requests to
21+
ENV DEFAULT_QGIS_SERVER_URL="http://qwc-qgis-server/ows/"
22+
23+
# Connection URL for configuration database to read QGIS project files
24+
ENV PGSERVICEFILE="/srv/pg_service.conf"
25+
ENV CONFIG_DB_URL="postgresql:///?service=qgisprojects"
26+
# The name of the DB schema which stores the project files in a table 'qgis_projects'.
27+
ENV PG_DB_SCHEMA="qwc_config"
2028

2129
COPY entrypoint.sh /entrypoint.sh
2230
RUN chmod +x /entrypoint.sh

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Add the `qwc-qgs-cache-preseed` container configuration to your QWC `docker-comp
3737
- ./volumes/preseed_services.txt:/preseed_services.txt:ro
3838
# OR
3939
# - ./volumes/qgs-resources:/data:ro
40+
# OR
41+
# - ./pg_service.conf:/srv/pg_service.conf:ro
4042
```
4143

4244
Configuration
@@ -48,16 +50,19 @@ To control which QGS projects will be processed, you can:
4850
- `subdir/projectname` for a QGS file located in `qgs-resources/subdir/projectname.qgs`
4951
- `pg/schema/projectname` for a QGS project located in a DB in schema `schema` and named `projectname`
5052
- Mount the `qgs-resources` dir (or whichever directory is mounted to `/data` for `qwc-qgis-server`) to `/data`, which will be then searches for projects (ending with `$QGS_EXT`).
53+
- Mount a postgres service configuration file to `/srv/pg_service.conf`. The service file should contain a `[qgisprojects]` service definition. It would consider all projects located in the service DB in a specific schema. The ENV `PG_DB_SCHEMA` can be used to set the schema name (defaults to `qwc_config`).
5154

5255
The following environment variables can be set:
5356

54-
| Name | Default | Description |
55-
|----------------------|-------------|----------------------------------------------------------------------------------|
56-
| `CRON_SCHEDULE` | `0 3 * * *` | Interval at which the pre-seeding script is run. Default: every day at 03:00. |
57-
| `EXECUTE_ON_STARTUP` | `0` | Whether to run the script when the container starts. |
58-
| `QGS_EXT` | `.qgs` | The QGS project extension to look for (`.qgs` or `.qgz`). |
59-
| `FCGI_INSTANCES` | `10` | The number of FCGI instances (i.e. the number if simultaneous requests to send). |
60-
| `SLEEP_INTERVAL` | `1` | The sleep interval in seconds between sending requests. |
57+
| Name | Default | Description |
58+
|---------------------------|-------------------------------|----------------------------------------------------------------------------------|
59+
| `CRON_SCHEDULE` | `0 3 * * *` | Interval at which the pre-seeding script is run. Default: every day at 03:00. |
60+
| `EXECUTE_ON_STARTUP` | `0` | Whether to run the script when the container starts. |
61+
| `QGS_EXT` | `.qgs` | The QGS project extension to look for (`.qgs` or `.qgz`). |
62+
| `FCGI_INSTANCES` | `10` | The number of FCGI instances (i.e. the number if simultaneous requests to send). |
63+
| `SLEEP_INTERVAL` | `1` | The sleep interval in seconds between sending requests. |
64+
| `DEFAULT_QGIS_SERVER_URL` | `http://qwc-qgis-server/ows/` | The default URL of the QGIS server to send requests to. |
65+
| `PG_DB_SCHEMA` | `qwc_config` | The name of the DB schema which stores QGIS projects in a table `qgis_projects`. |
6166

6267
*Note*: You should set `FCGI_MIN_PROCESSES` equals to `FCGI_MAX_PROCESSES` in the `qwc-qgis-server` container configuration
6368
and `FCGI_INSTANCES` to the same number in the `qwc-qgs-cache-preseed` container configuration.

entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mkdir -p $HOME/.cache
44
# Wait for qwc-qgis-server
55
while true; do
66
echo -n "Waiting for qwc-qgis-server"
7-
status_code=$(curl -o /dev/null -s -w "%{http_code}" http://qwc-qgis-server/ows)
7+
status_code=$(curl -o /dev/null -s -w "%{http_code}" ${DEFAULT_QGIS_SERVER_URL})
88
if [ "$status_code" -eq 000 ]; then
99
echo -n "."
1010
sleep 1

qgs_cache_preseed.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,22 @@ if [ -f /preseed_services.txt ]; then
1414
elif [ -d /data ]; then
1515
echo "Scanning /data for projects..."
1616
service_names=$(find /data -name '*'${QGS_EXT} | sed "s|^/data/||; s|${QGS_EXT}$||")
17+
elif [ -f /srv/pg_service.conf ]; then
18+
echo "Reading services names from database..."
19+
if ! psql service="qgisprojects" -c '\q' 2>/dev/null; then
20+
echo "Database is not available. Exiting."
21+
exit 1
22+
else
23+
service_names=$(psql service="qgisprojects" -t -A -c "SELECT name FROM ${PG_DB_SCHEMA}.qgis_projects;" | sed "s|^|pg/${PG_DB_SCHEMA}/|")
24+
fi
1725
else
18-
echo "No service names found. Mount a file to /preseed_services.txt or mount your projects dir to /data."
26+
echo "No service names found. Mount a file to /preseed_services.txt, mount your projects dir to /data or use a database connection."
1927
exit 0
2028
fi
2129

2230
echo "$service_names" | while IFS= read -r service_name; do
2331
echo "Processing service ${service_name}"
24-
url="http://qwc-qgis-server/ows/${service_name}?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.3.0"
32+
url="${DEFAULT_QGIS_SERVER_URL}${service_name}?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.3.0"
2533
echo "- Request URL: ${url}"
2634

2735
pids=""

0 commit comments

Comments
 (0)