aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-03-05 17:29:29 +0100
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-03-05 17:36:54 +0100
commita4c92ff7477d09b480cab028411bc7c6b250604e (patch)
tree5a8394a64cf4a1d3fb9ffcdb3c8ed3328b94fb79 /modules
parentd765eedf28199f6723dee5dab7c81a357be86f72 (diff)
downloadPuppet-a4c92ff7477d09b480cab028411bc7c6b250604e.tar.gz
Puppet-a4c92ff7477d09b480cab028411bc7c6b250604e.tar.zst
Puppet-a4c92ff7477d09b480cab028411bc7c6b250604e.zip
Add notification for app deployment
Diffstat (limited to 'modules')
-rw-r--r--modules/role/files/cryptoportfolio/slack-notify.py27
-rw-r--r--modules/role/manifests/cryptoportfolio.pp25
2 files changed, 52 insertions, 0 deletions
diff --git a/modules/role/files/cryptoportfolio/slack-notify.py b/modules/role/files/cryptoportfolio/slack-notify.py
new file mode 100644
index 0000000..fe64fb6
--- /dev/null
+++ b/modules/role/files/cryptoportfolio/slack-notify.py
@@ -0,0 +1,27 @@
1#!/usr/bin/env python3
2
3import sys
4import json
5import urllib3
6
7project = sys.argv[1]
8url = sys.argv[2]
9version = sys.argv[3]
10
11def post(url, data):
12 urllib3.disable_warnings()
13 http = urllib3.PoolManager()
14
15 encoded = data.encode('utf-8')
16
17 r = http.request("POST", url,
18 headers={'Content-Type': 'application/json'},
19 body=encoded)
20
21data = {
22 "icon_url": "https://learn.puppet.com/static/images/logos/Puppet-Logo-Mark-Amber.png",
23 "text": "Deployed {} on {}".format(version, project),
24 }
25
26json_data = json.dumps(data)
27post(url, json_data)
diff --git a/modules/role/manifests/cryptoportfolio.pp b/modules/role/manifests/cryptoportfolio.pp
index 6c760b5..67d88fb 100644
--- a/modules/role/manifests/cryptoportfolio.pp
+++ b/modules/role/manifests/cryptoportfolio.pp
@@ -41,6 +41,8 @@ class role::cryptoportfolio {
41 $cf_bot_app_conf = "${cf_home}/bot_config.ini" 41 $cf_bot_app_conf = "${cf_home}/bot_config.ini"
42 $cf_bot_app_reports = "${cf_home}/bot_reports" 42 $cf_bot_app_reports = "${cf_home}/bot_reports"
43 43
44 $cf_webhook_url = lookup("cryptoportfolio::slack_webhook") |$key| { "" }
45
44 file { "/var/lib/postgres/data/certs": 46 file { "/var/lib/postgres/data/certs":
45 ensure => directory, 47 ensure => directory,
46 mode => "0700", 48 mode => "0700",
@@ -179,6 +181,11 @@ class role::cryptoportfolio {
179 password => '!!', 181 password => '!!',
180 } 182 }
181 183
184 file { "/usr/local/bin/slack-notify":
185 mode => "0755",
186 source => "puppet:///modules/role/cryptoportfolio/slack-notify.py",
187 }
188
182 $front_version = lookup("cryptoportfolio::front_version") |$key| { {} } 189 $front_version = lookup("cryptoportfolio::front_version") |$key| { {} }
183 $front_sha256 = lookup("cryptoportfolio::front_sha256") |$key| { {} } 190 $front_sha256 = lookup("cryptoportfolio::front_sha256") |$key| { {} }
184 191
@@ -261,6 +268,15 @@ class role::cryptoportfolio {
261 Archive["${cf_home}/trader_${bot_version}.tar.gz"] 268 Archive["${cf_home}/trader_${bot_version}.tar.gz"]
262 ], 269 ],
263 } 270 }
271
272 unless empty($cf_webhook_url) {
273 exec { "bot-slack-notify":
274 refreshonly => true,
275 command => "/usr/local/bin/slack-notify Trader '${cf_webhook_url}' '${bot_version}'",
276 require => File["/usr/local/bin/slack-notify"],
277 subscribe => Exec["py-cryptoportfolio-dependencies"],
278 }
279 }
264 } 280 }
265 281
266 # FIXME: restore backup 282 # FIXME: restore backup
@@ -387,5 +403,14 @@ class role::cryptoportfolio {
387 command => "/usr/bin/make static ENV=${cf_env}", 403 command => "/usr/bin/make static ENV=${cf_env}",
388 refreshonly => true, 404 refreshonly => true,
389 } 405 }
406
407 unless empty($cf_webhook_url) {
408 exec { "front-slack-notify":
409 refreshonly => true,
410 command => "/usr/local/bin/slack-notify Front '${cf_webhook_url}' '${front_version}'",
411 require => File["/usr/local/bin/slack-notify"],
412 subscribe => [Exec["go-cryptoportfolio-app"], Exec["web-cryptoportfolio-build"]],
413 }
414 }
390 } 415 }
391} 416}