aboutsummaryrefslogtreecommitdiff
path: root/modules/role/manifests/cryptoportfolio/front.pp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/role/manifests/cryptoportfolio/front.pp')
-rw-r--r--modules/role/manifests/cryptoportfolio/front.pp158
1 files changed, 158 insertions, 0 deletions
diff --git a/modules/role/manifests/cryptoportfolio/front.pp b/modules/role/manifests/cryptoportfolio/front.pp
new file mode 100644
index 0000000..280ef8b
--- /dev/null
+++ b/modules/role/manifests/cryptoportfolio/front.pp
@@ -0,0 +1,158 @@
1class role::cryptoportfolio::front inherits role::cryptoportfolio {
2 ensure_resource('exec', 'systemctl daemon-reload', {
3 command => '/usr/bin/systemctl daemon-reload',
4 refreshonly => true
5 })
6
7 $password_seed = lookup("base_installation::puppet_pass_seed")
8
9 $cf_front_app = "${home}/go/src/immae.eu/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front"
10 $cf_front_app_api_workdir = "${cf_front_app}/cmd/app"
11 $cf_front_app_api_bin = "${cf_front_app_api_workdir}/cryptoportfolio-app"
12 $cf_front_app_api_conf = "${home}/conf.toml"
13 $cf_front_app_api_secret = generate_password(24, $password_seed, "cryptoportfolio_api_secret")
14
15 $cf_front_app_static_conf = "${cf_front_app}/cmd/web/env/prod.env"
16
17 ensure_packages(["go", "npm", "nodejs", "yarn"])
18
19 file { [
20 "${home}/go/",
21 "${home}/go/src",
22 "${home}/go/src/immae.eu",
23 "${home}/go/src/immae.eu/Immae",
24 "${home}/go/src/immae.eu/Immae/Projets",
25 "${home}/go/src/immae.eu/Immae/Projets/Cryptomonnaies",
26 "${home}/go/src/immae.eu/Immae/Projets/Cryptomonnaies/Cryptoportfolio",
27 $cf_front_app]:
28 ensure => "directory",
29 mode => "0700",
30 owner => $user,
31 group => $group,
32 require => User["$user:"],
33 }
34
35 file { "${home}/front":
36 ensure => "link",
37 target => $cf_front_app,
38 before => File[$cf_front_app],
39 }
40
41 file { "/etc/systemd/system/cryptoportfolio-app.service":
42 mode => "0644",
43 owner => "root",
44 group => "root",
45 content => template("role/cryptoportfolio/cryptoportfolio-app.service.erb"),
46 notify => Exec["systemctl daemon-reload"],
47 }
48
49 service { 'cryptoportfolio-app':
50 enable => true,
51 ensure => "running",
52 subscribe => [File[$cf_front_app_api_conf], Exec["go-cryptoportfolio-app"], Exec["web-cryptoportfolio-build"]],
53 require => [
54 File["/etc/systemd/system/cryptoportfolio-app.service"],
55 Postgresql::Server::Db[$pg_db]
56 ],
57 } ~>
58 exec { "dump $pg_db structure":
59 refreshonly => true,
60 user => $::profile::postgresql::pg_user,
61 group => $::profile::postgresql::pg_user,
62 command => "/usr/bin/pg_dump --schema-only --clean --no-publications $pg_db > /var/lib/postgres/${pg_db}.schema",
63 }
64
65 archive { "${home}/front_${front_version}.tar.gz":
66 path => "${home}/front_${front_version}.tar.gz",
67 source => "https://git.immae.eu/releases/cryptoportfolio/front/front_${front_version}.tar.gz",
68 checksum_type => "sha256",
69 checksum => $front_sha256,
70 cleanup => false,
71 extract => true,
72 user => $user,
73 username => lookup("base_installation::ldap_cn"),
74 password => generate_password(24, $password_seed, "ldap"),
75 extract_path => $cf_front_app,
76 require => [User["$user:"], File[$cf_front_app]],
77 notify => [
78 Exec["web-cryptoportfolio-dependencies"],
79 Exec["go-get-dep"],
80 ]
81 }
82
83 # Api
84 $pg_password = generate_password(24, $password_seed, "postgres_cryptoportfolio")
85 $pg_host = "${pg_hostname}:${pg_port}"
86 file { $cf_front_app_api_conf:
87 owner => $user,
88 group => $group,
89 mode => "0600",
90 content => template("role/cryptoportfolio/api_conf.toml.erb"),
91 before => Exec["go-cryptoportfolio-app"],
92 }
93
94 exec { "go-get-dep":
95 user => $user,
96 environment => ["HOME=${home}"],
97 creates => "${home}/go/bin/dep",
98 command => "/usr/bin/go get -u github.com/golang/dep/cmd/dep",
99 refreshonly => true,
100 } ~>
101 exec { "go-cryptoportfolio-dependencies":
102 cwd => $cf_front_app,
103 user => $user,
104 environment => ["HOME=${home}"],
105 command => "${home}/go/bin/dep ensure",
106 refreshonly => true,
107 } ~>
108 exec { "go-cryptoportfolio-app":
109 cwd => $cf_front_app_api_workdir,
110 user => $user,
111 environment => ["HOME=${home}"],
112 command => "/usr/bin/make build",
113 refreshonly => true,
114 }
115
116 # Static pages
117 file { $cf_front_app_static_conf:
118 owner => $user,
119 group => $group,
120 mode => "0600",
121 content => template("role/cryptoportfolio/static_conf.env.erb"),
122 before => Exec["web-cryptoportfolio-build"],
123 }
124
125 exec { "web-cryptoportfolio-dependencies":
126 cwd => "${cf_front_app}/cmd/web",
127 user => $user,
128 environment => ["HOME=${home}"],
129 command => "/usr/bin/make install",
130 refreshonly => true,
131 require => [Package["npm"], Package["nodejs"], Package["yarn"]]
132 } ~>
133 exec { "web-cryptoportfolio-build":
134 cwd => "${cf_front_app}/cmd/web",
135 user => $user,
136 environment => ["HOME=${home}"],
137 path => ["${cf_front_app}/cmd/web/node_modules/.bin/", "/usr/bin"],
138 command => "/usr/bin/make static ENV=${env}",
139 refreshonly => true,
140 }
141
142 unless empty($webhook_url) {
143 exec { "front-slack-notify":
144 refreshonly => true,
145 environment => [
146 "P_PROJECT=Front",
147 "P_WEBHOOK=${webhook_url}",
148 "P_VERSION=${front_version}",
149 "P_HOST=${web_host}",
150 "P_HTTPS=${web_ssl}",
151 ],
152 command => "/usr/local/bin/slack-notify",
153 require => File["/usr/local/bin/slack-notify"],
154 subscribe => [Exec["go-cryptoportfolio-app"], Exec["web-cryptoportfolio-build"]],
155 }
156 }
157
158}