cluster/services/ways: support gRPC

This commit is contained in:
Max Headroom 2024-08-23 02:50:01 +02:00
parent 06041f8498
commit 25bd410599
2 changed files with 15 additions and 2 deletions

View file

@ -25,7 +25,14 @@ in
]; ];
locations = lib.mkMerge [ locations = lib.mkMerge [
{ {
"/".proxyPass = cfg.target; "/" = if cfg.grpc then {
extraConfig = ''
set $nix_proxy_grpc_target ${cfg.target};
grpc_pass $nix_proxy_grpc_target;
'';
} else {
proxyPass = cfg.target;
};
"${cfg.healthCheckPath}".extraConfig = "access_log off;"; "${cfg.healthCheckPath}".extraConfig = "access_log off;";
} }
{ {

View file

@ -35,6 +35,12 @@ with lib;
}; };
}; };
grpc = mkOption {
description = "Whether this endpoint is a gRPC service.";
type = types.bool;
default = false;
};
target = mkOption { target = mkOption {
type = types.str; type = types.str;
}; };
@ -101,7 +107,7 @@ with lib;
(lib.mkIf options.consulService.isDefined { (lib.mkIf options.consulService.isDefined {
useConsul = true; useConsul = true;
nginxUpstreamName = "ways_upstream_${builtins.hashString "md5" options.consulService.value}"; nginxUpstreamName = "ways_upstream_${builtins.hashString "md5" options.consulService.value}";
target = "http://${options.nginxUpstreamName.value}"; target = "${if config.grpc then "grpc" else "http"}://${options.nginxUpstreamName.value}";
}) })
(lib.mkIf options.bucket.isDefined { (lib.mkIf options.bucket.isDefined {
consulService = "garage-web"; consulService = "garage-web";