From c0601e0f65bd32cefb610d93e82181e27c3168fd Mon Sep 17 00:00:00 2001 From: Stephan Maka Date: Fri, 26 Apr 2019 00:16:33 +0200 Subject: [PATCH] wrap mattermost-github-integration with uwsgi, add to nixbld --- nixbld-etc-nixos/configuration.nix | 18 +++++ .../mattermost-github-integration.nix | 76 ------------------- .../mattermost-github-integration/config.py | 25 ++++++ .../mattermost-github-integration/pkg.nix | 32 ++++++++ .../uwsgi-config.nix | 15 ++++ 5 files changed, 90 insertions(+), 76 deletions(-) delete mode 100644 nixbld-etc-nixos/mattermost-github-integration.nix create mode 100644 nixbld-etc-nixos/mattermost-github-integration/config.py create mode 100644 nixbld-etc-nixos/mattermost-github-integration/pkg.nix create mode 100644 nixbld-etc-nixos/mattermost-github-integration/uwsgi-config.nix diff --git a/nixbld-etc-nixos/configuration.nix b/nixbld-etc-nixos/configuration.nix index cd91c94..7c6722b 100644 --- a/nixbld-etc-nixos/configuration.nix +++ b/nixbld-etc-nixos/configuration.nix @@ -218,6 +218,24 @@ ACTION=="add", SUBSYSTEM=="tty", \ locations."~ /api/v[0-9]+/(users/)?websocket$".proxyPass = "http://127.0.0.1:8065"; locations."~ /api/v[0-9]+/(users/)?websocket$".proxyWebsockets = true; }; + "hooks.m-labs.hk" = { + extraConfig = '' + location / { + include ${pkgs.nginx}/conf/uwsgi_params; + uwsgi_pass unix:${config.services.uwsgi.runDir}/uwsgi.sock; + } + ''; + }; + }; + }; + services.uwsgi = { + enable = true; + plugins = [ "python3" ]; + instance = { + type = "emperor"; + vassals = { + mattermostgithub = import ./mattermost-github-integration/uwsgi-config.nix { inherit config pkgs; }; + }; }; }; diff --git a/nixbld-etc-nixos/mattermost-github-integration.nix b/nixbld-etc-nixos/mattermost-github-integration.nix deleted file mode 100644 index a2daff3..0000000 --- a/nixbld-etc-nixos/mattermost-github-integration.nix +++ /dev/null @@ -1,76 +0,0 @@ -{ fetchFromGitHub, python3Packages }: -with python3Packages; - -let - config = builtins.toFile "config.py" '' - USERNAME = "Github" - ICON_URL = "" - - # Repository settings - MATTERMOST_WEBHOOK_URLS = { - 'default' : ("yourdomain.org/hooks/hookid", "off-topic"), - } - - # Ignore specified event actions - GITHUB_IGNORE_ACTIONS = { - "pull_request": ["synchronize"] - } - - # Ignore events from specified users - IGNORE_USERS = { - "someuser": ["push"], - "anotheruser": ["push", "create"] - } - - # Redirect events to different channels - REDIRECT_EVENTS = { - "push": "commits" - } - SECRET = "" - SHOW_AVATARS = True - SERVER = { - 'hook': "/", - 'address': "0.0.0.0", - 'port': 5000, - } - ''; -in - -buildPythonApplication rec { - pname = "mattermost-github-integration"; - version = "0.0.0-unstable"; - src = fetchFromGitHub { - owner = "softdevteam"; - repo = "mattermost-github-integration"; - rev = "master"; - sha256 = "1hfvjaxjhliy8sv9j3616fkdwd2jqhfsj9ai7ggx88zhxknrfx85"; - }; - propagatedBuildInputs = [ - appdirs - click - flask - itsdangerous - jinja2 - markupsafe - olefile - packaging - pillow - pyparsing - requests - six - werkzeug - ]; - checkInputs = [ - pytest - ]; - preBuild = '' - cp ${config} mattermostgithub/config.py - ''; - postInstall = '' - mkdir $out/bin - echo "#!#{python}/bin/python" > $out/bin/server - cat server.py >> $out/bin/server - chmod a+x $out/bin/server - ''; - doCheck = true; -} diff --git a/nixbld-etc-nixos/mattermost-github-integration/config.py b/nixbld-etc-nixos/mattermost-github-integration/config.py new file mode 100644 index 0000000..319b240 --- /dev/null +++ b/nixbld-etc-nixos/mattermost-github-integration/config.py @@ -0,0 +1,25 @@ +USERNAME = "Github" +ICON_URL = "" + +# Repository settings +MATTERMOST_WEBHOOK_URLS = { + 'default' : ("chat.m-labs.hk/hooks/hookid", "town-square"), +} + +# Ignore specified event actions +GITHUB_IGNORE_ACTIONS = { +} + +# Ignore events from specified users +IGNORE_USERS = { +} + +# Redirect events to different channels +REDIRECT_EVENTS = { +} + +SECRET = "" +SHOW_AVATARS = True +SERVER = { + 'hook': "/mattermost-github", +} diff --git a/nixbld-etc-nixos/mattermost-github-integration/pkg.nix b/nixbld-etc-nixos/mattermost-github-integration/pkg.nix new file mode 100644 index 0000000..909da88 --- /dev/null +++ b/nixbld-etc-nixos/mattermost-github-integration/pkg.nix @@ -0,0 +1,32 @@ +{ fetchFromGitHub, python3Packages }: +with python3Packages; + +buildPythonPackage rec { + pname = "mattermost-github-integration"; + version = "0.0.0-unstable"; + src = fetchFromGitHub { + owner = "softdevteam"; + repo = "mattermost-github-integration"; + rev = "master"; + sha256 = "1hfvjaxjhliy8sv9j3616fkdwd2jqhfsj9ai7ggx88zhxknrfx85"; + }; + propagatedBuildInputs = [ + appdirs + click + flask + itsdangerous + jinja2 + markupsafe + olefile + packaging + pillow + pyparsing + requests + six + werkzeug + ]; + checkInputs = [ + pytest + ]; + doCheck = true; +} diff --git a/nixbld-etc-nixos/mattermost-github-integration/uwsgi-config.nix b/nixbld-etc-nixos/mattermost-github-integration/uwsgi-config.nix new file mode 100644 index 0000000..908da4c --- /dev/null +++ b/nixbld-etc-nixos/mattermost-github-integration/uwsgi-config.nix @@ -0,0 +1,15 @@ +{ config, pkgs }: + +let + pkg = pkgs.callPackage ./pkg.nix {}; +in { + type = "normal"; + pythonPackages = self: [ pkg ]; + module = "mattermostgithub:app"; + env = [ + "MGI_CONFIG_FILE=${./config.py}" + ]; + socket = "${config.services.uwsgi.runDir}/uwsgi.sock"; + # allow access from nginx + chmod-socket = 666; +}