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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pgadmin4: init at 6.3 #154764

Merged
merged 2 commits into from
Feb 26, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ in
pdns-recursor = handleTest ./pdns-recursor.nix {};
peerflix = handleTest ./peerflix.nix {};
peertube = handleTestOn ["x86_64-linux"] ./web-apps/peertube.nix {};
pgadmin4 = handleTest ./pgadmin4.nix {};
pgjwt = handleTest ./pgjwt.nix {};
pgmanage = handleTest ./pgmanage.nix {};
php = handleTest ./php {};
Expand Down
142 changes: 142 additions & 0 deletions nixos/tests/pgadmin4.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import ./make-test-python.nix ({ pkgs, lib, ... }:

let
pgadmin4SrcDir = "/pgadmin";
pgadmin4Dir = "/var/lib/pgadmin";
pgadmin4LogDir = "/var/log/pgadmin";

python-with-needed-packages = pkgs.python3.withPackages (ps: with ps; [
selenium
testtools
testscenarios
flask
flask-babelex
flask-babel
flask-gravatar
flask_login
flask_mail
flask_migrate
flask_sqlalchemy
flask_wtf
flask-compress
passlib
pytz
simplejson
six
sqlparse
wtforms
flask-paranoid
psutil
psycopg2
python-dateutil
sqlalchemy
itsdangerous
flask-security-too
bcrypt
cryptography
sshtunnel
ldap3
gssapi
flask-socketio
eventlet
httpagentparser
user-agents
wheel
authlib
qrcode
pillow
pyotp
]);
in
{
name = "pgadmin4";
meta.maintainers = with lib.maintainers; [ gador ];

nodes.machine = { pkgs, ... }: {
imports = [ ./common/x11.nix ];
environment.systemPackages = with pkgs; [
pgadmin4
postgresql
python-with-needed-packages
chromedriver
chromium
];
services.postgresql = {
enable = true;
authentication = ''
host all all localhost trust
'';
ensureUsers = [
{
name = "postgres";
ensurePermissions = {
"DATABASE \"postgres\"" = "ALL PRIVILEGES";
};
}
];
};
};

testScript = ''
machine.wait_for_unit("postgresql")

# pgadmin4 needs its data and log directories
machine.succeed(
"mkdir -p ${pgadmin4Dir} \
&& mkdir -p ${pgadmin4LogDir} \
&& mkdir -p ${pgadmin4SrcDir}"
)

machine.succeed(
"tar xvzf ${pkgs.pgadmin4.src} -C ${pgadmin4SrcDir}"
)

machine.wait_for_file("${pgadmin4SrcDir}/pgadmin4-${pkgs.pgadmin4.version}/README.md")

# set paths and config for tests
machine.succeed(
"cd ${pgadmin4SrcDir}/pgadmin4-${pkgs.pgadmin4.version} \
&& cp -v web/regression/test_config.json.in web/regression/test_config.json \
&& sed -i 's|PostgreSQL 9.4|PostgreSQL|' web/regression/test_config.json \
&& sed -i 's|/opt/PostgreSQL/9.4/bin/|${pkgs.postgresql}/bin|' web/regression/test_config.json \
&& sed -i 's|\"headless_chrome\": false|\"headless_chrome\": true|' web/regression/test_config.json"
)

# adapt chrome config to run within a sandbox without GUI
# see https://stackoverflow.com/questions/50642308/webdriverexception-unknown-error-devtoolsactiveport-file-doesnt-exist-while-t#50642913
# add chrome binary path. use spaces to satisfy python indention (tabs throw an error)
# this works for selenium 3 (currently used), but will need to be updated
# to work with "from selenium.webdriver.chrome.service import Service" in selenium 4
machine.succeed(
"cd ${pgadmin4SrcDir}/pgadmin4-${pkgs.pgadmin4.version} \
&& sed -i '\|options.add_argument(\"--disable-infobars\")|a \ \ \ \ \ \ \ \ options.binary_location = \"${pkgs.chromium}/bin/chromium\"' web/regression/runtests.py \
&& sed -i '\|options.add_argument(\"--no-sandbox\")|a \ \ \ \ \ \ \ \ options.add_argument(\"--headless\")' web/regression/runtests.py \
&& sed -i '\|options.add_argument(\"--disable-infobars\")|a \ \ \ \ \ \ \ \ options.add_argument(\"--disable-dev-shm-usage\")' web/regression/runtests.py \
&& sed -i 's|(chrome_options=options)|(executable_path=\"${pkgs.chromedriver}/bin/chromedriver\", chrome_options=options)|' web/regression/runtests.py \
&& sed -i 's|driver_local.maximize_window()||' web/regression/runtests.py"
)

# don't bother to test LDAP authentification
with subtest("run browser test"):
machine.succeed(
'cd ${pgadmin4SrcDir}/pgadmin4-${pkgs.pgadmin4.version}/web \
&& ${python-with-needed-packages.interpreter} regression/runtests.py --pkg browser --exclude \
browser.tests.test_ldap_login.LDAPLoginTestCase,browser.tests.test_ldap_login'
)

# fontconfig is necessary for chromium to run
# https://github.com/NixOS/nixpkgs/issues/136207
with subtest("run feature test"):
machine.succeed(
'cd ${pgadmin4SrcDir}/pgadmin4-${pkgs.pgadmin4.version}/web \
&& export FONTCONFIG_FILE=${pkgs.makeFontsConf { fontDirectories = [];}} \
&& ${python-with-needed-packages.interpreter} regression/runtests.py --pkg feature_tests'
)

with subtest("run resql test"):
machine.succeed(
'cd ${pgadmin4SrcDir}/pgadmin4-${pkgs.pgadmin4.version}/web \
&& ${python-with-needed-packages.interpreter} regression/runtests.py --pkg resql'
)
'';
})
158 changes: 158 additions & 0 deletions pkgs/tools/admin/pgadmin/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{ stdenv
, lib
, python3
, fetchurl
, zlib
, mkYarnModules
, sphinx
, nixosTests
}:

