Skip to content

Commit 50a933c

Browse files
committed
Initial commit
0 parents  commit 50a933c

File tree

91 files changed

+7231
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+7231
-0
lines changed

.docker/db-runner-entrypoint

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
# Basic entrypoint for executing shell commande
4+
5+
exec bash -c "$@"

.docker/docker-compose.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
services:
2+
qgis:
3+
image: ${QGIS_IMAGE_TAG}
4+
user: ${UID}:${GID}
5+
command: /src/.docker/run-tests.sh
6+
environment:
7+
# Remove HOME variable if not using database
8+
HOME: /home/qgis
9+
QGIS_VERSION: ${QGIS_VERSION}
10+
volumes:
11+
- {type: bind, source: "..", target: /src}
12+
#
13+
# Remove everything from here if your are not using database
14+
#
15+
- type: bind
16+
source: ./pg_service.conf
17+
target: /etc/postgresql-common/pg_service.conf
18+
depends_on:
19+
db:
20+
condition: service_healthy
21+
profiles:
22+
- qgis
23+
24+
db:
25+
image: 3liz/postgis:${POSTGIS_VERSION}
26+
hostname: db
27+
environment:
28+
POSTGRES_DB: "gis"
29+
POSTGRES_USER: "docker"
30+
POSTGRES_PASSWORD: "docker"
31+
POSTGRES_HOST: "db"
32+
ports:
33+
- "35432:5432"
34+
healthcheck:
35+
test: ["CMD-SHELL", "pg_isready -U docker -d gis -q || exit 1"]
36+
interval: 30s
37+
timeout: 30s
38+
start_interval: 2s
39+
start_period: 10s
40+
41+
db-runner:
42+
build:
43+
context: .
44+
dockerfile_inline: |
45+
FROM 3liz/postgis:${POSTGIS_VERSION}
46+
RUN apt-get -y update && apt-get install -y rename
47+
user: ${UID}:${GID}
48+
command: ${DB_COMMAND}
49+
working_dir: /src/.docker
50+
entrypoint: /src/.docker/db-runner-entrypoint
51+
stop_signal: SIGKILL
52+
volumes:
53+
- {type: bind, source: "..", target: /src}
54+
- {type: bind, source: "../${MODULE_NAME}", target: /plugin}
55+
- type: bind
56+
source: ./pg_service.conf
57+
target: /etc/postgresql-common/pg_service.conf
58+
environment:
59+
MODULE_NAME: ${MODULE_NAME}
60+
SCHEMA: ${SCHEMA}
61+
DB_CURRENT_VERSION: ${DB_CURRENT_VERSION}
62+
depends_on:
63+
db:
64+
condition: service_healthy
65+
healthcheck:
66+
test: ["CMD-SHELL", "[ -f /tmp/.db-runner-ok ] || exit 1"]
67+
start_interval: 2s
68+
start_period: 10s
69+
profiles:
70+
- schemaspy
71+
- dbrunner
72+
73+
# Wait for db-runner to set the /tmp/.db-runner-ok file
74+
schemaspy:
75+
image: schemaspy/schemaspy:latest
76+
volumes:
77+
- {type: bind, source: "../docs/database", target: /output}
78+
command: >-
79+
-t pgsql -host db -db gis -u docker -p docker -port 5432 -s ${SCHEMA} -nopages
80+
depends_on:
81+
db-runner:
82+
condition: service_healthy
83+
profiles:
84+
- schemaspy
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/sh
2+
#
3+
# Explode PostgreSQL database dump into several files, one per type
4+
# LICENCE: GPL 2
5+
# AUTHOR: 3LIZ
6+
7+
8+
echo "# CHECK INPUT PARAMETERS service and schema"
9+
if [ -n "$1" ]; then
10+
echo "# POSTGRESQL SERVICE: $1"
11+
SERVICE=$1
12+
else
13+
echo "ERROR: No PostgreSQL service given as second parameter";
14+
exit;
15+
fi
16+
if [ -n "$2" ]; then
17+
echo "# GIVEN SCHEMA: $2"
18+
SCHEMA=$2
19+
else
20+
SCHEMA="cartads"
21+
echo "# DEFAULT SCHEMA: $SCHEMA";
22+
fi
23+
echo ""
24+
25+
OUTDIR=$SCHEMA
26+
mkdir -p ./$OUTDIR
27+
28+
# STRUCTURE
29+
# Dump database structure
30+
pg_dump service=$SERVICE --schema-only -n $SCHEMA --no-acl --no-owner -Fc -f "$OUTDIR/dump"
31+
32+
# Loop through DB object types and extract SQL
33+
I=10
34+
for ITEM in FUNCTION "TABLE|SEQUENCE|DEFAULT" VIEW INDEX TRIGGER CONSTRAINT COMMENT; do
35+
echo $ITEM
36+
# Extract list of objects for current item
37+
pg_restore --no-acl --no-owner -l $OUTDIR/dump | grep -E "$ITEM" > "$OUTDIR/$ITEM";
38+
# Extract SQL for these objects
39+
pg_restore -f "$OUTDIR"/"$I"_"$ITEM".sql --no-acl --no-owner -L "$OUTDIR/$ITEM" "$OUTDIR/dump";
40+
# Remove file containing list of objects
41+
rm "$OUTDIR/$ITEM";
42+
# Simplify comments inside SQL files
43+
perl -i -0pe 's/\n--\n-- Name: (TABLE )?(COLUMN )?(.+); Type:.+\n--\n\n/\n-- $3\n/g' "$OUTDIR"/"$I"_"$ITEM".sql;
44+
# Remove audit trigger (added afterwards)
45+
if [ $ITEM = 'TRIGGER' ]
46+
then
47+
sed -i '/audit_trigger/d' "$OUTDIR"/"$I"_"$ITEM".sql;
48+
fi
49+
# Remove SET function to remove some compatibility issues between PostgreSQL versions
50+
sed -i "s#SET idle_in_transaction_session_timeout = 0;##g" "$OUTDIR"/"$I"_"$ITEM".sql;
51+
# Remove as integer for sequences, to keep compatibility
52+
sed -i -E "s# AS integer##g" "$OUTDIR"/"$I"_"$ITEM".sql;
53+
# Remove SET search_path
54+
sed -i "s#SELECT pg_catalog.set_config('search_path', '', false);##g" "$OUTDIR"/"$I"_"$ITEM".sql;
55+
# Remove default_table_access_method
56+
sed -i "s#SET default_table_access_method = heap##g" "$OUTDIR"/"$I"_"$ITEM".sql;
57+
# Remove SET transaction_timeout = 0;
58+
sed -i "s#SET transaction_timeout = 0;##g" "$OUTDIR"/"$I"_"$ITEM".sql;
59+
# Remove --- Dumped blah
60+
sed -i 's#-- Dumped.*$##g' "$OUTDIR"/"$I"_"$ITEM".sql;
61+
# Replace FOR EACH ROW EXECUTE FUNCTION (pg13) by FOR EACH ROW EXECUTE PROCEDURE (still ok for Pg13)
62+
sed -i "s#FOR EACH ROW EXECUTE FUNCTION#FOR EACH ROW EXECUTE PROCEDURE#g" "$OUTDIR"/"$I"_"$ITEM".sql;
63+
# Remove new pg_dump 17 restrict lines
64+
sed -i -E "s#\\\(un)?restrict .*##g" "$OUTDIR"/"$I"_"$ITEM".sql;
65+
# Replace public.geometry by geometry
66+
sed -i "s#public.geometry#geometry#g" "$OUTDIR"/"$I"_"$ITEM".sql;
67+
# Rename
68+
rename -f 's#\|#_#g' "$OUTDIR"/"$I"_"$ITEM".sql;
69+
# Increment I
70+
I=$(($I+10));
71+
done
72+
73+
# Remove dump
74+
rm "$OUTDIR/dump"
75+
76+
# NOMENCLATURE
77+
echo "GLOSSARY"
78+
if [ $SCHEMA = 'cartads' ]
79+
then
80+
pg_dump service=$SERVICE --data-only --inserts --column-inserts -n $SCHEMA --no-acl --no-owner --table "$SCHEMA.glossary_*" -f "$OUTDIR"/90_GLOSSARY.sql
81+
sed -i "s#SET idle_in_transaction_session_timeout = 0;##g" "$OUTDIR"/"90_GLOSSARY.sql"
82+
sed -i "s#SELECT pg_catalog.set_config('search_path', '', false);##g" "$OUTDIR"/"90_GLOSSARY.sql"
83+
# Remove --- Dumped blah
84+
sed -i 's#-- Dumped.*$##g' "$OUTDIR"/"90_GLOSSARY.sql";
85+
# Remove SET transaction_timeout = 0;
86+
sed -i "s#SET transaction_timeout = 0;##g" "$OUTDIR"/"90_GLOSSARY.sql";
87+
# Remove new pg_dump 17 restrict lines
88+
sed -i -E "s#\\\(un)?restrict .*##g" "$OUTDIR"/"90_GLOSSARY.sql";
89+
fi

