Skip to content

Commit

Permalink
docker: implement multi-stage-builds for ubuntu (OSGeo#3170)
Browse files Browse the repository at this point in the history
* test grass.script.setup

* test script for docker images

* black

* add test instructions

* multi-stage-build similar to alpine

* Apply suggestions from code review

Co-authored-by: Carmen Tawalika <mmacata@users.noreply.github.com>

* add test for GDAL-plugin

* copy GDAL-plugin and set path

* Update docker/ubuntu/Dockerfile

Co-authored-by: Edouard Choinière <27212526+echoix@users.noreply.github.com>

* ignore dist.* in docker builds

* address review comments

* separate datum grid (proj >= 7) stage

* use network grids

* GUI build argument

* GUI build argument

---------

Co-authored-by: ninsbl <stbl@nve.no>
Co-authored-by: Carmen Tawalika <mmacata@users.noreply.github.com>
Co-authored-by: Edouard Choinière <27212526+echoix@users.noreply.github.com>
  • Loading branch information
4 people authored and neteler committed Nov 7, 2023
1 parent 3149f09 commit 698dad0
Show file tree
Hide file tree
Showing 5 changed files with 378 additions and 157 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ docker
.github
.travis
.travis.yml
# Do not copy files from previous compilations
dist.*

# The following git files are needed by GRASS GIS to extract the revision
# during compilation. If you are not using one of the Dockerimages from this
Expand Down
66 changes: 66 additions & 0 deletions docker/testdata/test_docker_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/sh

set -e

# to be used in Dockerfile

# Display environment
printf "\n############\nPrinting defined environment variables:\n############\n"
printenv

# run simple LAZ test
cp docker/testdata/simple.laz /tmp/
cp docker/testdata/test_grass_session.py /tmp/
cp docker/testdata/test_grass_python.py /tmp/
cp -r demolocation /tmp/

# Test gdal-grass-plugin
printf "\n############\nTesting the gdal_grass plugin:\n############\n"
gdalinfo --formats | grep "GRASS -raster-"

# Test grass-session
printf "\n############\nTesting grass_session:\n############\n"
/usr/bin/python3 /tmp/test_grass_session.py

# Test grass-setup
printf "\n############\nTesting grass script setup:\n############\n"
export DEMOLOCATION=/tmp/demolocation/PERMANENT
/usr/bin/python3 /tmp/test_grass_python.py

# Test PDAL
printf "\n############\nTesting PDAL with laz:\n############\n"
grass --tmp-location EPSG:25832 --exec r.in.pdal input="/tmp/simple.laz" output="count_1" method="n" resolution=1 -g

# Test GRASS GIS Python-addon installation
# add dependency
printf "\n############\nTesting GRASS GIS Python-addon installation:\n############\n"
/usr/bin/python3 -m pip install --no-cache-dir scikit-learn

grass --tmp-location XY --exec g.extension extension=r.learn.ml2 operation=add && \
grass --tmp-location XY --exec g.extension extension=r.learn.ml2 operation=remove -f

# cleanup dependency
/usr/bin/python3 -m pip uninstall -y scikit-learn

# Test GRASS GIS C-addon installation: raster and vector
printf "\n############\nTesting GRASS GIS C-addon installation:\n############\n"
grass --tmp-location XY --exec g.extension extension=r.gwr operation=add && \
grass --tmp-location XY --exec g.extension extension=r.gwr operation=remove -f
grass --tmp-location XY --exec g.extension extension=v.centerpoint operation=add && \
grass --tmp-location XY --exec g.extension extension=v.centerpoint operation=remove -f

# show GRASS GIS, PROJ, GDAL etc versions
printf "\n############\nPrinting GRASS, PDAL and Python versions:\n############\n"
grass --tmp-location EPSG:4326 --exec g.version -rge && \
pdal --version && \
python3 --version

# Test presence of central python packages
printf "\n############\nPrinting versions of central python packages:\n############\n"
python3 -c "import psycopg2;import numpy as np;print(psycopg2.__version__);print(np.__version__)"

# Run testsuite
if [ $TESTSUITE ] ; then
printf "\n############\nRunning the testsuite:\n############\n"
bash /grassdb/.github/workflows/test_thorough.sh
fi
22 changes: 22 additions & 0 deletions docker/testdata/test_grass_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Import GRASS Python bindings
import os
import grass.script as gs

# hint: do not use ~ as an alias for HOME
with gs.setup.init(
# run in PERMANENT mapset of demolocation in GRASS GIS source
os.environ["DEMOLOCATION"] # "/grassdata/demolocation/PERMANENT",
):
print("grass-setup: tests for PROJ, GDAL, PDAL, GRASS GIS")
print(gs.parse_command("g.gisenv", flags="s"))

# simple test: just scan the LAZ file
gs.run_command(
"r.in.pdal",
input="/tmp/simple.laz",
output="count_1",
method="n",
flags="g",
resolution=1,
overwrite=True,
)
Loading

0 comments on commit 698dad0

Please sign in to comment.