-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test: Add a container to run the tests (#479)
- Loading branch information
Showing
11 changed files
with
255 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ __pycache__/ | |
# Distribution / packaging | ||
.Python | ||
env/ | ||
venv/ | ||
bin/ | ||
build/ | ||
develop-eggs/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM ubuntu:22.04 | ||
|
||
COPY ./helpers/install_requirements.sh / | ||
RUN /install_requirements.sh | ||
|
||
COPY ./helpers/init_postgres.sh / | ||
env PGDATA="/var/lib/postgresql/data" | ||
env POSTGRES_PATH="/usr/lib/postgresql/14" | ||
RUN su postgres -c /init_postgres.sh | ||
|
||
ENV SPATIALITE_LIBRARY_PATH="/usr/lib/x86_64-linux-gnu/mod_spatialite.so" | ||
|
||
COPY ./helpers/init_mysql.sh / | ||
RUN /init_mysql.sh | ||
|
||
COPY ./helpers/entrypoint.sh / | ||
ENTRYPOINT ["/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
|
||
cd "${SCRIPT_DIR}" | ||
docker build -t geoalchemy2 . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "starting postgres" | ||
(su postgres -c '${POSTGRES_PATH}/bin/pg_ctl start' > /dev/null 2>&1) & | ||
|
||
while ! ${POSTGRES_PATH}/bin/pg_isready --quiet; do | ||
sleep 0.2 | ||
done | ||
|
||
echo "starting mysql" | ||
/etc/init.d/mysql start | ||
|
||
echo "waiting for mysql to start" | ||
while ! mysqladmin ping -h 127.0.0.1 --silent; do | ||
sleep 0.2 | ||
done | ||
|
||
echo "###############################" | ||
echo "GeoAlchemy2 Test Container" | ||
echo "" | ||
echo 'run tests with `tox --workdir /output -vv`' | ||
echo "###############################" | ||
|
||
############################### | ||
# workarounds to get the tests working while mounting the code in as read-only | ||
mkdir /geoalchemy2 | ||
find /geoalchemy2_read_only -mindepth 1 -maxdepth 1 | while read -r item; do | ||
ln -s "${item}" "/geoalchemy2/$(basename "${item}")" | ||
done | ||
|
||
cd /geoalchemy2 | ||
|
||
# remove links that would cause issues if they are present and read-only | ||
rm -f .mypy_cache .eggs *.egg-info .git .gitignore doc reports | ||
|
||
# copy these items instead of symlinking | ||
cp -r /geoalchemy2_read_only/doc /geoalchemy2/doc | ||
cp /geoalchemy2_read_only/.gitignore ./ | ||
|
||
# store reports in the output directory | ||
mkdir -p /output/reports | ||
ln -s /output/reports /geoalchemy2/reports | ||
|
||
# to allow pre-commit to run | ||
git config --global init.defaultBranch master | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "user" | ||
git init > /dev/null | ||
git add --all | ||
git commit -m "dummy commit" > /dev/null | ||
|
||
export MYPY_CACHE_DIR=/output/.mypy_cache | ||
|
||
############################### | ||
|
||
exec bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
if [ $(whoami) != "root" ]; then | ||
echo "must run as the root user" | ||
exit 1 | ||
fi | ||
|
||
/etc/init.d/mysql start | ||
|
||
echo "waiting for mysql to start" | ||
while ! mysqladmin ping -h 127.0.0.1 --silent; do | ||
sleep 0.2 | ||
done | ||
|
||
echo "Create the 'gis' role" | ||
mysql -e "CREATE USER 'gis'@'%' IDENTIFIED BY 'gis';" | ||
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'gis'@'%' WITH GRANT OPTION;" | ||
|
||
echo "Create the 'gis' database" | ||
mysql -u gis --password=gis -e "CREATE DATABASE gis;" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
if [ $(whoami) != "postgres" ]; then | ||
echo "must run as the postgres user" | ||
exit 1 | ||
fi | ||
|
||
${POSTGRES_PATH}/bin/initdb --auth=trust --username=postgres -E 'UTF-8' | ||
|
||
# by default only listens on localhost so host cannot connect | ||
echo "listen_addresses = '0.0.0.0'" >> "${PGDATA}/postgresql.conf" | ||
|
||
(${POSTGRES_PATH}/bin/pg_ctl start > /dev/null 2>&1) & | ||
|
||
while ! ${POSTGRES_PATH}/bin/pg_isready --quiet; do | ||
sleep 0.2 | ||
done | ||
|
||
echo "Create the 'gis' role" | ||
psql -c "CREATE ROLE gis PASSWORD 'gis' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;" | ||
|
||
echo "Create the 'gis' database" | ||
createdb -E UTF-8 gis | ||
psql -d gis -c 'CREATE SCHEMA gis;' | ||
psql -c 'GRANT CREATE ON DATABASE gis TO "gis";' | ||
psql -d gis -c 'GRANT USAGE,CREATE ON SCHEMA gis TO "gis";' | ||
|
||
|
||
echo "Enable PostGIS for the 'gis' database" | ||
psql -d gis -c "CREATE EXTENSION postgis;" | ||
|
||
echo "With PostGIS 3 enable PostGIS Raster as well" | ||
psql -d gis -c "CREATE EXTENSION postgis_raster;" | ||
|
||
|
||
${POSTGRES_PATH}/bin/pg_ctl stop | ||
sleep 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
# based on geoalchemy2/TEST.rst | ||
packages=( | ||
# for managing virtual environments | ||
tox | ||
git | ||
pypy3 | ||
pypy3-dev | ||
pypy3-venv | ||
python3.7 | ||
python3.7-dev | ||
python3.7-venv | ||
python3.8 | ||
python3.8-dev | ||
python3.8-venv | ||
python3.9 | ||
python3.9-dev | ||
python3.9-venv | ||
python3.10 | ||
python3.10-dev | ||
python3.10-venv | ||
python3.11 | ||
python3.11-dev | ||
python3.11-venv | ||
|
||
# PostgreSQL and PostGIS | ||
postgresql | ||
postgresql-14-postgis-3 | ||
postgresql-14-postgis-3-scripts | ||
libpq-dev | ||
libgeos-dev | ||
|
||
# SpatiaLite | ||
libsqlite3-mod-spatialite | ||
|
||
# MySQL | ||
mysql-client | ||
mysql-server | ||
default-libmysqlclient-dev | ||
|
||
# mysqlclient requirements | ||
# https://github.com/PyMySQL/mysqlclient#linux | ||
default-libmysqlclient-dev | ||
build-essential | ||
pkg-config | ||
|
||
# rasterio requirements with pypy | ||
libgdal-dev | ||
) | ||
|
||
export DEBIAN_FRONTEND=noninteractive | ||
|
||
apt-get update -y | ||
apt-get install --no-install-recommends -y software-properties-common gnupg2 | ||
add-apt-repository ppa:deadsnakes/ppa | ||
apt-get update -y | ||
|
||
apt-get install --no-install-recommends -y "${packages[@]}" | ||
|
||
# clear the package list cache (populated with apt-get update) | ||
rm -rf /var/lib/apt/lists/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
|
||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
|
||
ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" | ||
|
||
mkdir -p "${SCRIPT_DIR}/output" | ||
|
||
docker run --rm -it \ | ||
--mount type=bind,source="${ROOT}",target=/geoalchemy2_read_only,ro \ | ||
--mount type=bind,source="${SCRIPT_DIR}/output",target=/output \ | ||
geoalchemy2 |