.docker/install_db.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
echo 'Installation from latest version'
4+
psql service=test -c "DROP SCHEMA IF EXISTS ${SCHEMA} CASCADE;" > /dev/null
5+
psql service=test -f /src/${MODULE_NAME}/install/sql/00_initialize_database.sql > /dev/null
6+
for sql_file in `ls -d -v /src/${MODULE_NAME}/install/sql/${SCHEMA}/*.sql`; do
7+
echo "${sql_file}"
8+
psql service=test -f ${sql_file} > /dev/null;
9+
done;

.docker/install_db_and_wait.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
set -e
2+
3+
./install_db.sh
4+
touch /tmp/.db-runner-ok
5+
sleep infinity
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# 1.Install the database with a stored previous version.
5+
# 2.Run the migrations scripts up to the current version.
6+
# 3.Output the migrate schema in tests/.tests-migration-<from>-to-<current>
7+
# 4.Generate a diff `sql.patch` between the current schema and the upgraded one
8+
#
9+
10+
set -eu
11+
12+
current_version=$DB_CURRENT_VERSION
13+
db_version=${DB_INSTALL_VERSION:-$((current_version-1))}
14+
15+
install_dir=/src/tests/data/install-version-$db_version/sql
16+
17+
if [[ ! -e $install_dir ]]; then
18+
echo "No installation version for database version $db_version"
19+
exit 1
20+
fi
21+
22+
echo "== Installation from version $db_version"
23+
psql service=test -c "DROP SCHEMA IF EXISTS ${SCHEMA} CASCADE;" > /dev/null
24+
psql service=test -f $install_dir/00_initialize_database.sql > /dev/null
25+
26+
for sql_file in `ls -d -v $install_dir/${SCHEMA}/*.sql`; do
27+
echo "${sql_file}"
28+
psql service=test -f ${sql_file} > /dev/null
29+
done
30+
31+
echo ""
32+
33+
start_migration=$((db_version+1))
34+
echo "== Run SQL migrations stored from version $db_version to $current_version =="
35+
for ((i=start_migration;i<=current_version;i++)); do
36+
migration=/src/${MODULE_NAME}/install/sql/upgrade/upgrade_to_$i.sql
37+
if [[ ! -e $migration ]]; then
38+
echo "Missing migration file $migration"
39+
exit 1
40+
fi
41+
echo "Running migration: ${migration}"
42+
psql service=test -f ${migration} > /dev/null;
43+
done;
44+
echo ""
45+
46+
cd /src
47+
48+
echo '== Export update database as installation SQL files'
49+
destination_dir=tests/.test-migration-$db_version-to-$current_version
50+
rm -rf $destination_dir
51+
mkdir -p $destination_dir/sql
52+
pushd $destination_dir/sql
53+
/src/.docker/export_database_structure_to_SQL.sh test ${SCHEMA}
54+
popd
55+
56+
57+
# Generate a diff file between current and install version
58+
echo "== Creating patch file"
59+
set +e # Suppress exit on erreur
60+
diff -urB $MODULE_NAME/install/sql/$SCHEMA $destination_dir/sql/$SCHEMA > $destination_dir/sql.patch
61+
62+
[[ $? -eq 1 ]] && true
63+
echo "== Done"

