Skip to content

Commit

Permalink
Merge pull request #697 from NixOS/feat/webhook-riir
Browse files Browse the repository at this point in the history
Rewrite the webhook receiver in Rust
  • Loading branch information
dasJ authored Dec 27, 2024
2 parents 6d4559d + 0702f76 commit df03a6c
Show file tree
Hide file tree
Showing 22 changed files with 384 additions and 1,050 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: nix-build
run: nix-build -A ofborg.rs -A ofborg.php
run: nix-build -A ofborg.rs
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
config.php
vendor
*.log
test.php
config.json
.bash_hist
config.private.json
Expand Down
24 changes: 22 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions config.public.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
{
"github_webhook_receiver": {
"listen": "[::1]:9899",
"webhook_secret_file: "/run/secrets/ofborg/github-webhook-secret",
"rabbitmq": {
"host": "localhost",
"ssl": false,
"username": "ofborg-github-webhook",
"password_file": "/run/secrets/ofborg/github-webhook-amqp-password",
"virtualhost": "ofborg"
}
},
"feedback": {
"full_logs": true
},
Expand Down
27 changes: 5 additions & 22 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 3 additions & 27 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-22.11";
nixpkgs-for-php.url = "github:nixos/nixpkgs/nixos-22.05";
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
};

outputs =
{ self
, nixpkgs
, nixpkgs-for-php
, ...
}@inputs:
let
Expand All @@ -22,21 +20,6 @@
pkgs = import nixpkgs {
inherit system;
};
phpPkgs = import nixpkgs-for-php {
inherit system;
};

phpEnv = pkgs.mkShell {
name = "gh-event-forwarder";
buildInputs = with pkgs; [
nix-prefetch-git
phpPkgs.php
phpPkgs.phpPackages.composer
git
curl
bash
];
};
in
{
default = pkgs.mkShell {
Expand Down Expand Up @@ -78,7 +61,6 @@
RUST_BACKTRACE = "1";
RUST_LOG = "ofborg=debug";
NIX_PATH = "nixpkgs=${pkgs.path}";
passthru.phpEnv = phpEnv;
};
});

Expand All @@ -88,16 +70,12 @@
inherit system;
};

phpPkgs = import nixpkgs-for-php {
inherit system;
};

pkg = pkgs.rustPlatform.buildRustPackage {
name = "ofborg";
src = pkgs.nix-gitignore.gitignoreSource [ ] ./.;

nativeBuildInputs = with pkgs; [
pkgconfig
pkg-config
pkgs.rustPackages.clippy
];

Expand Down Expand Up @@ -144,16 +122,14 @@
test -e $out/bin/builder
test -e $out/bin/github_comment_filter
test -e $out/bin/github_comment_poster
test -e $out/bin/github_webhook_receiver
test -e $out/bin/log_message_collector
test -e $out/bin/evaluation_filter
'';

ofborg.php = import ./php { pkgs = phpPkgs; };
});

hydraJobs = {
buildRs = forAllSystems (system: self.packages.${system}.ofborg.rs);
buildPhp = self.packages.x86_64-linux.ofborg.php;
};
};
}
3 changes: 3 additions & 0 deletions ofborg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ tracing = "0.1.37"
tracing-subscriber = { version = "0.3.16", features = ["json", "env-filter"] }
uuid = { version = "1.2", features = ["v4"] }
rustls-pemfile = "1.0.2"
hmac = "0.12.1"
sha2 = "0.10.8"
hex = "0.4.3"
13 changes: 9 additions & 4 deletions ofborg/src/bin/evaluation-filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::env;
use std::error::Error;

use async_std::task;
use tracing::info;
use tracing::{error, info};

use ofborg::config;
use ofborg::easyamqp::{self, ChannelExt, ConsumerExt};
Expand All @@ -14,10 +14,15 @@ fn main() -> Result<(), Box<dyn Error>> {

let arg = env::args()
.nth(1)
.expect("usage: evaluation-filter <config>");
.unwrap_or_else(|| panic!("usage: {} <config>", std::env::args().next().unwrap()));
let cfg = config::load(arg.as_ref());

let conn = easylapin::from_config(&cfg.rabbitmq)?;
let Some(filter_cfg) = config::load(arg.as_ref()).evaluation_filter else {
error!("No evaluation filter configuration found!");
panic!();
};

let conn = easylapin::from_config(&filter_cfg.rabbitmq)?;
let mut chan = task::block_on(conn.create_channel())?;

chan.declare_exchange(easyamqp::ExchangeConfig {
Expand Down Expand Up @@ -52,7 +57,7 @@ fn main() -> Result<(), Box<dyn Error>> {
chan.bind_queue(easyamqp::BindQueueConfig {
queue: queue_name.clone(),
exchange: "github-events".to_owned(),
routing_key: Some("pull_request.nixos/nixpkgs".to_owned()),
routing_key: Some("pull_request.nixos/*".to_owned()),
no_wait: false,
})?;

Expand Down
34 changes: 31 additions & 3 deletions ofborg/src/bin/github-comment-filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::env;
use std::error::Error;

use async_std::task;
use tracing::info;
use ofborg::systems::System;
use tracing::{error, info};

use ofborg::config;
use ofborg::easyamqp::{self, ChannelExt, ConsumerExt};
Expand All @@ -14,10 +15,15 @@ fn main() -> Result<(), Box<dyn Error>> {

let arg = env::args()
.nth(1)
.expect("usage: github-comment-filter <config>");
.unwrap_or_else(|| panic!("usage: {} <config>", std::env::args().next().unwrap()));
let cfg = config::load(arg.as_ref());

let conn = easylapin::from_config(&cfg.rabbitmq)?;
let Some(filter_cfg) = config::load(arg.as_ref()).github_comment_filter else {
error!("No comment filter configuration found!");
panic!();
};

let conn = easylapin::from_config(&filter_cfg.rabbitmq)?;
let mut chan = task::block_on(conn.create_channel())?;

chan.declare_exchange(easyamqp::ExchangeConfig {
Expand Down Expand Up @@ -57,6 +63,28 @@ fn main() -> Result<(), Box<dyn Error>> {
no_wait: false,
})?;

chan.declare_exchange(easyamqp::ExchangeConfig {
exchange: "build-results".to_owned(),
exchange_type: easyamqp::ExchangeType::Fanout,
passive: false,
durable: true,
auto_delete: false,
no_wait: false,
internal: false,
})?;

// Create build job queues
for sys in System::all_known_systems().iter().map(System::to_string) {
chan.declare_queue(easyamqp::QueueConfig {
queue: format!("build-inputs-{sys}"),
passive: false,
durable: true,
exclusive: false,
auto_delete: false,
no_wait: false,
})?;
}

let handle = easylapin::WorkerChannel(chan).consume(
tasks::githubcommentfilter::GitHubCommentWorker::new(cfg.acl(), cfg.github()),
easyamqp::ConsumeConfig {
Expand Down
Loading

0 comments on commit df03a6c

Please sign in to comment.