Hydra/ru: Difference between revisions

From NixOS Wiki
Unabomberlive (talk | contribs)
Created page with "* [https://hydra.nixos.org/project/nixos NixOS]"
Tags: Mobile edit Mobile web edit
Unabomberlive (talk | contribs)
Created page with "== Источники =="
 
(3 intermediate revisions by the same user not shown)
Line 30: Line 30:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Web_Configuration"></span>
=== Web Configuration ===
=== Веб-настройка ===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 259: Line 258:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Known_Issues"></span>
== Known Issues ==
== Известные Проблемы ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 304: Line 302:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* [https://hydra.nixos.org/project/nixpkgs Nixpkgs]
* [https://hydra.nixos.org/project/nixpkgs Nixpkgs]
</div>


* [https://hydra.nixos.org/project/nixos NixOS]
* [https://hydra.nixos.org/project/nixos NixOS]


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Resources"></span>
== Resources ==
== Источники ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">

Latest revision as of 10:39, 14 August 2024

Hydra - это инструмент для непрерывного интеграционного тестирования и выпуска программного обеспечения, который использует чисто функциональный язык для описания заданий сборки и их зависимостей. Непрерывная интеграция - это простая техника, позволяющая повысить качество процесса разработки программного обеспечения. Автоматизированная система постоянно или периодически проверяет исходный код проекта, собирает его, запускает тесты и готовит отчеты для разработчиков. Таким образом, автоматически отлавливаются различные ошибки, которые могут быть случайно зафиксированы в кодовой базе.

Официальные серверы Hydra предоставляют готовые бинарные пакеты для ускорения процесса обновления Nixpgs: Пользователям не нужно компилировать их на своих компьютерах.

Руководство [https://nixos.org/hydra/manual/ Hydra] содержит обзор функциональности и возможностей Hydra, а также актуальное руководство по установке.

Установка

Полное развертывание может быть осуществлено так:

  services.hydra = {
    enable = true;
    hydraURL = "http://localhost:3000"; # externally visible URL
    notificationSender = "hydra@localhost"; # e-mail of Hydra service
    # a standalone Hydra will require you to unset the buildMachinesFiles list to avoid using a nonexistant /etc/nix/machines
    buildMachinesFiles = [];
    # you will probably also want, otherwise *everything* will be built from scratch
    useSubstitutes = true;
  };

Модуль автоматически включит postgresql, если вы не измените опцию services.hydra.dbi. Схема базы данных будет создана автоматически службой Hydra, однако имейте в виду, что в базе данных будет храниться некоторое состояние, и полная stateless-конфигурация в настоящее время невозможна - делайте резервные копии.

Веб-настройка

Hydra will provide the web interface at localhost port 3000. However you need to create a new admin user (as UNIX user hydra) before being able to perform any changes:

# su - hydra
$ hydra-create-user alice --full-name 'Alice Q. User' \
    --email-address 'alice@example.org' --password-prompt --role admin

Виртуальная машина

If not configured explicitly to do otherwise, Hydra will specify localhost as the default build machine. By default, system features enabling builds to be performed in virtual machines like "kvm" or "nixos-test" are not enabled. Such jobs will be queued indefinitely. Those options can be activated as follows:

{
  nix.buildMachines = [
    { hostName = "localhost";
      system = "x86_64-linux";
      supportedFeatures = ["kvm" "nixos-test" "big-parallel" "benchmark"];
      maxJobs = 8;
    }
  ];
}

This option leads to the file /etc/nix/machines being created. If the hydra service config is still set to buildMachinesFiles = [], then it will be ignored, so remove this option again or add /etc/nix/machines to it.

Flake jobset

Configure jobset to the following:

  • Type: Flake

The Flake output should have the attribute hydraJobs containing an attribute set that may be nested and reference derivations.

Пример вывода Flake, который заставляет Hydra собирать все пакеты, может выглядеть следующим образом:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  };
  outputs = { self, nixpkgs, ... }: {
    packages.x86_64-linux = {
      ...
    };

    hydraJobs = {
      inherit (self)
        packages;
    };
  };
}

Restricted Mode

Hydra evaluates flakes in restricted mode. This prevents access to files outside of the nix store, including those fetched as flake inputs. Update your nix.settings.allowed-uris to include URI prefixes from which you expect flake inputs to be fetched:

nix.settings.allowed-uris = [
  "github:"
  "git+https://github.com/"
  "git+ssh://github.com/"
];

Build a single Package from nixpkgs

Right now it is not possible to build a single package from nixpkgs with just that input. You will need to provide a supplementary repository which defines what to build. For examples you can check the hydra-example by makefu and in the Hydra Manual.

Императивная Сборка

These steps are required to build the hello package.

  1. log into Hydra after creating a user with hydra-create-user
  1. create new project
  • identifier: example-hello
  • display name: example-hello
  1. Actions -> Create jobset
  • identifier: hello
  • Nix expression: release.nix in hydra-example -> will evaluate the file release.nix in the given input
  • check interval: 60
  • scheduling shares: 1
  • Inputs:
Input Name Type Value Note
nixpkgs git checkout https://github.com/nixos/nixpkgs nixos-21.11 will check out branch nixos-21.11, will be made available to the nix expression via <nixpkgs>.
hydra-example git checkout https://github.com/makefu/hydra-example hydra-example is used by the jobset as input, release.nix is in the root directory

After creation, the jobset should be in the evaluation phase where inputs will be fetched. This phase may take some time as the complete nixpkgs repository needs to be downloaded before continuing. The result of the evaluation should be a single job which will get built.

Декларативная Сборка

Since 2016, Hydra supports declarative creation of jobsets. Check out the example repository and description by Shea Levy.

Hydra Internals

Definitions

This subsection provides an overview of the Hydra-specific definitions and how to configure them.

Project

A cluster of Jobs which are all coming from a single input (like a git checkout), the first thing you will need to create. Every Job should be able to be built independently from another. Most of the time the project maps to a single repository like nixpkgs. It is comparable to the project definition in Jenkins.

Jobsets

A Jobset is a list of jobs which will be run. Often a jobset fits to a certain branch (master, staging, stable). A Jobset is defined by its inputs and will trigger if these inputs change. For example when a new commit onto a branch is added. Jobsets may depend on each other.

Job

A closure which will be built as part of a job set (like a single package, iso image or tarball).

Release Set

Defines all the jobs which are described in your release. By convention a file calledrelease.nix is being used. See the Hydra manual for Build Recipes for a thorough description of the structure.

Evaluation

The process of interpreting nix code into a list of .drv files. These files are the build recipes for all related outputs. You can introspect these files by running nix show-derivation nixpkgs.hello.

Сборка

Instantiation of a Job which is being triggered by being part of the release set.

Известные Проблемы

  • hydra-queue-runner sometimes gets stuck even with builds are in the queue, and the builds are not scheduled. The issue is being tracked here. In the meantime, a workaround is to add a cron job that regularly restarts the hydra-queue-runner systemd service. Possible fix: [1]
  • If you see error: unexpected end-of-file it can mean multiple things, some of them are:
  1. You have a miss-match between nix versions on the Hydra server and the builder
  1. It can also mean that hydra-queue-runner needs privileges on the build server. Reference: [2]
  • The default timeout for git operations is 600 seconds [3], which might cause fetches of large repositories like nixos/nixpkgs to fail: error fetching latest change from git repo at `https://github.com/nixos/nixpkgs': timeout. The timeout can be increased with the following configuration.nix snippet:
{
  services.hydra.extraConfig = ''
    <git-input>
      timeout = 3600
    </git-input>
  '';
}

Hydra для релизов NixOS

Hydra is used for managing official Nix project releases. The project Hydra server: https://hydra.nixos.org/

Some Hydra trackers for Nix projects:

Источники