]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blame_incremental - modules/role/manifests/cryptoportfolio/front.pp
Merge branch 'dev'
[perso/Immae/Projets/Puppet.git] / modules / role / manifests / cryptoportfolio / front.pp
... / ...
CommitLineData
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_password_reset_secret = generate_password(24, $password_seed, "cryptoportfolio_api_password_reset_secret")
16 $cf_front_app_free_sms_user = lookup("role::cryptoportfolio::front::free_sms_user")
17 $cf_front_app_free_sms_pass = lookup("role::cryptoportfolio::front::free_sms_pass")
18
19 $cf_front_app_static_conf = "${cf_front_app}/cmd/web/env/prod.env"
20
21 ensure_packages(["go", "npm", "nodejs", "yarn"])
22
23 file { [
24 "${home}/go/",
25 "${home}/go/src",
26 "${home}/go/src/immae.eu",
27 "${home}/go/src/immae.eu/Immae",
28 "${home}/go/src/immae.eu/Immae/Projets",
29 "${home}/go/src/immae.eu/Immae/Projets/Cryptomonnaies",
30 "${home}/go/src/immae.eu/Immae/Projets/Cryptomonnaies/Cryptoportfolio",
31 $cf_front_app]:
32 ensure => "directory",
33 mode => "0700",
34 owner => $user,
35 group => $group,
36 require => User["$user:"],
37 }
38
39 file { "${home}/front":
40 ensure => "link",
41 target => $cf_front_app,
42 before => File[$cf_front_app],
43 }
44
45 file { "/etc/systemd/system/cryptoportfolio-app.service":
46 mode => "0644",
47 owner => "root",
48 group => "root",
49 content => template("role/cryptoportfolio/cryptoportfolio-app.service.erb"),
50 notify => Exec["systemctl daemon-reload"],
51 }
52
53 service { 'cryptoportfolio-app':
54 enable => true,
55 ensure => "running",
56 subscribe => [File[$cf_front_app_api_conf], Exec["go-cryptoportfolio-app"], Exec["web-cryptoportfolio-build"]],
57 require => [
58 File["/etc/systemd/system/cryptoportfolio-app.service"],
59 Postgresql::Server::Db[$pg_db]
60 ],
61 } ~>
62 exec { "dump $pg_db structure":
63 refreshonly => true,
64 user => $::profile::postgresql::pg_user,
65 group => $::profile::postgresql::pg_user,
66 command => "/usr/bin/pg_dump --schema-only --clean --no-publications $pg_db > /var/lib/postgres/${pg_db}.schema",
67 }
68
69 archive { "${home}/front_${front_version}.tar.gz":
70 path => "${home}/front_${front_version}.tar.gz",
71 source => "https://git.immae.eu/releases/cryptoportfolio/front/front_${front_version}.tar.gz",
72 checksum_type => "sha256",
73 checksum => $front_sha256,
74 cleanup => false,
75 extract => true,
76 user => $user,
77 username => lookup("base_installation::ldap_cn"),
78 password => generate_password(24, $password_seed, "ldap"),
79 extract_path => $cf_front_app,
80 require => [User["$user:"], File[$cf_front_app]],
81 notify => [
82 Exec["web-cryptoportfolio-dependencies"],
83 Exec["go-get-dep"],
84 ]
85 }
86
87 # Api
88 $pg_password = generate_password(24, $password_seed, "postgres_cryptoportfolio")
89 $pg_host = "${pg_hostname}:${pg_port}"
90 file { $cf_front_app_api_conf:
91 owner => $user,
92 group => $group,
93 mode => "0600",
94 content => template("role/cryptoportfolio/api_conf.toml.erb"),
95 before => Exec["go-cryptoportfolio-app"],
96 }
97
98 exec { "go-get-dep":
99 user => $user,
100 environment => ["HOME=${home}"],
101 creates => "${home}/go/bin/dep",
102 command => "/usr/bin/go get -u github.com/golang/dep/cmd/dep",
103 refreshonly => true,
104 } ~>
105 exec { "go-cryptoportfolio-dependencies":
106 cwd => $cf_front_app,
107 user => $user,
108 environment => ["HOME=${home}"],
109 command => "${home}/go/bin/dep ensure",
110 refreshonly => true,
111 } ~>
112 exec { "go-cryptoportfolio-app":
113 cwd => $cf_front_app_api_workdir,
114 user => $user,
115 environment => ["HOME=${home}"],
116 command => "/usr/bin/make build",
117 refreshonly => true,
118 }
119
120 # Static pages
121 file { $cf_front_app_static_conf:
122 owner => $user,
123 group => $group,
124 mode => "0600",
125 content => template("role/cryptoportfolio/static_conf.env.erb"),
126 before => Exec["web-cryptoportfolio-build"],
127 }
128
129 exec { "web-cryptoportfolio-dependencies":
130 cwd => "${cf_front_app}/cmd/web",
131 user => $user,
132 environment => ["HOME=${home}"],
133 command => "/usr/bin/make install",
134 refreshonly => true,
135 require => [Package["npm"], Package["nodejs"], Package["yarn"]]
136 } ~>
137 exec { "web-cryptoportfolio-build":
138 cwd => "${cf_front_app}/cmd/web",
139 user => $user,
140 environment => ["HOME=${home}"],
141 path => ["${cf_front_app}/cmd/web/node_modules/.bin/", "/usr/bin"],
142 command => "/usr/bin/make static ENV=${env}",
143 refreshonly => true,
144 }
145
146 # Slack logger
147 $slack_logger = lookup("role::cryptoportfolio::front::slack_logger")
148 $slack_logger_username = lookup("role::cryptoportfolio::front::slack_logger_username", { "default_value" => "Logger" })
149
150 unless empty($slack_logger) {
151 file { "/usr/local/bin/api_logger":
152 mode => "0755",
153 content => template("role/cryptoportfolio/api_logger.py.erb"),
154 notify => Service["cryptoportfolio-log"],
155 }
156 ->
157 file { "/etc/systemd/system/cryptoportfolio-log.service":
158 mode => "0644",
159 owner => "root",
160 group => "root",
161 content => template("role/cryptoportfolio/cryptoportfolio-log.service.erb"),
162 notify => [
163 Exec["systemctl daemon-reload"],
164 Service["cryptoportfolio-log"]
165 ]
166 }
167 ->
168 service { 'cryptoportfolio-log':
169 enable => true,
170 ensure => "running",
171 require => [
172 Service["cryptoportfolio-app"],
173 ],
174 }
175 }
176
177 unless empty($webhook_url) {
178 exec { "front-slack-notify":
179 refreshonly => true,
180 environment => [
181 "P_PROJECT=Front",
182 "P_WEBHOOK=${webhook_url}",
183 "P_VERSION=${front_version}",
184 "P_HOST=${web_host}",
185 "P_HTTPS=${web_ssl}",
186 ],
187 command => "/usr/local/bin/slack-notify",
188 require => File["/usr/local/bin/slack-notify"],
189 subscribe => [Exec["go-cryptoportfolio-app"], Exec["web-cryptoportfolio-build"]],
190 }
191 }
192
193}