.docker/pg_service.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[test]
2+
host=db
3+
port=5432
4+
user=docker
5+
password=docker
6+
dbname=gis

.docker/processing_doc.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
export $(grep -v '^#' .env | xargs)
3+
4+
#xhost +
5+
6+
docker run -d \
7+
--name qgis-testing-environment \
8+
-v $(pwd)/../${PLUGIN_NAME}:/tests_directory/${PLUGIN_NAME} \
9+
-v $(pwd)/../docs/processing:/processing \
10+
-e DISPLAY=:99 \
11+
qgis/qgis:release-3_34
12+
13+
sleep 10
14+
15+
echo "Setting up"
16+
docker exec -t qgis-testing-environment sh -c "qgis_setup.sh ${PLUGIN_NAME}"
17+
docker exec -t qgis-testing-environment sh \
18+
-c "qgis_testrunner.sh ${PLUGIN_NAME}.qgis_plugin_tools.infrastructure.doc_processing.generate_processing_doc"
19+
20+
docker kill qgis-testing-environment
21+
docker rm qgis-testing-environment

.docker/reformat_sql_install.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
echo 'Generating SQL files'
4+
cd /src/${MODULE_NAME}/install/sql/
5+
./export_database_structure_to_SQL.sh test ${SCHEMA}
6+

.docker/run-tests.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
#
3+
# Run test in docker QGIS image
4+
#
5+
6+
set -e
7+
8+
cd /src
9+
10+
VENV=/src/.docker-venv-$QGIS_VERSION
11+
12+
python3 -m venv $VENV --system-site-package
13+
14+
echo "Installing requirements..."
15+
$VENV/bin/pip install -q --no-cache -r requirements/tests.txt
16+
17+
cd tests && $VENV/bin/python -m pytest -v
18+
19+

0 commit comments

Comments
 (0)