]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/commitdiff
Add notification for app deployment
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 5 Mar 2018 16:29:29 +0000 (17:29 +0100)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 5 Mar 2018 16:36:54 +0000 (17:36 +0100)
environments/integration/data/roles/cryptoportfolio.yaml
environments/production/data/roles/cryptoportfolio.yaml
modules/role/files/cryptoportfolio/slack-notify.py [new file with mode: 0644]
modules/role/manifests/cryptoportfolio.pp

index e55d15bb09b74f9c502ebd11521b8ea556417e0c..204d86bbf20b0153538a9ae4da1b784aee97ec0d 100644 (file)
@@ -5,3 +5,4 @@ cryptoportfolio::front_version: v0.0.2-3-g6200f9a
 cryptoportfolio::front_sha256: 69d31251ecd4fcea46d93dfee0184b1171019a765b6744b84f6eec6b10e5818f
 cryptoportfolio::bot_version: v0.4-2-g123411c
 cryptoportfolio::bot_sha256: c344653c6523ed4902e4e4270740c434b45c87876d827d2a695c6732a99cd59b
+cryptoportfolio::slack_webhook: "%{ldapvar.self.vars.cf_slack_webhook.0}"
index 37ab6a26b64e4610ebd8b907b6928bb2fa7ebd6c..1f967bf65eaa293c2fe7f959b4afec025df5f534 100644 (file)
@@ -5,3 +5,4 @@ cryptoportfolio::front_version: v0.0.2-3-g6200f9a
 cryptoportfolio::front_sha256: 69d31251ecd4fcea46d93dfee0184b1171019a765b6744b84f6eec6b10e5818f
 cryptoportfolio::bot_version: v0.5
 cryptoportfolio::bot_sha256: 8c606091da1502489cebfdae2be71522f691382287d514433f3b31dd6d301772
+cryptoportfolio::slack_webhook: "%{ldapvar.self.vars.cf_slack_webhook.0}"
diff --git a/modules/role/files/cryptoportfolio/slack-notify.py b/modules/role/files/cryptoportfolio/slack-notify.py
new file mode 100644 (file)
index 0000000..fe64fb6
--- /dev/null
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+
+import sys
+import json
+import urllib3
+
+project = sys.argv[1]
+url     = sys.argv[2]
+version = sys.argv[3]
+
+def post(url, data):
+    urllib3.disable_warnings()
+    http = urllib3.PoolManager()
+
+    encoded = data.encode('utf-8')
+
+    r = http.request("POST", url,
+            headers={'Content-Type': 'application/json'},
+            body=encoded)
+
+data = {
+        "icon_url": "https://learn.puppet.com/static/images/logos/Puppet-Logo-Mark-Amber.png",
+        "text": "Deployed {} on {}".format(version, project),
+        }
+
+json_data = json.dumps(data)
+post(url, json_data)
index 6c760b580c9b0c9327e36a97fe85af492f275e08..67d88fb7b38c97e21e2c0780d1b3788e2a937c7a 100644 (file)
@@ -41,6 +41,8 @@ class role::cryptoportfolio {
   $cf_bot_app_conf = "${cf_home}/bot_config.ini"
   $cf_bot_app_reports = "${cf_home}/bot_reports"
 
+  $cf_webhook_url = lookup("cryptoportfolio::slack_webhook") |$key| { "" }
+
   file { "/var/lib/postgres/data/certs":
     ensure  => directory,
     mode    => "0700",
@@ -179,6 +181,11 @@ class role::cryptoportfolio {
     password   => '!!',
   }
 
+  file { "/usr/local/bin/slack-notify":
+    mode   => "0755",
+    source => "puppet:///modules/role/cryptoportfolio/slack-notify.py",
+  }
+
   $front_version = lookup("cryptoportfolio::front_version") |$key| { {} }
   $front_sha256 = lookup("cryptoportfolio::front_sha256") |$key| { {} }
 
@@ -261,6 +268,15 @@ class role::cryptoportfolio {
         Archive["${cf_home}/trader_${bot_version}.tar.gz"]
       ],
     }
+
+    unless empty($cf_webhook_url) {
+      exec { "bot-slack-notify":
+        refreshonly => true,
+        command     => "/usr/local/bin/slack-notify Trader '${cf_webhook_url}' '${bot_version}'",
+        require     => File["/usr/local/bin/slack-notify"],
+        subscribe   => Exec["py-cryptoportfolio-dependencies"],
+      }
+    }
   }
 
   # FIXME: restore backup
@@ -387,5 +403,14 @@ class role::cryptoportfolio {
       command     => "/usr/bin/make static ENV=${cf_env}",
       refreshonly => true,
     }
+
+    unless empty($cf_webhook_url) {
+      exec { "front-slack-notify":
+        refreshonly => true,
+        command     => "/usr/local/bin/slack-notify Front '${cf_webhook_url}' '${front_version}'",
+        require     => File["/usr/local/bin/slack-notify"],
+        subscribe   => [Exec["go-cryptoportfolio-app"], Exec["web-cryptoportfolio-build"]],
+      }
+    }
   }
 }