let

pname = "pgadmin";
version = "6.3";

src = fetchurl {
url = "https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v${version}/source/pgadmin4-${version}.tar.gz";
sha256 = "0xcg5gx6hf4k15idjkxzsnm5s9829fn4li54ga9qbyfqn3wwpg0h";
};

yarnDeps = mkYarnModules {
pname = "${pname}-yarn-deps";
inherit version;
packageJSON = ./package.json;
yarnLock = ./yarn.lock;
yarnNix = ./yarn.nix;
};
in

python3.pkgs.buildPythonApplication rec {
inherit pname version src;

# from Dockerfile
CPPFLAGS = "-DPNG_ARM_NEON_OPT=0";

format = "setuptools";

postPatch = ''
# patching Makefile, so it doesn't try to build sphinx documentation here
# (will do so later)
substituteInPlace Makefile --replace "LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 $(MAKE) -C docs/en_US -f Makefile.sphinx html" "true"
# fix document which refers a non-existing document and fails
substituteInPlace docs/en_US/contributions.rst --replace "code_snippets" ""
patchShebangs .
gador marked this conversation as resolved.
Show resolved Hide resolved
# relax dependencies
substituteInPlace requirements.txt \
--replace "Pillow==8.3.*" "Pillow>=8.3.0" \
--replace "psycopg2==2.8.*" "psycopg2>=2.8.0" \
--replace "cryptography==3.*" "cryptography>=3.0" \
--replace "requests==2.25.*" "requests>=2.25.0"
# don't use Server Mode (can be overridden later)
substituteInPlace pkg/pip/setup_pip.py \
--replace "req = req.replace('psycopg2', 'psycopg2-binary')" "req = req" \
--replace "builtins.SERVER_MODE = None" "builtins.SERVER_MODE = False"
'';

preBuild = ''
# Adapted from pkg/pip/build.sh
echo Creating required directories...
mkdir -p pip-build/pgadmin4/docs

# build the documentation
cd docs/en_US
${sphinx}/bin/sphinx-build -W -b html -d _build/doctrees . _build/html

# Build the clean tree
cd ../../web
cp -r * ../pip-build/pgadmin4
cd ../docs
cp -r * ../pip-build/pgadmin4/docs
for DIR in `ls -d ??_??/`
do
if [ -d ''${DIR}_build/html ]; then
mkdir -p ../pip-build/pgadmin4/docs/''${DIR}_build
cp -Rv ''${DIR}_build/html ../pip-build/pgadmin4/docs/''${DIR}_build
fi
done
cd ../

cp -r ${yarnDeps}/* pip-build/pgadmin4

echo Creating distro config...
echo HELP_PATH = \'../../docs/en_US/_build/html/\' > pip-build/pgadmin4/config_distro.py
echo MINIFY_HTML = False >> pip-build/pgadmin4/config_distro.py

echo Creating manifest...
echo recursive-include pgadmin4 \* > pip-build/MANIFEST.in

echo Building wheel...
cd pip-build
# copy non-standard setup.py to local directory
# so setuptools-build-hook can call it
cp -v ../pkg/pip/setup_pip.py setup.py
'';

nativeBuildInputs = [ python3 python3.pkgs.cython python3.pkgs.pip ];
buildInputs = [
zlib
python3.pkgs.wheel
];

# tests need an own data, log directory
# and a working and correctly setup postgres database
# checks will be run through nixos/tests
doCheck = false;

propagatedBuildInputs = with python3.pkgs; [
flask
flask-gravatar
flask_login
flask_mail
flask_migrate
flask_sqlalchemy
flask_wtf
flask-compress
passlib
pytz
simplejson
six
speaklater3
sqlparse
wtforms
flask-paranoid
psutil
psycopg2
python-dateutil
sqlalchemy
itsdangerous
flask-security-too
bcrypt
cryptography
sshtunnel
ldap3
flask-babelex
flask-babel
gssapi
flask-socketio
eventlet
httpagentparser
user-agents
wheel
authlib
qrcode
pillow
pyotp
];

passthru = {
tests = { inherit (nixosTests) pgadmin4; };
};

meta = with lib; {
description = "Administration and development platform for PostgreSQL";
homepage = "https://www.pgadmin.org/";
license = licenses.mit;
maintainers = with maintainers; [ gador ];
};
}
Loading