From d1237c315d3ff4c79427df1e603ec0057862aeeb Mon Sep 17 00:00:00 2001 From: Andreas Rammhold Date: Wed, 13 May 2020 17:37:25 +0200 Subject: [PATCH] Add runHydra shell runHyda automatically starts hydra and postgres: ``` $ nix-shell -A runHydra ``` The shell receives hydra from the working copy as buildInput. Running hydra, queue-runner, evaluator and postgres is managed by foreman (https://github.com/ddollar/foreman) and configured in `Procfile`. --- .gitignore | 1 + Procfile | 4 ++++ flake.nix | 7 ++++++- run-hydra.nix | 16 ++++++++++++++++ scripts/start-evaluator.sh | 6 ++++++ scripts/start-hydra.sh | 11 +++++++++++ scripts/start-postgres.sh | 4 ++++ scripts/start-queue-runner.sh | 6 ++++++ 8 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 Procfile create mode 100644 run-hydra.nix create mode 100755 scripts/start-evaluator.sh create mode 100755 scripts/start-hydra.sh create mode 100755 scripts/start-postgres.sh create mode 100755 scripts/start-queue-runner.sh diff --git a/.gitignore b/.gitignore index f0e7b240..b5693cf3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ Makefile Makefile.in .deps +.hydra-data /config.guess /config.log /config.status diff --git a/Procfile b/Procfile new file mode 100644 index 00000000..42267366 --- /dev/null +++ b/Procfile @@ -0,0 +1,4 @@ +hydra-server: ./scripts/start-hydra.sh +hydra-queue-runner: ./scripts/start-queue-runner.sh +hydra-evaluator: ./scripts/start-evaluator.sh +postgres: ./scripts/start-postgres.sh diff --git a/flake.nix b/flake.nix index ec6e0349..f8e316f8 100644 --- a/flake.nix +++ b/flake.nix @@ -104,13 +104,16 @@ [ makeWrapper autoconf automake libtool unzip nukeReferences pkgconfig libpqxx gitAndTools.topGit mercurial darcs subversion bazaar openssl bzip2 libxslt perlDeps perl final.nix - postgresql95 # for running the tests boost (if lib.versionAtLeast lib.version "20.03pre" then nlohmann_json else nlohmann_json.override { multipleHeaders = true; }) ]; + checkInputs = [ + postgresql95 + ]; + hydraPath = lib.makeBinPath ( [ subversion openssh final.nix coreutils findutils pixz gzip bzip2 lzma gnutar unzip git gitAndTools.topGit mercurial darcs gnused bazaar @@ -290,6 +293,8 @@ nixpkgs.overlays = [ self.overlay nix.overlay ]; }; + runHydra = pkgs.callPackage ./run-hydra.nix {}; + nixosModules.hydraTest = { imports = [ self.nixosModules.hydra ]; diff --git a/run-hydra.nix b/run-hydra.nix new file mode 100644 index 00000000..7012e26e --- /dev/null +++ b/run-hydra.nix @@ -0,0 +1,16 @@ +{ foreman, mkShell, hydra, netcat, postgresql95 }: +{ doCheck ? true }: +mkShell { + buildInputs = [ + foreman (hydra.overrideAttrs (_: { inherit doCheck; })) netcat postgresql95 + ]; + + shellHook = '' + export HYDRA_HOME="src/" + mkdir -p .hydra-data + export HYDRA_DATA="$(pwd)/.hydra-data" + export HYDRA_DBI='dbi:Pg:dbname=hydra;host=localhost;' + + exec foreman start + ''; +} diff --git a/scripts/start-evaluator.sh b/scripts/start-evaluator.sh new file mode 100755 index 00000000..c0b43cf3 --- /dev/null +++ b/scripts/start-evaluator.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +# wait for hydra-server to listen +while ! nc -z localhost 3000; do sleep 1; done + +exec hydra-evaluator diff --git a/scripts/start-hydra.sh b/scripts/start-hydra.sh new file mode 100755 index 00000000..70bd9beb --- /dev/null +++ b/scripts/start-hydra.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# wait for postgresql to listen +while ! nc -z localhost 5432; do sleep 1; done + +createdb -h $(pwd)/.hydra-data/postgres hydra + +hydra-init +hydra-create-user alice --password foobar --role admin + +exec hydra-server diff --git a/scripts/start-postgres.sh b/scripts/start-postgres.sh new file mode 100755 index 00000000..fae2c4cb --- /dev/null +++ b/scripts/start-postgres.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +initdb ./.hydra-data/postgres +exec postgres -D ./.hydra-data/postgres -k $(pwd)/.hydra-data/postgres diff --git a/scripts/start-queue-runner.sh b/scripts/start-queue-runner.sh new file mode 100755 index 00000000..4b2741f7 --- /dev/null +++ b/scripts/start-queue-runner.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +# wait until hydra is listening on port 3000 +while ! nc -z localhost 3000; do sleep 1; done + +hydra-queue-runner