Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

geoserver: add extensions and update script #281739

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 60 additions & 5 deletions nixos/tests/geoserver.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
{ pkgs, lib, ... }: {
{ pkgs, lib, ... }:

let
geoserver = pkgs.geoserver;
geoserverWithImporterExtension = pkgs.geoserver.withExtensions (ps: with ps; [ importer ]);

# Blacklisted extensions:
# - wps-jdbc needs a running (Postrgres) db server.
blacklist = [ "wps-jdbc" ];

blacklistedToNull = n: v: if ! builtins.elem n blacklist then v else null;
getNonBlackistedExtensionsAsList = ps: builtins.filter (x: x != null) (lib.attrsets.mapAttrsToList blacklistedToNull ps);
geoserverWithAllExtensions = pkgs.geoserver.withExtensions (ps: getNonBlackistedExtensionsAsList ps);
in
{

name = "geoserver";
meta = {
Expand All @@ -9,16 +23,57 @@
machine = { pkgs, ... }: {
virtualisation.diskSize = 2 * 1024;

environment.systemPackages = [ pkgs.geoserver ];
environment.systemPackages = [
geoserver
geoserverWithImporterExtension
geoserverWithAllExtensions
];
};
};

testScript = ''
from contextlib import contextmanager

curl_cmd = "curl --fail --connect-timeout 2"
curl_cmd_rest = f"{curl_cmd} -u admin:geoserver -X GET"
base_url = "http://localhost:8080/geoserver"
log_file = "./log.txt"

@contextmanager
def running_geoserver(pkg):
try:
print(f"Launching geoserver from {pkg}...")
machine.execute(f"{pkg}/bin/geoserver-startup > {log_file} 2>&1 &")
machine.wait_until_succeeds(f"{curl_cmd} {base_url} 2>&1", timeout=60)
yield
finally:
# We need to wait a little bit to make sure the server is properly
# shutdown before launching a new instance.
machine.execute(f"{pkg}/bin/geoserver-shutdown; sleep 1")

start_all()

machine.execute("${pkgs.geoserver}/bin/geoserver-startup > /dev/null 2>&1 &")
machine.wait_until_succeeds("curl --fail --connect-timeout 2 http://localhost:8080/geoserver", timeout=60)
with running_geoserver("${geoserver}"):
machine.succeed(f"{curl_cmd} {base_url}/ows?service=WMS&version=1.3.0&request=GetCapabilities")

# No extensions yet.
machine.fail(f"{curl_cmd_rest} {base_url}/rest/imports")
machine.fail(f"{curl_cmd_rest} {base_url}/rest/monitor/requests.csv")


with running_geoserver("${geoserverWithImporterExtension}"):
machine.succeed(f"{curl_cmd_rest} {base_url}/rest/imports")
machine.fail(f"{curl_cmd_rest} {base_url}/rest/monitor/requests.csv")

with running_geoserver("${geoserverWithAllExtensions}"):
machine.succeed(f"{curl_cmd_rest} {base_url}/rest/imports")
machine.succeed(f"{curl_cmd_rest} {base_url}/rest/monitor/requests.csv")
_, stdout = machine.execute(f"cat {log_file}")
print(stdout.replace("\\n", "\n"))
assert "GDAL Native Library loaded" in stdout, "gdal"
assert "The turbo jpeg encoder is available for usage" in stdout, "libjpeg-turbo"
assert "org.geotools.imageio.netcdf.utilities.NetCDFUtilities" in stdout, "netcdf"
assert "Unable to load library 'netcdf'" not in stdout, "netcdf"

machine.succeed("curl --fail --connect-timeout 2 http://localhost:8080/geoserver/ows?service=WMS&version=1.3.0&request=GetCapabilities")
'';
}
74 changes: 52 additions & 22 deletions pkgs/servers/geospatial/geoserver/default.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{ lib
, callPackage
, fetchurl
, makeWrapper
, nixosTests
, stdenv

, jre
, unzip
}:

stdenv.mkDerivation rec {
stdenv.mkDerivation (finalAttrs: rec {
pname = "geoserver";
version = "2.24.2";

Expand All @@ -25,24 +24,55 @@ stdenv.mkDerivation rec {
sourceRoot = ".";
nativeBuildInputs = [ unzip makeWrapper ];

installPhase = ''
runHook preInstall
mkdir -p $out/share/geoserver
cp -r . $out/share/geoserver
rm -fr $out/share/geoserver/bin/*.bat

makeWrapper $out/share/geoserver/bin/startup.sh $out/bin/geoserver-startup \
--set JAVA_HOME "${jre}" \
--set GEOSERVER_HOME "$out/share/geoserver"
makeWrapper $out/share/geoserver/bin/shutdown.sh $out/bin/geoserver-shutdown \
--set JAVA_HOME "${jre}" \
--set GEOSERVER_HOME "$out/share/geoserver"
runHook postInstall
'';

passthru = {
tests.geoserver = nixosTests.geoserver;
};
installPhase =
let
inputs = finalAttrs.buildInputs or [ ];
ldLibraryPathEnvName = if stdenv.isDarwin then "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH";
in
''
runHook preInstall
mkdir -p $out/share/geoserver
cp -r . $out/share/geoserver
rm -fr $out/share/geoserver/bin/*.bat

makeWrapper $out/share/geoserver/bin/startup.sh $out/bin/geoserver-startup \
--prefix PATH : "${lib.makeBinPath inputs}" \
--prefix ${ldLibraryPathEnvName} : "${lib.makeLibraryPath inputs}" \
--set JAVA_HOME "${jre}" \
--set GEOSERVER_HOME "$out/share/geoserver"
makeWrapper $out/share/geoserver/bin/shutdown.sh $out/bin/geoserver-shutdown \
--prefix PATH : "${lib.makeBinPath inputs}" \
--prefix ${ldLibraryPathEnvName} : "${lib.makeLibraryPath inputs}" \
--set JAVA_HOME "${jre}" \
--set GEOSERVER_HOME "$out/share/geoserver"
runHook postInstall
'';


passthru =
let
geoserver = finalAttrs.finalPackage;
extensions = lib.attrsets.filterAttrs (n: v: lib.isDerivation v) (callPackage ./extensions.nix { });
in
{
withExtensions = selector:
let
selectedExtensions = selector extensions;
in
geoserver.overrideAttrs (finalAttrs: previousAttrs: {
pname = previousAttrs.pname + "-with-extensions";
buildInputs = lib.lists.unique ((previousAttrs.buildInputs or [ ]) ++ lib.lists.concatMap (drv: drv.buildInputs) selectedExtensions);
postInstall = (previousAttrs.postInstall or "") + ''
for extension in ${builtins.toString selectedExtensions} ; do
cp -r $extension/* $out
# Some files are the same for all/several extensions. We allow overwriting them again.
chmod -R +w $out
done
'';
});
tests.geoserver = nixosTests.geoserver;
passthru.updateScript = ./update.sh;
};

meta = with lib; {
description = "Open source server for sharing geospatial data";
Expand All @@ -52,4 +82,4 @@ stdenv.mkDerivation rec {
maintainers = teams.geospatial.members;
platforms = platforms.all;
};
}
})