From 6c3ae3664899e218345cdf1a55af45691af538b4 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 22 Feb 2016 17:23:06 +0100 Subject: [PATCH] hydra-queue-runner: Get store mode configuration from hydra.conf To use the local Nix store (default): store_mode = direct To use a local binary cache: store_mode = local-binary-cache binary_cache_dir = /var/lib/hydra/binary-cache To use an S3 bucket: store_mode = s3-binary-cache binary_cache_s3_bucket = my-nix-bucket Also, respect binary_cache_{secret,public}_key_file for signing the binary cache. --- src/hydra-queue-runner/hydra-queue-runner.cc | 62 ++++++++++++++++---- src/hydra-queue-runner/state.hh | 2 + 2 files changed, 51 insertions(+), 13 deletions(-) diff --git a/src/hydra-queue-runner/hydra-queue-runner.cc b/src/hydra-queue-runner/hydra-queue-runner.cc index 6fd6e2f8..a3ca0221 100644 --- a/src/hydra-queue-runner/hydra-queue-runner.cc +++ b/src/hydra-queue-runner/hydra-queue-runner.cc @@ -23,6 +23,25 @@ State::State() hydraData = getEnv("HYDRA_DATA"); if (hydraData == "") throw Error("$HYDRA_DATA must be set"); + /* Read hydra.conf. */ + auto hydraConfigFile = getEnv("HYDRA_CONFIG"); + if (pathExists(hydraConfigFile)) { + + for (auto line : tokenizeString(readFile(hydraConfigFile), "\n")) { + line = trim(string(line, 0, line.find('#'))); + + auto eq = line.find('='); + if (eq == std::string::npos) continue; + + auto key = trim(std::string(line, 0, eq)); + auto value = trim(std::string(line, eq + 1)); + + if (key == "") continue; + + hydraConfig[key] = value; + } + } + logDir = canonPath(hydraData + "/build-logs"); } @@ -727,20 +746,37 @@ void State::run(BuildID buildOne) if (!lock) throw Error("hydra-queue-runner is already running"); -#if 0 - auto store = make_ref(getLocalStore(), - "/home/eelco/Misc/Keys/test.nixos.org/secret", - "/home/eelco/Misc/Keys/test.nixos.org/public", - "/tmp/binary-cache"); -#endif + auto storeMode = hydraConfig["store_mode"]; - auto store = std::make_shared( - [this]() { return this->getLocalStore(); }, - "/home/eelco/hydra/secret", - "/home/eelco/hydra/public", - "nix-test-cache"); - store->init(); - _destStore = store; + if (storeMode == "direct" || storeMode == "") { + _destStore = openStore(); + } + + else if (storeMode == "local-binary-cache") { + auto dir = hydraConfig["binary_cache_dir"]; + if (dir == "") + throw Error("you must set ‘binary_cache_dir’ in hydra.conf"); + auto store = make_ref( + [this]() { return this->getLocalStore(); }, + "/home/eelco/Misc/Keys/test.nixos.org/secret", + "/home/eelco/Misc/Keys/test.nixos.org/public", + dir); + store->init(); + _destStore = std::shared_ptr(store); + } + + else if (storeMode == "s3-binary-cache") { + auto bucketName = hydraConfig["binary_cache_s3_bucket"]; + if (bucketName == "") + throw Error("you must set ‘binary_cache_s3_bucket’ in hydra.conf"); + auto store = make_ref( + [this]() { return this->getLocalStore(); }, + hydraConfig["binary_cache_secret_key_file"], + hydraConfig["binary_cache_public_key_file"], + bucketName); + store->init(); + _destStore = std::shared_ptr(store); + } { auto conn(dbPool.get()); diff --git a/src/hydra-queue-runner/state.hh b/src/hydra-queue-runner/state.hh index a524670d..58abe6ec 100644 --- a/src/hydra-queue-runner/state.hh +++ b/src/hydra-queue-runner/state.hh @@ -262,6 +262,8 @@ private: nix::Path hydraData, logDir; + std::map hydraConfig; + /* The queued builds. */ typedef std::map Builds; Sync builds;