2019-05-08 11:28:02 +00:00
|
|
|
{
|
|
|
|
description = "A Nix-based continuous build system";
|
|
|
|
|
2020-10-20 10:21:06 +00:00
|
|
|
inputs.nixpkgs.follows = "nix/nixpkgs";
|
2022-09-06 14:18:52 +00:00
|
|
|
inputs.nix.url = "github:NixOS/nix/2.11.0";
|
2019-09-24 17:58:10 +00:00
|
|
|
|
2022-07-12 12:58:25 +00:00
|
|
|
outputs = { self, nixpkgs, nix }:
|
2019-08-09 11:10:50 +00:00
|
|
|
let
|
2019-09-17 15:25:59 +00:00
|
|
|
|
2022-03-31 10:55:15 +00:00
|
|
|
version = "${builtins.readFile ./version.txt}.${builtins.substring 0 8 (self.lastModifiedDate or "19700101")}.${self.shortRev or "DIRTY"}";
|
2019-09-17 15:25:59 +00:00
|
|
|
|
|
|
|
pkgs = import nixpkgs {
|
|
|
|
system = "x86_64-linux";
|
2022-07-12 13:03:27 +00:00
|
|
|
overlays = [ self.overlays.default nix.overlays.default ];
|
2019-05-22 12:44:10 +00:00
|
|
|
};
|
2019-09-17 15:25:59 +00:00
|
|
|
|
|
|
|
# NixOS configuration used for VM tests.
|
|
|
|
hydraServer =
|
|
|
|
{ config, pkgs, ... }:
|
2022-02-09 15:43:40 +00:00
|
|
|
{
|
|
|
|
imports = [ self.nixosModules.hydraTest ];
|
2019-09-17 15:25:59 +00:00
|
|
|
|
|
|
|
virtualisation.memorySize = 1024;
|
|
|
|
virtualisation.writableStore = true;
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.perlPackages.LWP pkgs.perlPackages.JSON ];
|
|
|
|
|
|
|
|
nix = {
|
|
|
|
# Without this nix tries to fetch packages from the default
|
|
|
|
# cache.nixos.org which is not reachable from this sandboxed NixOS test.
|
2022-02-09 15:43:40 +00:00
|
|
|
binaryCaches = [ ];
|
2019-09-17 15:25:59 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-02-09 15:43:40 +00:00
|
|
|
in
|
|
|
|
rec {
|
2019-05-08 11:28:02 +00:00
|
|
|
|
2019-09-17 15:25:59 +00:00
|
|
|
# A Nixpkgs overlay that provides a 'hydra' package.
|
2022-07-12 13:03:27 +00:00
|
|
|
overlays.default = final: prev: {
|
2019-09-17 15:25:59 +00:00
|
|
|
|
2020-09-09 11:30:43 +00:00
|
|
|
# Add LDAP dependencies that aren't currently found within nixpkgs.
|
|
|
|
perlPackages = prev.perlPackages // {
|
2021-06-07 15:34:51 +00:00
|
|
|
|
2022-03-11 19:51:26 +00:00
|
|
|
PrometheusTiny = final.perlPackages.buildPerlPackage {
|
2021-06-07 15:34:51 +00:00
|
|
|
pname = "Prometheus-Tiny";
|
|
|
|
version = "0.007";
|
|
|
|
src = final.fetchurl {
|
|
|
|
url = "mirror://cpan/authors/id/R/RO/ROBN/Prometheus-Tiny-0.007.tar.gz";
|
|
|
|
sha256 = "0ef8b226a2025cdde4df80129dd319aa29e884e653c17dc96f4823d985c028ec";
|
|
|
|
};
|
|
|
|
buildInputs = with final.perlPackages; [ HTTPMessage Plack TestException ];
|
|
|
|
meta = {
|
|
|
|
homepage = "https://github.com/robn/Prometheus-Tiny";
|
|
|
|
description = "A tiny Prometheus client";
|
|
|
|
license = with final.lib.licenses; [ artistic1 gpl1Plus ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-09-09 11:30:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
hydra = with final; let
|
2019-09-17 15:25:59 +00:00
|
|
|
perlDeps = buildEnv {
|
|
|
|
name = "hydra-perl-deps";
|
2020-03-31 11:19:36 +00:00
|
|
|
paths = with perlPackages; lib.closePropagation
|
2021-08-18 18:06:48 +00:00
|
|
|
[
|
2021-04-24 20:41:04 +00:00
|
|
|
AuthenSASL
|
2019-09-17 15:25:59 +00:00
|
|
|
CatalystActionREST
|
|
|
|
CatalystAuthenticationStoreDBIxClass
|
2020-09-09 11:30:43 +00:00
|
|
|
CatalystAuthenticationStoreLDAP
|
2019-09-17 15:25:59 +00:00
|
|
|
CatalystDevel
|
|
|
|
CatalystPluginAccessLog
|
|
|
|
CatalystPluginAuthorizationRoles
|
|
|
|
CatalystPluginCaptcha
|
2021-06-10 21:45:45 +00:00
|
|
|
CatalystPluginPrometheusTiny
|
2019-09-17 15:25:59 +00:00
|
|
|
CatalystPluginSessionStateCookie
|
|
|
|
CatalystPluginSessionStoreFastMmap
|
|
|
|
CatalystPluginStackTrace
|
|
|
|
CatalystTraitForRequestProxyBase
|
|
|
|
CatalystViewDownload
|
|
|
|
CatalystViewJSON
|
|
|
|
CatalystViewTT
|
|
|
|
CatalystXRoleApplicator
|
2021-08-18 18:06:48 +00:00
|
|
|
CatalystXScriptServerStarman
|
2021-04-15 14:55:40 +00:00
|
|
|
CryptPassphrase
|
|
|
|
CryptPassphraseArgon2
|
2019-09-17 15:25:59 +00:00
|
|
|
CryptRandPasswd
|
|
|
|
DataDump
|
|
|
|
DateTime
|
2021-08-18 18:06:48 +00:00
|
|
|
DBDPg
|
|
|
|
DBDSQLite
|
2019-09-17 15:25:59 +00:00
|
|
|
DigestSHA1
|
|
|
|
EmailMIME
|
|
|
|
EmailSender
|
2022-08-04 19:18:55 +00:00
|
|
|
FileLibMagic
|
2021-09-07 01:44:46 +00:00
|
|
|
FileSlurper
|
2021-02-19 22:04:19 +00:00
|
|
|
FileWhich
|
2021-08-18 18:06:48 +00:00
|
|
|
final.nix.perl-bindings
|
|
|
|
git
|
2019-09-17 15:25:59 +00:00
|
|
|
IOCompress
|
|
|
|
IPCRun
|
2022-01-25 20:09:05 +00:00
|
|
|
IPCRun3
|
2019-09-17 15:25:59 +00:00
|
|
|
JSON
|
2021-09-08 01:52:43 +00:00
|
|
|
JSONMaybeXS
|
2019-09-17 15:25:59 +00:00
|
|
|
JSONXS
|
2021-12-14 15:08:30 +00:00
|
|
|
ListSomeUtils
|
2019-09-17 15:25:59 +00:00
|
|
|
LWP
|
|
|
|
LWPProtocolHttps
|
2021-08-18 18:06:48 +00:00
|
|
|
ModulePluggable
|
2019-09-17 15:25:59 +00:00
|
|
|
NetAmazonS3
|
2019-11-07 17:42:15 +00:00
|
|
|
NetPrometheus
|
2019-09-17 15:25:59 +00:00
|
|
|
NetStatsd
|
|
|
|
PadWalker
|
2021-08-18 18:08:38 +00:00
|
|
|
ParallelForkManager
|
2021-08-19 19:55:52 +00:00
|
|
|
PerlCriticCommunity
|
2021-06-07 15:35:12 +00:00
|
|
|
PrometheusTinyShared
|
2021-12-14 15:03:18 +00:00
|
|
|
ReadonlyX
|
2019-09-17 15:25:59 +00:00
|
|
|
SetScalar
|
2021-08-18 18:06:48 +00:00
|
|
|
SQLSplitStatement
|
2019-09-17 15:25:59 +00:00
|
|
|
Starman
|
2021-04-15 14:40:55 +00:00
|
|
|
StringCompareConstantTime
|
2019-09-17 15:25:59 +00:00
|
|
|
SysHostnameLong
|
2019-09-24 17:03:18 +00:00
|
|
|
TermSizeAny
|
2022-01-21 16:11:09 +00:00
|
|
|
TermReadKey
|
2021-08-18 18:06:48 +00:00
|
|
|
Test2Harness
|
2021-02-22 18:29:52 +00:00
|
|
|
TestPostgreSQL
|
2019-09-17 15:25:59 +00:00
|
|
|
TextDiff
|
|
|
|
TextTable
|
2022-01-24 16:52:32 +00:00
|
|
|
UUID4Tiny
|
2022-02-10 02:06:28 +00:00
|
|
|
YAML
|
2019-09-17 15:25:59 +00:00
|
|
|
XMLSimple
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2022-02-09 15:43:40 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation {
|
2019-09-17 15:25:59 +00:00
|
|
|
|
|
|
|
name = "hydra-${version}";
|
|
|
|
|
|
|
|
src = self;
|
|
|
|
|
|
|
|
buildInputs =
|
2022-02-09 15:43:40 +00:00
|
|
|
[
|
|
|
|
makeWrapper
|
|
|
|
autoconf
|
|
|
|
automake
|
|
|
|
libtool
|
|
|
|
unzip
|
|
|
|
nukeReferences
|
2022-07-12 10:14:50 +00:00
|
|
|
pkg-config
|
2022-02-09 15:43:40 +00:00
|
|
|
libpqxx
|
2022-07-12 10:14:50 +00:00
|
|
|
top-git
|
2022-02-09 15:43:40 +00:00
|
|
|
mercurial
|
|
|
|
darcs
|
|
|
|
subversion
|
|
|
|
breezy
|
|
|
|
openssl
|
|
|
|
bzip2
|
|
|
|
libxslt
|
|
|
|
final.nix
|
|
|
|
perlDeps
|
|
|
|
perl
|
|
|
|
mdbook
|
|
|
|
pixz
|
2019-09-17 15:25:59 +00:00
|
|
|
boost
|
2022-01-24 15:44:27 +00:00
|
|
|
postgresql_13
|
2020-03-31 10:55:35 +00:00
|
|
|
(if lib.versionAtLeast lib.version "20.03pre"
|
2022-02-09 15:43:40 +00:00
|
|
|
then nlohmann_json
|
|
|
|
else nlohmann_json.override { multipleHeaders = true; })
|
2022-03-10 20:21:30 +00:00
|
|
|
prometheus-cpp
|
2019-09-17 15:25:59 +00:00
|
|
|
];
|
|
|
|
|
2020-05-13 15:37:25 +00:00
|
|
|
checkInputs = [
|
2022-02-09 15:43:40 +00:00
|
|
|
cacert
|
2022-07-12 12:58:25 +00:00
|
|
|
foreman
|
2022-02-09 15:43:40 +00:00
|
|
|
glibcLocales
|
2022-03-11 19:51:26 +00:00
|
|
|
libressl.nc
|
2022-02-09 15:43:58 +00:00
|
|
|
openldap
|
2022-02-09 15:43:40 +00:00
|
|
|
python3
|
2020-05-13 15:37:25 +00:00
|
|
|
];
|
|
|
|
|
2019-09-17 15:25:59 +00:00
|
|
|
hydraPath = lib.makeBinPath (
|
2022-02-09 15:43:40 +00:00
|
|
|
[
|
|
|
|
subversion
|
|
|
|
openssh
|
|
|
|
final.nix
|
|
|
|
coreutils
|
|
|
|
findutils
|
|
|
|
pixz
|
|
|
|
gzip
|
|
|
|
bzip2
|
2022-07-12 10:14:50 +00:00
|
|
|
xz
|
2022-02-09 15:43:40 +00:00
|
|
|
gnutar
|
|
|
|
unzip
|
|
|
|
git
|
2022-07-12 10:14:50 +00:00
|
|
|
top-git
|
2022-02-09 15:43:40 +00:00
|
|
|
mercurial
|
|
|
|
darcs
|
|
|
|
gnused
|
|
|
|
breezy
|
|
|
|
] ++ lib.optionals stdenv.isLinux [ rpm dpkg cdrkit ]
|
|
|
|
);
|
2019-09-17 15:25:59 +00:00
|
|
|
|
2022-02-09 15:45:27 +00:00
|
|
|
OPENLDAP_ROOT = openldap;
|
|
|
|
|
2019-09-17 15:25:59 +00:00
|
|
|
shellHook = ''
|
2021-03-05 07:35:57 +00:00
|
|
|
pushd $(git rev-parse --show-toplevel) >/dev/null
|
|
|
|
|
2020-02-19 19:36:52 +00:00
|
|
|
PATH=$(pwd)/src/hydra-evaluator:$(pwd)/src/script:$(pwd)/src/hydra-eval-jobs:$(pwd)/src/hydra-queue-runner:$PATH
|
2019-09-17 15:25:59 +00:00
|
|
|
PERL5LIB=$(pwd)/src/lib:$PERL5LIB
|
2021-03-05 07:35:57 +00:00
|
|
|
export HYDRA_HOME="$(pwd)/src/"
|
2020-05-15 11:48:21 +00:00
|
|
|
mkdir -p .hydra-data
|
|
|
|
export HYDRA_DATA="$(pwd)/.hydra-data"
|
|
|
|
export HYDRA_DBI='dbi:Pg:dbname=hydra;host=localhost;port=64444'
|
2021-03-05 07:35:57 +00:00
|
|
|
|
|
|
|
popd >/dev/null
|
2019-09-17 15:25:59 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
preConfigure = "autoreconf -vfi";
|
|
|
|
|
|
|
|
NIX_LDFLAGS = [ "-lpthread" ];
|
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
2020-03-04 14:39:21 +00:00
|
|
|
doCheck = true;
|
|
|
|
|
2019-09-17 15:25:59 +00:00
|
|
|
preCheck = ''
|
|
|
|
patchShebangs .
|
|
|
|
export LOGNAME=''${LOGNAME:-foo}
|
2020-10-12 15:16:31 +00:00
|
|
|
# set $HOME for bzr so it can create its trace file
|
|
|
|
export HOME=$(mktemp -d)
|
2019-09-17 15:25:59 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
mkdir -p $out/nix-support
|
|
|
|
|
|
|
|
for i in $out/bin/*; do
|
|
|
|
read -n 4 chars < $i
|
|
|
|
if [[ $chars =~ ELF ]]; then continue; fi
|
|
|
|
wrapProgram $i \
|
|
|
|
--prefix PERL5LIB ':' $out/libexec/hydra/lib:$PERL5LIB \
|
|
|
|
--prefix PATH ':' $out/bin:$hydraPath \
|
|
|
|
--set HYDRA_RELEASE ${version} \
|
|
|
|
--set HYDRA_HOME $out/libexec/hydra \
|
2019-10-04 15:32:29 +00:00
|
|
|
--set NIX_RELEASE ${final.nix.name or "unknown"}
|
2019-09-17 15:25:59 +00:00
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
|
|
|
dontStrip = true;
|
|
|
|
|
2022-07-12 10:14:50 +00:00
|
|
|
meta.description = "Build of Hydra on ${final.stdenv.system}";
|
2020-10-20 10:15:18 +00:00
|
|
|
passthru = { inherit perlDeps; inherit (final) nix; };
|
2019-09-17 15:25:59 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
hydraJobs = {
|
|
|
|
|
2019-10-15 18:21:42 +00:00
|
|
|
build.x86_64-linux = packages.x86_64-linux.hydra;
|
2019-09-17 15:25:59 +00:00
|
|
|
|
|
|
|
manual =
|
2022-02-09 15:43:40 +00:00
|
|
|
pkgs.runCommand "hydra-manual-${version}" { }
|
|
|
|
''
|
|
|
|
mkdir -p $out/share
|
|
|
|
cp -prvd ${pkgs.hydra}/share/doc $out/share/
|
2019-09-17 15:25:59 +00:00
|
|
|
|
2022-02-09 15:43:40 +00:00
|
|
|
mkdir $out/nix-support
|
|
|
|
echo "doc manual $out/share/doc/hydra" >> $out/nix-support/hydra-build-products
|
|
|
|
'';
|
2019-09-17 15:25:59 +00:00
|
|
|
|
|
|
|
tests.install.x86_64-linux =
|
2020-05-11 19:36:32 +00:00
|
|
|
with import (nixpkgs + "/nixos/lib/testing-python.nix") { system = "x86_64-linux"; };
|
2019-09-17 15:25:59 +00:00
|
|
|
simpleTest {
|
2022-07-12 12:46:48 +00:00
|
|
|
nodes.machine = hydraServer;
|
2019-09-17 15:25:59 +00:00
|
|
|
testScript =
|
|
|
|
''
|
2020-05-11 19:36:32 +00:00
|
|
|
machine.wait_for_job("hydra-init")
|
|
|
|
machine.wait_for_job("hydra-server")
|
|
|
|
machine.wait_for_job("hydra-evaluator")
|
|
|
|
machine.wait_for_job("hydra-queue-runner")
|
|
|
|
machine.wait_for_open_port("3000")
|
|
|
|
machine.succeed("curl --fail http://localhost:3000/")
|
2019-09-17 15:25:59 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
tests.notifications.x86_64-linux =
|
2020-05-11 19:36:32 +00:00
|
|
|
with import (nixpkgs + "/nixos/lib/testing-python.nix") { system = "x86_64-linux"; };
|
2019-09-17 15:25:59 +00:00
|
|
|
simpleTest {
|
2022-07-12 12:46:48 +00:00
|
|
|
nodes.machine = { pkgs, ... }: {
|
2019-09-17 15:25:59 +00:00
|
|
|
imports = [ hydraServer ];
|
|
|
|
services.hydra-dev.extraConfig = ''
|
|
|
|
<influxdb>
|
|
|
|
url = http://127.0.0.1:8086
|
|
|
|
db = hydra
|
|
|
|
</influxdb>
|
|
|
|
'';
|
|
|
|
services.influxdb.enable = true;
|
|
|
|
};
|
|
|
|
testScript = ''
|
2020-05-11 19:36:32 +00:00
|
|
|
machine.wait_for_job("hydra-init")
|
2019-09-17 15:25:59 +00:00
|
|
|
|
|
|
|
# Create an admin account and some other state.
|
2020-05-11 19:36:32 +00:00
|
|
|
machine.succeed(
|
|
|
|
"""
|
|
|
|
su - hydra -c "hydra-create-user root --email-address 'alice@example.org' --password foobar --role admin"
|
|
|
|
mkdir /run/jobset
|
|
|
|
chmod 755 /run/jobset
|
2021-08-16 19:51:51 +00:00
|
|
|
cp ${./t/jobs/api-test.nix} /run/jobset/default.nix
|
2020-05-11 19:36:32 +00:00
|
|
|
chmod 644 /run/jobset/default.nix
|
|
|
|
chown -R hydra /run/jobset
|
|
|
|
"""
|
|
|
|
)
|
2019-09-17 15:25:59 +00:00
|
|
|
|
|
|
|
# Wait until InfluxDB can receive web requests
|
2020-05-11 19:36:32 +00:00
|
|
|
machine.wait_for_job("influxdb")
|
|
|
|
machine.wait_for_open_port("8086")
|
2019-09-17 15:25:59 +00:00
|
|
|
|
|
|
|
# Create an InfluxDB database where hydra will write to
|
2020-05-11 19:36:32 +00:00
|
|
|
machine.succeed(
|
|
|
|
"curl -XPOST 'http://127.0.0.1:8086/query' "
|
|
|
|
+ "--data-urlencode 'q=CREATE DATABASE hydra'"
|
|
|
|
)
|
2019-09-17 15:25:59 +00:00
|
|
|
|
|
|
|
# Wait until hydra-server can receive HTTP requests
|
2020-05-11 19:36:32 +00:00
|
|
|
machine.wait_for_job("hydra-server")
|
|
|
|
machine.wait_for_open_port("3000")
|
2019-09-17 15:25:59 +00:00
|
|
|
|
|
|
|
# Setup the project and jobset
|
2020-05-11 19:36:32 +00:00
|
|
|
machine.succeed(
|
2021-03-05 07:35:57 +00:00
|
|
|
"su - hydra -c 'perl -I ${pkgs.hydra.perlDeps}/lib/perl5/site_perl ${./t/setup-notifications-jobset.pl}' >&2"
|
2020-05-11 19:36:32 +00:00
|
|
|
)
|
2019-09-17 15:25:59 +00:00
|
|
|
|
|
|
|
# Wait until hydra has build the job and
|
|
|
|
# the InfluxDBNotification plugin uploaded its notification to InfluxDB
|
2020-05-11 19:36:32 +00:00
|
|
|
machine.wait_until_succeeds(
|
|
|
|
"curl -s -H 'Accept: application/csv' "
|
|
|
|
+ "-G 'http://127.0.0.1:8086/query?db=hydra' "
|
|
|
|
+ "--data-urlencode 'q=SELECT * FROM hydra_build_status' | grep success"
|
|
|
|
)
|
2019-09-17 15:25:59 +00:00
|
|
|
'';
|
2022-02-09 15:43:40 +00:00
|
|
|
};
|
2019-09-17 15:25:59 +00:00
|
|
|
|
2021-03-30 20:35:39 +00:00
|
|
|
tests.gitea.x86_64-linux =
|
|
|
|
with import (nixpkgs + "/nixos/lib/testing-python.nix") { system = "x86_64-linux"; };
|
|
|
|
makeTest {
|
2022-07-12 12:46:48 +00:00
|
|
|
nodes.machine = { pkgs, ... }: {
|
2021-03-30 20:35:39 +00:00
|
|
|
imports = [ hydraServer ];
|
|
|
|
services.hydra-dev.extraConfig = ''
|
|
|
|
<gitea_authorization>
|
|
|
|
root=d7f16a3412e01a43a414535b16007c6931d3a9c7
|
|
|
|
</gitea_authorization>
|
|
|
|
'';
|
|
|
|
nix = {
|
|
|
|
distributedBuilds = true;
|
|
|
|
buildMachines = [{
|
|
|
|
hostName = "localhost";
|
|
|
|
systems = [ "x86_64-linux" ];
|
|
|
|
}];
|
2022-02-09 15:43:40 +00:00
|
|
|
binaryCaches = [ ];
|
2021-03-30 20:35:39 +00:00
|
|
|
};
|
|
|
|
services.gitea = {
|
|
|
|
enable = true;
|
|
|
|
database.type = "postgres";
|
|
|
|
disableRegistration = true;
|
|
|
|
httpPort = 3001;
|
|
|
|
};
|
|
|
|
services.openssh.enable = true;
|
|
|
|
environment.systemPackages = with pkgs; [ gitea git jq gawk ];
|
|
|
|
networking.firewall.allowedTCPPorts = [ 3000 ];
|
|
|
|
};
|
|
|
|
skipLint = true;
|
2022-02-09 15:43:40 +00:00
|
|
|
testScript =
|
|
|
|
let
|
|
|
|
scripts.mktoken = pkgs.writeText "token.sql" ''
|
|
|
|
INSERT INTO access_token (id, uid, name, created_unix, updated_unix, token_hash, token_salt, token_last_eight) VALUES (1, 1, 'hydra', 1617107360, 1617107360, 'a930f319ca362d7b49a4040ac0af74521c3a3c3303a86f327b01994430672d33b6ec53e4ea774253208686c712495e12a486', 'XRjWE9YW0g', '31d3a9c7');
|
|
|
|
'';
|
2021-03-30 20:35:39 +00:00
|
|
|
|
2022-02-09 15:43:40 +00:00
|
|
|
scripts.git-setup = pkgs.writeShellScript "setup.sh" ''
|
|
|
|
set -x
|
|
|
|
mkdir -p /tmp/repo $HOME/.ssh
|
|
|
|
cat ${snakeoilKeypair.privkey} > $HOME/.ssh/privk
|
|
|
|
chmod 0400 $HOME/.ssh/privk
|
|
|
|
git -C /tmp/repo init
|
|
|
|
cp ${smallDrv} /tmp/repo/jobset.nix
|
|
|
|
git -C /tmp/repo add .
|
|
|
|
git config --global user.email test@localhost
|
|
|
|
git config --global user.name test
|
|
|
|
git -C /tmp/repo commit -m 'Initial import'
|
|
|
|
git -C /tmp/repo remote add origin gitea@machine:root/repo
|
|
|
|
GIT_SSH_COMMAND='ssh -i $HOME/.ssh/privk -o StrictHostKeyChecking=no' \
|
|
|
|
git -C /tmp/repo push origin master
|
|
|
|
git -C /tmp/repo log >&2
|
|
|
|
'';
|
2021-03-30 20:35:39 +00:00
|
|
|
|
2022-02-09 15:43:40 +00:00
|
|
|
scripts.hydra-setup = pkgs.writeShellScript "hydra.sh" ''
|
|
|
|
set -x
|
|
|
|
su -l hydra -c "hydra-create-user root --email-address \
|
|
|
|
'alice@example.org' --password foobar --role admin"
|
|
|
|
|
|
|
|
URL=http://localhost:3000
|
|
|
|
USERNAME="root"
|
|
|
|
PASSWORD="foobar"
|
|
|
|
PROJECT_NAME="trivial"
|
|
|
|
JOBSET_NAME="trivial"
|
|
|
|
mycurl() {
|
|
|
|
curl --referer $URL -H "Accept: application/json" \
|
|
|
|
-H "Content-Type: application/json" $@
|
2021-03-30 20:35:39 +00:00
|
|
|
}
|
|
|
|
|
2022-02-09 15:43:40 +00:00
|
|
|
cat >data.json <<EOF
|
|
|
|
{ "username": "$USERNAME", "password": "$PASSWORD" }
|
|
|
|
EOF
|
|
|
|
mycurl -X POST -d '@data.json' $URL/login -c hydra-cookie.txt
|
2021-03-30 20:35:39 +00:00
|
|
|
|
2022-02-09 15:43:40 +00:00
|
|
|
cat >data.json <<EOF
|
|
|
|
{
|
|
|
|
"displayname":"Trivial",
|
|
|
|
"enabled":"1",
|
|
|
|
"visible":"1"
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
mycurl --silent -X PUT $URL/project/$PROJECT_NAME \
|
|
|
|
-d @data.json -b hydra-cookie.txt
|
|
|
|
|
|
|
|
cat >data.json <<EOF
|
|
|
|
{
|
|
|
|
"description": "Trivial",
|
|
|
|
"checkinterval": "60",
|
|
|
|
"enabled": "1",
|
|
|
|
"visible": "1",
|
|
|
|
"keepnr": "1",
|
|
|
|
"enableemail": true,
|
|
|
|
"emailoverride": "hydra@localhost",
|
|
|
|
"type": 0,
|
|
|
|
"nixexprinput": "git",
|
|
|
|
"nixexprpath": "jobset.nix",
|
|
|
|
"inputs": {
|
|
|
|
"git": {"value": "http://localhost:3001/root/repo.git", "type": "git"},
|
|
|
|
"gitea_repo_name": {"value": "repo", "type": "string"},
|
|
|
|
"gitea_repo_owner": {"value": "root", "type": "string"},
|
|
|
|
"gitea_status_repo": {"value": "git", "type": "string"},
|
|
|
|
"gitea_http_url": {"value": "http://localhost:3001", "type": "string"}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOF
|
2021-03-30 20:35:39 +00:00
|
|
|
|
2022-02-09 15:43:40 +00:00
|
|
|
mycurl --silent -X PUT $URL/jobset/$PROJECT_NAME/$JOBSET_NAME \
|
|
|
|
-d @data.json -b hydra-cookie.txt
|
2021-03-30 20:35:39 +00:00
|
|
|
'';
|
|
|
|
|
2022-02-09 15:43:40 +00:00
|
|
|
api_token = "d7f16a3412e01a43a414535b16007c6931d3a9c7";
|
|
|
|
|
|
|
|
snakeoilKeypair = {
|
|
|
|
privkey = pkgs.writeText "privkey.snakeoil" ''
|
|
|
|
-----BEGIN EC PRIVATE KEY-----
|
|
|
|
MHcCAQEEIHQf/khLvYrQ8IOika5yqtWvI0oquHlpRLTZiJy5dRJmoAoGCCqGSM49
|
|
|
|
AwEHoUQDQgAEKF0DYGbBwbj06tA3fd/+yP44cvmwmHBWXZCKbS+RQlAKvLXMWkpN
|
|
|
|
r1lwMyJZoSGgBHoUahoYjTh9/sJL7XLJtA==
|
|
|
|
-----END EC PRIVATE KEY-----
|
|
|
|
'';
|
|
|
|
|
|
|
|
pubkey = pkgs.lib.concatStrings [
|
|
|
|
"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHA"
|
|
|
|
"yNTYAAABBBChdA2BmwcG49OrQN33f/sj+OHL5sJhwVl2Qim0vkUJQCry1zFpKTa"
|
|
|
|
"9ZcDMiWaEhoAR6FGoaGI04ff7CS+1yybQ= sakeoil"
|
|
|
|
];
|
|
|
|
};
|
2021-03-30 20:35:39 +00:00
|
|
|
|
2022-02-09 15:43:40 +00:00
|
|
|
smallDrv = pkgs.writeText "jobset.nix" ''
|
|
|
|
{ trivial = builtins.derivation {
|
|
|
|
name = "trivial";
|
|
|
|
system = "x86_64-linux";
|
|
|
|
builder = "/bin/sh";
|
|
|
|
allowSubstitutes = false;
|
|
|
|
preferLocalBuild = true;
|
|
|
|
args = ["-c" "echo success > $out; exit 0"];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
''
|
|
|
|
import json
|
|
|
|
|
|
|
|
machine.start()
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
machine.wait_for_open_port(3000)
|
|
|
|
machine.wait_for_open_port(3001)
|
|
|
|
|
|
|
|
machine.succeed(
|
|
|
|
"su -l gitea -c 'GITEA_WORK_DIR=/var/lib/gitea gitea admin user create "
|
|
|
|
+ "--username root --password root --email test@localhost'"
|
|
|
|
)
|
|
|
|
machine.succeed("su -l postgres -c 'psql gitea < ${scripts.mktoken}'")
|
|
|
|
|
|
|
|
machine.succeed(
|
|
|
|
"curl --fail -X POST http://localhost:3001/api/v1/user/repos "
|
|
|
|
+ "-H 'Accept: application/json' -H 'Content-Type: application/json' "
|
|
|
|
+ f"-H 'Authorization: token ${api_token}'"
|
|
|
|
+ ' -d \'{"auto_init":false, "description":"string", "license":"mit", "name":"repo", "private":false}\'''
|
|
|
|
)
|
|
|
|
|
|
|
|
machine.succeed(
|
|
|
|
"curl --fail -X POST http://localhost:3001/api/v1/user/keys "
|
|
|
|
+ "-H 'Accept: application/json' -H 'Content-Type: application/json' "
|
|
|
|
+ f"-H 'Authorization: token ${api_token}'"
|
|
|
|
+ ' -d \'{"key":"${snakeoilKeypair.pubkey}","read_only":true,"title":"SSH"}\'''
|
|
|
|
)
|
|
|
|
|
|
|
|
machine.succeed(
|
|
|
|
"${scripts.git-setup}"
|
|
|
|
)
|
|
|
|
|
|
|
|
machine.succeed(
|
|
|
|
"${scripts.hydra-setup}"
|
|
|
|
)
|
|
|
|
|
|
|
|
machine.wait_until_succeeds(
|
|
|
|
'curl -Lf -s http://localhost:3000/build/1 -H "Accept: application/json" '
|
|
|
|
+ '| jq .buildstatus | xargs test 0 -eq'
|
|
|
|
)
|
|
|
|
|
|
|
|
data = machine.succeed(
|
|
|
|
'curl -Lf -s "http://localhost:3001/api/v1/repos/root/repo/statuses/$(cd /tmp/repo && git show | head -n1 | awk "{print \\$2}")" '
|
|
|
|
+ "-H 'Accept: application/json' -H 'Content-Type: application/json' "
|
|
|
|
+ f"-H 'Authorization: token ${api_token}'"
|
|
|
|
)
|
|
|
|
|
|
|
|
response = json.loads(data)
|
|
|
|
|
|
|
|
assert len(response) == 2, "Expected exactly two status updates for latest commit!"
|
|
|
|
assert response[0]['status'] == "success", "Expected latest status to be success!"
|
|
|
|
assert response[1]['status'] == "pending", "Expected first status to be pending!"
|
|
|
|
|
|
|
|
machine.shutdown()
|
2021-03-30 20:35:39 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-01-03 17:47:05 +00:00
|
|
|
tests.validate-openapi = pkgs.runCommand "validate-openapi"
|
|
|
|
{ buildInputs = [ pkgs.openapi-generator-cli ]; }
|
|
|
|
''
|
|
|
|
openapi-generator-cli validate -i ${./hydra-api.yaml}
|
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
|
2019-09-24 19:48:28 +00:00
|
|
|
container = nixosConfigurations.container.config.system.build.toplevel;
|
2019-08-09 11:10:50 +00:00
|
|
|
};
|
2019-06-03 10:29:42 +00:00
|
|
|
|
2019-10-15 18:21:42 +00:00
|
|
|
checks.x86_64-linux.build = hydraJobs.build.x86_64-linux;
|
|
|
|
checks.x86_64-linux.install = hydraJobs.tests.install.x86_64-linux;
|
2021-01-03 17:47:05 +00:00
|
|
|
checks.x86_64-linux.validate-openapi = hydraJobs.tests.validate-openapi;
|
2019-05-08 11:28:02 +00:00
|
|
|
|
2019-10-15 18:21:42 +00:00
|
|
|
packages.x86_64-linux.hydra = pkgs.hydra;
|
2022-07-12 13:03:27 +00:00
|
|
|
packages.x86_64-linux.default = pkgs.hydra;
|
2019-05-08 16:12:24 +00:00
|
|
|
|
2019-09-17 15:25:59 +00:00
|
|
|
nixosModules.hydra = {
|
|
|
|
imports = [ ./hydra-module.nix ];
|
2022-07-12 13:03:27 +00:00
|
|
|
nixpkgs.overlays = [ self.overlays.default nix.overlays.default ];
|
2019-09-24 17:58:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nixosModules.hydraTest = {
|
|
|
|
imports = [ self.nixosModules.hydra ];
|
|
|
|
|
|
|
|
services.hydra-dev.enable = true;
|
|
|
|
services.hydra-dev.hydraURL = "http://hydra.example.org";
|
|
|
|
services.hydra-dev.notificationSender = "admin@hydra.example.org";
|
|
|
|
|
|
|
|
systemd.services.hydra-send-stats.enable = false;
|
|
|
|
|
|
|
|
services.postgresql.enable = true;
|
2020-05-27 15:34:14 +00:00
|
|
|
services.postgresql.package = pkgs.postgresql_11;
|
2019-09-24 17:58:10 +00:00
|
|
|
|
|
|
|
# The following is to work around the following error from hydra-server:
|
|
|
|
# [error] Caught exception in engine "Cannot determine local time zone"
|
|
|
|
time.timeZone = "UTC";
|
2019-10-04 19:31:27 +00:00
|
|
|
|
|
|
|
nix.extraOptions = ''
|
|
|
|
allowed-uris = https://github.com/
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
nixosModules.hydraProxy = {
|
|
|
|
services.httpd = {
|
|
|
|
enable = true;
|
|
|
|
adminAddr = "hydra-admin@example.org";
|
|
|
|
extraConfig = ''
|
|
|
|
<Proxy *>
|
|
|
|
Order deny,allow
|
|
|
|
Allow from all
|
|
|
|
</Proxy>
|
|
|
|
|
|
|
|
ProxyRequests Off
|
|
|
|
ProxyPreserveHost On
|
|
|
|
ProxyPass /apache-errors !
|
|
|
|
ErrorDocument 503 /apache-errors/503.html
|
|
|
|
ProxyPass / http://127.0.0.1:3000/ retry=5 disablereuse=on
|
|
|
|
ProxyPassReverse / http://127.0.0.1:3000/
|
|
|
|
'';
|
|
|
|
};
|
2019-09-24 17:58:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nixosConfigurations.container = nixpkgs.lib.nixosSystem {
|
|
|
|
system = "x86_64-linux";
|
|
|
|
modules =
|
2022-02-09 15:43:40 +00:00
|
|
|
[
|
|
|
|
self.nixosModules.hydraTest
|
2019-11-07 17:46:32 +00:00
|
|
|
self.nixosModules.hydraProxy
|
2022-02-09 15:43:40 +00:00
|
|
|
{
|
2022-07-12 12:58:25 +00:00
|
|
|
system.configurationRevision = self.lastModifiedDate;
|
2019-09-24 17:58:10 +00:00
|
|
|
|
|
|
|
boot.isContainer = true;
|
|
|
|
networking.useDHCP = false;
|
|
|
|
networking.firewall.allowedTCPPorts = [ 80 ];
|
|
|
|
networking.hostName = "hydra";
|
|
|
|
|
|
|
|
services.hydra-dev.useSubstitutes = true;
|
|
|
|
}
|
|
|
|
];
|
2019-09-17 15:25:59 +00:00
|
|
|
};
|
2019-08-09 11:10:50 +00:00
|
|
|
|
|
|
|
};
|
2019-05-08 11:28:02 +00:00
|
|
|
}
|