aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--environments/integration/data/roles/cryptoportfolio.yaml1
-rw-r--r--environments/production/data/roles/cryptoportfolio.yaml1
-rw-r--r--modules/role/files/cryptoportfolio/slack-notify.py27
-rw-r--r--modules/role/manifests/cryptoportfolio.pp25
4 files changed, 54 insertions, 0 deletions
diff --git a/environments/integration/data/roles/cryptoportfolio.yaml b/environments/integration/data/roles/cryptoportfolio.yaml
index e55d15b..204d86b 100644
--- a/environments/integration/data/roles/cryptoportfolio.yaml
+++ b/environments/integration/data/roles/cryptoportfolio.yaml
@@ -5,3 +5,4 @@ cryptoportfolio::front_version: v0.0.2-3-g6200f9a
5cryptoportfolio::front_sha256: 69d31251ecd4fcea46d93dfee0184b1171019a765b6744b84f6eec6b10e5818f 5cryptoportfolio::front_sha256: 69d31251ecd4fcea46d93dfee0184b1171019a765b6744b84f6eec6b10e5818f
6cryptoportfolio::bot_version: v0.4-2-g123411c 6cryptoportfolio::bot_version: v0.4-2-g123411c
7cryptoportfolio::bot_sha256: c344653c6523ed4902e4e4270740c434b45c87876d827d2a695c6732a99cd59b 7cryptoportfolio::bot_sha256: c344653c6523ed4902e4e4270740c434b45c87876d827d2a695c6732a99cd59b
8cryptoportfolio::slack_webhook: "%{ldapvar.self.vars.cf_slack_webhook.0}"
diff --git a/environments/production/data/roles/cryptoportfolio.yaml b/environments/production/data/roles/cryptoportfolio.yaml
index 37ab6a2..1f967bf 100644
--- a/environments/production/data/roles/cryptoportfolio.yaml
+++ b/environments/production/data/roles/cryptoportfolio.yaml
@@ -5,3 +5,4 @@ cryptoportfolio::front_version: v0.0.2-3-g6200f9a
5cryptoportfolio::front_sha256: 69d31251ecd4fcea46d93dfee0184b1171019a765b6744b84f6eec6b10e5818f 5cryptoportfolio::front_sha256: 69d31251ecd4fcea46d93dfee0184b1171019a765b6744b84f6eec6b10e5818f
6cryptoportfolio::bot_version: v0.5 6cryptoportfolio::bot_version: v0.5
7cryptoportfolio::bot_sha256: 8c606091da1502489cebfdae2be71522f691382287d514433f3b31dd6d301772 7cryptoportfolio::bot_sha256: 8c606091da1502489cebfdae2be71522f691382287d514433f3b31dd6d301772
8cryptoportfolio::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
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}