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..2ccd32b2 --- /dev/null +++ b/Procfile @@ -0,0 +1,4 @@ +hydra-server: ./foreman/start-hydra.sh +hydra-queue-runner: ./foreman/start-queue-runner.sh +hydra-evaluator: ./foreman/start-evaluator.sh +postgres: ./foreman/start-postgres.sh diff --git a/README.md b/README.md index c4a40de9..100e24f2 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ Make sure **State** at the top of the page is set to "_Enabled_" and click on "_ ### Building Hydra You can build Hydra via `nix-build` using the provided [default.nix](./default.nix): + ``` $ nix-build ``` @@ -84,6 +85,27 @@ $ configurePhase # NOTE: not ./configure $ make ``` +### Executing Hydra During Development + +When working on new features or bug fixes you need to be able to run Hydra from your working copy. This +can be done using [foreman](https://github.com/ddollar/foreman): + +``` +$ nix-shell +$ # hack hack +$ make +$ foreman start +``` + +Have a look at the [Procfile](./Procfile) if you want to see how the processes are being started. In order to avoid +conflicts with services that might be running on your host, hydra and postgress are started on custom ports: + +- hydra-server: 63333 +- postgresql: 64444 + +Note that this is only ever meant as an ad-hoc way of executing Hydra during development. Please make use of the +NixOS module for actually running Hydra in production. + ### JSON API You can also interface with Hydra through a JSON API. The API is defined in [hydra-api.yaml](./hydra-api.yaml) and you can test and explore via the [swagger editor](https://editor.swagger.io/?url=https://raw.githubusercontent.com/NixOS/hydra/master/hydra-api.yaml) diff --git a/flake.nix b/flake.nix index ec6e0349..2611bd01 100644 --- a/flake.nix +++ b/flake.nix @@ -104,13 +104,17 @@ [ 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 + postgresql95 (if lib.versionAtLeast lib.version "20.03pre" then nlohmann_json else nlohmann_json.override { multipleHeaders = true; }) ]; + checkInputs = [ + foreman + ]; + hydraPath = lib.makeBinPath ( [ subversion openssh final.nix coreutils findutils pixz gzip bzip2 lzma gnutar unzip git gitAndTools.topGit mercurial darcs gnused bazaar @@ -121,6 +125,10 @@ shellHook = '' PATH=$(pwd)/src/hydra-evaluator:$(pwd)/src/script:$(pwd)/src/hydra-eval-jobs:$(pwd)/src/hydra-queue-runner:$PATH PERL5LIB=$(pwd)/src/lib:$PERL5LIB + export HYDRA_HOME="src/" + mkdir -p .hydra-data + export HYDRA_DATA="$(pwd)/.hydra-data" + export HYDRA_DBI='dbi:Pg:dbname=hydra;host=localhost;port=64444' ''; preConfigure = "autoreconf -vfi"; diff --git a/foreman/start-evaluator.sh b/foreman/start-evaluator.sh new file mode 100755 index 00000000..249c4047 --- /dev/null +++ b/foreman/start-evaluator.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# wait for hydra-server to listen +while ! nc -z localhost 63333; do sleep 1; done + +touch .hydra-data/hydra.conf +HYDRA_CONFIG=$(pwd)/.hydra-data/hydra.conf exec hydra-evaluator diff --git a/foreman/start-hydra.sh b/foreman/start-hydra.sh new file mode 100755 index 00000000..79b4fdb8 --- /dev/null +++ b/foreman/start-hydra.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +# wait for postgresql to listen +while ! pg_isready -h $(pwd)/.hydra-data/postgres -p 64444; do sleep 1; done + +createdb -h $(pwd)/.hydra-data/postgres -p 64444 hydra + +hydra-init +hydra-create-user alice --password foobar --role admin + +touch .hydra-data/hydra.conf +HYDRA_CONFIG=$(pwd)/.hydra-data/hydra.conf exec hydra-dev-server --port 63333 diff --git a/foreman/start-postgres.sh b/foreman/start-postgres.sh new file mode 100755 index 00000000..c3fd7669 --- /dev/null +++ b/foreman/start-postgres.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +initdb ./.hydra-data/postgres +exec postgres -D ./.hydra-data/postgres -k $(pwd)/.hydra-data/postgres -p 64444 diff --git a/foreman/start-queue-runner.sh b/foreman/start-queue-runner.sh new file mode 100755 index 00000000..7c92f4e9 --- /dev/null +++ b/foreman/start-queue-runner.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# wait until hydra is listening on port 63333 +while ! nc -z localhost 63333; do sleep 1; done + +touch .hydra-data/hydra.conf +HYDRA_CONFIG=$(pwd)/.hydra-data/hydra.conf exec hydra-queue-runner