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