Skip to content

Commit

Permalink
Use single Dockerfile for GEOS images
Browse files Browse the repository at this point in the history
  • Loading branch information
peterstace committed May 20, 2023
1 parent cc8e0c3 commit 6d7a785
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 94 deletions.
12 changes: 4 additions & 8 deletions .ci/docker-compose-cmpgeos.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
version: "3.7"
services:
cmprefimpl:
build:
context: .
dockerfile: geos.Dockerfile
working_dir: /go/src/github.com/peterstace/simplefeatures
entrypoint: sh -c "go install ./internal/cmprefimpl/cmpgeos && cmpgeos"
image: peterstace/simplefeatures-ci:geos-3.11.2-go-1.20.4
working_dir: /mnt/sf
entrypoint: sh -c "go run ./internal/cmprefimpl/cmpgeos"
volumes:
- ..:/go/src/github.com/peterstace/simplefeatures
environment:
- GO111MODULE=on
- ..:/mnt/sf
10 changes: 3 additions & 7 deletions .ci/docker-compose-geos.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
version: "2.1"
services:
geostests:
build:
context: .
dockerfile: geos.Dockerfile
working_dir: /go/src/github.com/peterstace/simplefeatures
image: peterstace/simplefeatures-ci:geos-${GEOS_VERSION}-go-1.20.4
working_dir: /mnt/sf
entrypoint: go test -test.count=1 -test.run=. ./geos
volumes:
- ..:/go/src/github.com/peterstace/simplefeatures
environment:
- GO111MODULE=on
- ..:/mnt/sf
6 changes: 0 additions & 6 deletions .ci/geos.Dockerfile

This file was deleted.

1 change: 1 addition & 0 deletions .ci/geos_images/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
28 changes: 28 additions & 0 deletions .ci/geos_images/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM debian:bullseye

