From 21b356c900b3982f1c95b661dd7c29046253f3ca Mon Sep 17 00:00:00 2001 From: Peter Stace Date: Mon, 18 Dec 2023 06:09:31 +1100 Subject: [PATCH] Use alpine images for GEOS tests The previous approach compiled the GEOS library from source. This was quite annoying when new versions of GEOS came out, because new images had to be created (they take several hours to build on a powerful machine). The new approach is simpler and is based on pre-built alpine images. --- .ci/docker-compose-cmpgeos.yml | 8 ++- .ci/docker-compose-geos.yml | 8 ++- .ci/geos.Dockerfile | 9 ++++ .ci/geos_images/.dockerignore | 1 - .ci/geos_images/.gitignore | 1 - .ci/geos_images/Dockerfile | 28 ---------- .ci/geos_images/README.md | 54 ------------------- Makefile | 22 ++++---- .../rawgeos => geos}/entrypoints_test.go | 17 +----- 9 files changed, 34 insertions(+), 114 deletions(-) create mode 100644 .ci/geos.Dockerfile delete mode 100644 .ci/geos_images/.dockerignore delete mode 100644 .ci/geos_images/.gitignore delete mode 100644 .ci/geos_images/Dockerfile delete mode 100644 .ci/geos_images/README.md rename {internal/rawgeos => geos}/entrypoints_test.go (99%) diff --git a/.ci/docker-compose-cmpgeos.yml b/.ci/docker-compose-cmpgeos.yml index 0cbce97f..de577af0 100644 --- a/.ci/docker-compose-cmpgeos.yml +++ b/.ci/docker-compose-cmpgeos.yml @@ -1,8 +1,12 @@ version: "3.7" services: cmprefimpl: - image: peterstace/simplefeatures-ci:geos-3.11.2-go-1.20.4 + build: + dockerfile: geos.Dockerfile + args: + ALPINE_VERSION: 3.19 + GEOS_VERSION: 3.12.1-r0 working_dir: /mnt/sf - entrypoint: sh -c "go run ./internal/cmprefimpl/cmpgeos" + entrypoint: go run ./internal/cmprefimpl/cmpgeos volumes: - ..:/mnt/sf diff --git a/.ci/docker-compose-geos.yml b/.ci/docker-compose-geos.yml index 31521e3c..6b5c2d5d 100644 --- a/.ci/docker-compose-geos.yml +++ b/.ci/docker-compose-geos.yml @@ -1,8 +1,12 @@ version: "2.1" services: geostests: - image: peterstace/simplefeatures-ci:geos-${GEOS_VERSION}-go-1.20.4 + build: + dockerfile: geos.Dockerfile + args: + ALPINE_VERSION: $alpine_version + GEOS_VERSION: $geos_version working_dir: /mnt/sf - entrypoint: go test -test.count=1 -test.run=. ./geos + entrypoint: go test -test.count=1 -test.run=. ./geos ./internal/rawgeos volumes: - ..:/mnt/sf diff --git a/.ci/geos.Dockerfile b/.ci/geos.Dockerfile new file mode 100644 index 00000000..cb8d2632 --- /dev/null +++ b/.ci/geos.Dockerfile @@ -0,0 +1,9 @@ +ARG ALPINE_VERSION +FROM alpine:${ALPINE_VERSION} + +ARG GEOS_VERSION +RUN apk add gcc musl-dev geos-dev=${GEOS_VERSION} + +COPY --from=golang:1.21-alpine /usr/local/go /usr/local/go +ENV PATH=${PATH}:/usr/local/go/bin +RUN go version diff --git a/.ci/geos_images/.dockerignore b/.ci/geos_images/.dockerignore deleted file mode 100644 index 72e8ffc0..00000000 --- a/.ci/geos_images/.dockerignore +++ /dev/null @@ -1 +0,0 @@ -* diff --git a/.ci/geos_images/.gitignore b/.ci/geos_images/.gitignore deleted file mode 100644 index cfaad761..00000000 --- a/.ci/geos_images/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.pem diff --git a/.ci/geos_images/Dockerfile b/.ci/geos_images/Dockerfile deleted file mode 100644 index 6c24014c..00000000 --- a/.ci/geos_images/Dockerfile +++ /dev/null @@ -1,28 +0,0 @@ -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 diff --git a/.ci/geos_images/README.md b/.ci/geos_images/README.md deleted file mode 100644 index 69b4c809..00000000 --- a/.ci/geos_images/README.md +++ /dev/null @@ -1,54 +0,0 @@ -# GEOS Images - -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 historic versions GEOS can -be used in CI, testing backwards compatibility with old releases. - -## Building and uploading - -Assumes using an `amd64` AWS EC2 instance with Ubuntu Linux. The instance size -should be compute optimised, e.g. `c6a.xlarge`. - -Install `docker`: -```sh -sudo snap install docker -sudo groupadd docker -sudo usermod -aG docker $USER -sudo reboot -docker run hello-world -``` - -Set up buildx: -```sh -docker buildx create --name mybuilder -docker buildx use mybuilder -``` - -Login to dockerhub: -```sh -docker login # interactive -``` - -Use tmux in case the SSH connection goes down (optional): -```sh -tmux -``` - -Specify the versions of GEOS and Go to build the images for: -```sh -GEOS_VERSION=3.11.2 -GO_VERSION=1.20.4 -``` - -Build and push the image: -```sh -docker buildx build \ - --platform linux/amd64,linux/arm64 \ - --file Dockerfile \ - --build-arg GEOS_VERSION=${GEOS_VERSION} \ - --build-arg GO_VERSION=${GO_VERSION} \ - --tag peterstace/simplefeatures-ci:geos-${GEOS_VERSION}-go-${GO_VERSION} \ - --push . -``` diff --git a/Makefile b/Makefile index e0a1211e..4f9bf0de 100644 --- a/Makefile +++ b/Makefile @@ -27,36 +27,36 @@ cmpgeos: task=cmpgeos; $(DC_RUN) DC_GEOS_RUN = \ - env GEOS_VERSION=$$version \ docker compose \ - --project-name sf-geos-$$(echo $$version | sed 's/\./-/g') \ + --project-name sf-geos-$$(echo $$geos_version | sed 's/\./-/g') \ --file .ci/docker-compose-geos.yml \ up \ + --build \ --abort-on-container-exit +.PHONY: geos-3.12 +geos-3.12: + export alpine_version=3.19 geos_version=3.12.1-r0; $(DC_GEOS_RUN) + .PHONY: geos-3.11 geos-3.11: - version=3.11.2; $(DC_GEOS_RUN) + export alpine_version=3.18 geos_version=3.11.2-r0; $(DC_GEOS_RUN) .PHONY: geos-3.10 geos-3.10: - version=3.10.5; $(DC_GEOS_RUN) + export alpine_version=3.16 geos_version=3.10.3-r0; $(DC_GEOS_RUN) .PHONY: geos-3.9 geos-3.9: - version=3.9.4; $(DC_GEOS_RUN) + export alpine_version=3.14 geos_version=3.9.1-r0; $(DC_GEOS_RUN) .PHONY: geos-3.8 geos-3.8: - version=3.8.3; $(DC_GEOS_RUN) - -.PHONY: geos-3.7 -geos-3.7: - version=3.7.5; $(DC_GEOS_RUN) + export alpine_version=3.13 geos_version=3.8.1-r2; $(DC_GEOS_RUN) .PHONY: geos +geos: geos-3.12 geos: geos-3.11 geos: geos-3.10 geos: geos-3.9 geos: geos-3.8 -geos: geos-3.7 diff --git a/internal/rawgeos/entrypoints_test.go b/geos/entrypoints_test.go similarity index 99% rename from internal/rawgeos/entrypoints_test.go rename to geos/entrypoints_test.go index 3057fd51..bda22111 100644 --- a/internal/rawgeos/entrypoints_test.go +++ b/geos/entrypoints_test.go @@ -1,4 +1,4 @@ -package rawgeos_test +package geos_test import ( "math" @@ -29,7 +29,7 @@ func expectNoErr(t *testing.T, err error) { func expectErr(t *testing.T, err error) { t.Helper() if err == nil { - t.Fatal("unexpected error but got nil") + t.Fatal("expected error but got nil") } } @@ -623,11 +623,6 @@ func TestUnion(t *testing.T) { "POINT(3 4)", "MULTIPOINT(1 2,3 4)", }, - { - "POINT EMPTY", - "POINT(3 4)", - "POINT(3 4)", - }, { "POINT EMPTY", "POINT EMPTY", @@ -900,14 +895,6 @@ func TestCoverageUnion(t *testing.T) { )`, wantErr: true, }, - { - // Input constraint violated: not noded correctly. - input: `GEOMETRYCOLLECTION( - POLYGON((0 0,0 1,1 1,1 0,0 0)), - POLYGON((0 1,2 1,2 2,0 2,0 1)) - )`, - wantErr: true, - }, { // Input constraint violation: not everything is a polygon. input: `GEOMETRYCOLLECTION(POINT(1 2),POLYGON((0 0,0 1,1 0,0 0)))`,