RUN apt-get update \
&& apt-get install -y cmake build-essential wget \
&& rm -rf /var/lib/apt/lists/*

ARG GEOS_VERSION
RUN cd /tmp \
&& wget https://download.osgeo.org/geos/geos-$GEOS_VERSION.tar.bz2 \
&& tar -xf geos-$GEOS_VERSION.tar.bz2 \
&& rm geos-$GEOS_VERSION.tar.bz2 \
&& cd geos-$GEOS_VERSION \
&& cmake . -DCMAKE_INSTALL_PREFIX=/usr/local \
&& make -j$(nproc) \
&& make install \
&& ldconfig \
&& cd .. \
&& rm -r geos-$GEOS_VERSION

ARG GO_VERSION
ARG TARGETARCH
RUN cd /tmp \
&& wget https://go.dev/dl/go$GO_VERSION.linux-$TARGETARCH.tar.gz \
&& tar -C /usr/local -xzf go$GO_VERSION.linux-$TARGETARCH.tar.gz \
&& rm go$GO_VERSION.linux-$TARGETARCH.tar.gz
ENV PATH=$PATH:/usr/local/go/bin

CMD geos-config --version && go version
23 changes: 9 additions & 14 deletions .ci/geos_images/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
This directory contains a Dockerfile and instructions for how to create GEOS
images. These images are used for CI.

The images install GEOS from source. This is so that each version of GEOS can
be used in CI.
The images install GEOS from source. This is so that historic versions GEOS can
be used in CI, testing backwards compatibility with old releases.

## Building and uploading

Expand All @@ -31,27 +31,22 @@ Login to dockerhub:
docker login # interactive
```

Specify the versions of GEOS and Go to build the images for:
Use tmux in case the SSH connection goes down (optional):
```sh
GEOS_VERSION=3.10.5
GO_VERSION=1.20.4
tmux
```

Build and push the GEOS images:
Specify the versions of GEOS and Go to build the images for:
```sh
docker buildx build \
--platform linux/amd64,linux/arm64 \
--file geos.Dockerfile \
--build-arg GEOS_VERSION=${GEOS_VERSION} \
--tag peterstace/simplefeatures-ci:geos-${GEOS_VERSION} \
--push .
GEOS_VERSION=3.11.2
GO_VERSION=1.20.4
```

Build and push the Go images:
Build and push the image:
```sh
docker buildx build \
--platform linux/amd64,linux/arm64 \
--file go.Dockerfile \
--file Dockerfile \
--build-arg GEOS_VERSION=${GEOS_VERSION} \
--build-arg GO_VERSION=${GO_VERSION} \
--tag peterstace/simplefeatures-ci:geos-${GEOS_VERSION}-go-${GO_VERSION} \
Expand Down
20 changes: 0 additions & 20 deletions .ci/geos_images/geos.Dockerfile

This file was deleted.

16 changes: 0 additions & 16 deletions .ci/geos_images/go.Dockerfile

This file was deleted.

17 changes: 11 additions & 6 deletions .ci/run_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ set -eo pipefail

start="$(date +%s.%N)"
here="$(dirname "$(readlink -f "$0")")"
cd "$here"

docker-compose -p sf-lint -f "$here/docker-compose-lint.yml" up --abort-on-container-exit
docker-compose -p sf-unit -f "$here/docker-compose-unit.yml" up --abort-on-container-exit
docker-compose -p sf-geos -f "$here/docker-compose-geos.yml" up --abort-on-container-exit
docker-compose -p sf-pgscan -f "$here/docker-compose-pgscan.yml" up --abort-on-container-exit
docker-compose -p sf-cmppg -f "$here/docker-compose-cmppg.yml" up --abort-on-container-exit
docker-compose -p sf-cmpgeos -f "$here/docker-compose-cmpgeos.yml" up --abort-on-container-exit
docker-compose -p sf-lint -f docker-compose-lint.yml up --abort-on-container-exit
docker-compose -p sf-unit -f docker-compose-unit.yml up --abort-on-container-exit

for v in 3.11.2 3.10.5 3.9.4 3.8.3 3.7.5; do
env GEOS_VERSION=$v docker-compose -p sf-geos-$(echo $v | tr . -) -f docker-compose-geos.yml up --abort-on-container-exit
done

docker-compose -p sf-pgscan -f docker-compose-pgscan.yml up --abort-on-container-exit
docker-compose -p sf-cmppg -f docker-compose-cmppg.yml up --abort-on-container-exit
docker-compose -p sf-cmpgeos -f docker-compose-cmpgeos.yml up --abort-on-container-exit

printf "\nduration: %.1f seconds\n" "$(echo "$(date +%s.%N) - $start" | bc)"
48 changes: 31 additions & 17 deletions geos/entrypoints_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package geos

import (
"math"
"strconv"
"testing"

Expand Down Expand Up @@ -592,6 +593,14 @@ func RunBinaryOperationTest(t *testing.T, fn func(a, b geom.Geometry, opts ...ge
t.Logf("WKT2: %v", g2.AsText())
got, err := fn(g1, g2)
expectNoErr(t, err)

if got.IsEmpty() {
// Normalise the result to a geometry collection when
// it's empty. This is needed because different
// versions of GEOS will give different geometry types
// for empty geometries.
got = geom.GeometryCollection{}.AsGeometry()
}
expectGeomEq(t, got, geomFromWKT(t, c.Out), geom.IgnoreOrder)
}
}
Expand All @@ -616,17 +625,17 @@ func TestUnion(t *testing.T) {
{
"POINT EMPTY",
"POINT EMPTY",
"POINT EMPTY",
"GEOMETRYCOLLECTION EMPTY",
},
{
"MULTIPOINT(EMPTY)",
"MULTIPOINT(EMPTY)",
"POINT EMPTY",
"GEOMETRYCOLLECTION EMPTY",
},
{
"GEOMETRYCOLLECTION(POINT EMPTY)",
"GEOMETRYCOLLECTION(POINT EMPTY)",
"POINT EMPTY",
"GEOMETRYCOLLECTION EMPTY",
},
{
"POLYGON((0 0,0 2,2 2,2 0,0 0))",
Expand All @@ -648,8 +657,8 @@ func TestUnion(t *testing.T) {

func TestIntersection(t *testing.T) {
RunBinaryOperationTest(t, Intersection, []BinaryOperationTestCase{
{"POINT EMPTY", "POINT EMPTY", "POINT EMPTY"},
{"POINT(1 2)", "POINT EMPTY", "POINT EMPTY"},
{"POINT EMPTY", "POINT EMPTY", "GEOMETRYCOLLECTION EMPTY"},
{"POINT(1 2)", "POINT EMPTY", "GEOMETRYCOLLECTION EMPTY"},
{"POINT(1 2)", "POINT(1 2)", "POINT(1 2)"},
{
"POLYGON((0 0,3 0,3 3,2 3,2 1,0 1,0 0))",
Expand Down Expand Up @@ -717,9 +726,9 @@ func TestBuffer(t *testing.T) {
"POLYGON((0.9 0.1,0.9 1,0.901921471959677 1.019509032201613,0.9076120467488714 1.0382683432365092,0.9168530387697456 1.0555570233019602,0.9292893218813453 1.0707106781186548,0.9444429766980398 1.0831469612302547,0.961731656763491 1.0923879532511287,0.9804909677983872 1.0980785280403231,1 1.1,1.0195090322016127 1.0980785280403231,1.038268343236509 1.0923879532511287,1.0555570233019602 1.0831469612302547,1.0707106781186546 1.0707106781186548,1.0831469612302544 1.0555570233019602,1.0923879532511287 1.0382683432365092,1.0980785280403231 1.019509032201613,1.1 1,1.1 0,1.0980785280403231 -0.019509032201612826,1.0923879532511287 -0.03826834323650898,1.0831469612302544 -0.05555702330196022,1.0707106781186548 -0.07071067811865475,1.0555570233019602 -0.08314696123025453,1.038268343236509 -0.09238795325112868,1.019509032201613 -0.09807852804032305,1 -0.1,0 -0.1,-0.019509032201612955 -0.09807852804032302,-0.03826834323650912 -0.09238795325112863,-0.055557023301960363 -0.08314696123025443,-0.07071067811865482 -0.07071067811865468,-0.08314696123025457 -0.055557023301960155,-0.0923879532511287 -0.03826834323650893,-0.09807852804032306 -0.01950903220161279,-0.1 0.000000000000000012246467991473533,-0.09807852804032305 0.01950903220161282,-0.0923879532511287 0.03826834323650895,-0.08314696123025456 0.055557023301960176,-0.07071067811865482 0.0707106781186547,-0.05555702330196031 0.08314696123025447,-0.0382683432365091 0.09238795325112864,-0.019509032201612972 0.09807852804032302,0 0.1,0.9 0.1))",
},
{
"LINESTRING(0 0,1 0,1 1)", 0.1,
[]BufferOption{BufferJoinStyleMitre(0.05)},
"POLYGON((0.9 0.1,0.9 1,0.901921471959677 1.019509032201613,0.9076120467488713 1.038268343236509,0.9168530387697454 1.0555570233019602,0.9292893218813453 1.0707106781186548,0.9444429766980398 1.0831469612302547,0.961731656763491 1.0923879532511287,0.9804909677983872 1.0980785280403231,1 1.1,1.019509032201613 1.0980785280403231,1.038268343236509 1.0923879532511287,1.0555570233019602 1.0831469612302544,1.0707106781186548 1.0707106781186548,1.0831469612302544 1.0555570233019602,1.0923879532511287 1.038268343236509,1.0980785280403231 1.019509032201613,1.1 1,1.1 0,1 -0.1,0 -0.1,-0.019509032201612868 -0.09807852804032303,-0.03826834323650904 -0.09238795325112865,-0.05555702330196022 -0.08314696123025453,-0.07071067811865477 -0.07071067811865475,-0.08314696123025456 -0.0555570233019602,-0.0923879532511287 -0.03826834323650897,-0.09807852804032305 -0.019509032201612837,-0.1 0.000000000000000012246467991473533,-0.09807852804032305 0.01950903220161286,-0.09238795325112868 0.03826834323650899,-0.08314696123025454 0.05555702330196022,-0.07071067811865475 0.07071067811865477,-0.0555570233019602 0.08314696123025456,-0.038268343236508975 0.09238795325112868,-0.019509032201612844 0.09807852804032305,0 0.1,0.9 0.1))",
"LINESTRING(0 0,5 0,0 1)", 0.1,
[]BufferOption{BufferJoinStyleMitre(3.5)},
"POLYGON((3.9900980486407214 0.1,-0.019611613513818404 0.9019419324309079,-0.038364961837643596 0.9076521266991159,-0.05564396619336664 0.9169111979489927,-0.07078460413377427 0.9293633252649527,-0.08320502943378437 0.944529980377477,-0.0924279321145722 0.9618283172361496,-0.09809888119837851 0.9805935704565105,-0.09999994529221752 1.0001046018809767,-0.09805806756909202 1.0196116135138185,-0.09234787330088415 1.0383649618376436,-0.08308880205100731 1.0556439661933665,-0.0706366747350473 1.0707846041337743,-0.05547001962252293 1.0832050294337843,-0.03817168276385041 1.0924279321145722,-0.01940642954348947 1.0980988811983785,0.00010460188097669381 1.0999999452922176,0.019611613513818404 1.098058067569092,5.3547836142425265 0.03102366742335057,5.341809714425123 -0.1,0 -0.1,-0.019509032201612868 -0.09807852804032303,-0.03826834323650904 -0.09238795325112865,-0.05555702330196022 -0.08314696123025453,-0.07071067811865477 -0.07071067811865475,-0.08314696123025456 -0.0555570233019602,-0.0923879532511287 -0.03826834323650897,-0.09807852804032305 -0.019509032201612837,-0.1 0.000000000000000012246467991473533,-0.09807852804032305 0.01950903220161286,-0.09238795325112868 0.03826834323650899,-0.08314696123025454 0.05555702330196022,-0.07071067811865475 0.07071067811865477,-0.0555570233019602 0.08314696123025456,-0.038268343236508975 0.09238795325112868,-0.019509032201612844 0.09807852804032305,0 0.1,3.9900980486407214 0.1))",
},
{
"LINESTRING(0 0,1 0,1 1)", 0.1,
Expand All @@ -730,16 +739,21 @@ func TestBuffer(t *testing.T) {
t.Run(strconv.Itoa(i), func(t *testing.T) {
g := geomFromWKT(t, tt.wkt)
t.Logf("WKT: %v", g.AsText())

got, err := Buffer(g, tt.radius, tt.opts...)
expectNoErr(t, err)
expectGeomEq(t, got, geomFromWKT(t, tt.want),
// Different versions of GEOS can output geometry parts in
// different orders, but there is no semantic difference.
geom.IgnoreOrder,
// Account for some slight differences in GEOS behaviour
// between `x86_64` and `aarch64`:
geom.ToleranceXY(1e-15),
)

gWant := geomFromWKT(t, tt.want)
symDiff, err := geom.SymmetricDifference(gWant, got)
expectNoErr(t, err)
const threshold = 1e-3
relativeAreaDiff := symDiff.Area() / math.Min(gWant.Area(), got.Area())
if relativeAreaDiff > threshold {
t.Errorf(
"expected relativeAreaDiff <= %f but was %f",
threshold, relativeAreaDiff,
)
}
})
}
}
Expand Down Expand Up @@ -811,7 +825,7 @@ func TestMakeValid(t *testing.T) {
}
expectNoErr(t, err)
wantGeom := geomFromWKT(t, tt.wantOutput)
expectGeomEq(t, gotGeom, wantGeom)
expectGeomEq(t, gotGeom, wantGeom, geom.IgnoreOrder)
})
}
}

0 comments on commit 6d7a785

Please sign in to comment.