]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blame - modules/role/manifests/cryptoportfolio.pp
Migrate to apache
[perso/Immae/Projets/Puppet.git] / modules / role / manifests / cryptoportfolio.pp
CommitLineData
57ae81ea
IB
1class role::cryptoportfolio {
2 include "base_installation"
3
4 include "profile::postgresql"
2bb35074 5 include "profile::apache"
57ae81ea
IB
6
7 $password_seed = lookup("base_installation::puppet_pass_seed") |$key| { {} }
8
159df176
IB
9 $cf_pg_user = "cryptoportfolio"
10 $cf_pg_db = "cryptoportfolio"
11 $cf_pg_password = generate_password(24, $password_seed, "postgres_cryptoportfolio")
12 $cf_pg_host = "localhost:5432"
13
14 $cf_user = "cryptoportfolio"
15 $cf_group = "cryptoportfolio"
16 $cf_home = "/opt/cryptoportfolio"
17 $cf_env = "prod"
18 $cf_front_app_host = "cryptoportfolio.immae.eu"
19 $cf_front_app_port = ""
20 $cf_front_app_ssl = "false"
21 $cf_front_app = "${cf_home}/go/src/immae.eu/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front"
22 $cf_front_app_api_workdir = "${cf_front_app}/cmd/app"
23 $cf_front_app_api_bin = "${cf_front_app_api_workdir}/cryptoportfolio-app"
24 $cf_front_app_api_conf = "${cf_home}/conf.toml"
25 $cf_front_app_api_secret = generate_password(24, $password_seed, "cryptoportfolio_api_secret")
26
27 $cf_front_app_static_conf = "${cf_front_app}/cmd/web/env/prod.env"
28
29 postgresql::server::db { $cf_pg_db:
30 user => $cf_pg_user,
31 password => postgresql_password($cf_pg_user, $cf_pg_password)
57ae81ea
IB
32 }
33
6a919776
IB
34 postgresql::server::pg_hba_rule { 'allow localhost TCP access to cryptoportfolio user':
35 type => 'host',
159df176
IB
36 database => $cf_pg_db,
37 user => $cf_pg_user,
6a919776
IB
38 address => '127.0.0.1/32',
39 auth_method => 'md5',
40 order => "b0",
41 }
42 postgresql::server::pg_hba_rule { 'allow localhost ip6 TCP access to cryptoportfolio user':
43 type => 'host',
159df176
IB
44 database => $cf_pg_db,
45 user => $cf_pg_user,
6a919776
IB
46 address => '::1/128',
47 auth_method => 'md5',
48 order => "b0",
49 }
0a4ec379 50
2bb35074
IB
51 apache::vhost { $cf_front_app_host:
52 port => '80',
53 docroot => false,
54 manage_docroot => false,
55 proxy_dest => "http://localhost:8000",
56 proxy_preserve_host => true,
57 no_proxy_uris => [
58 "/maintenance_immae.html",
59 "/googleb6d69446ff4ca3e5.html",
60 "/.well-known/acme-challenge"
61 ],
62 no_proxy_uris_match => [
63 '^/licen[cs]es?_et_tip(ping)?$',
64 '^/licen[cs]es?_and_tip(ping)?$',
65 '^/licen[cs]es?$',
66 '^/tip(ping)?$',
67 ]
0a4ec379 68 }
f67c5285 69
159df176
IB
70 user { $cf_user:
71 name => $cf_user,
76a321e1
IB
72 ensure => "present",
73 managehome => true,
159df176 74 home => $cf_home,
76a321e1
IB
75 system => true,
76 password => '!!',
77 }
78
79 $front_version = lookup("cryptoportfolio::front_version") |$key| { {} }
80 $front_sha256 = lookup("cryptoportfolio::front_sha256") |$key| { {} }
81
82 unless empty($front_version) {
159df176 83 ensure_packages(["go", "npm", "nodejs", "yarn"])
76a321e1 84
159df176
IB
85 file { [
86 "${cf_home}/go/",
87 "${cf_home}/go/src",
88 "${cf_home}/go/src/immae.eu",
89 "${cf_home}/go/src/immae.eu/Immae",
90 "${cf_home}/go/src/immae.eu/Immae/Projets",
91 "${cf_home}/go/src/immae.eu/Immae/Projets/Cryptomonnaies",
92 "${cf_home}/go/src/immae.eu/Immae/Projets/Cryptomonnaies/Cryptoportfolio",
93 $cf_front_app]:
94 ensure => "directory",
76a321e1 95 mode => "0700",
159df176
IB
96 owner => $cf_user,
97 group => $cf_group,
98 require => User[$cf_user],
76a321e1
IB
99 }
100
159df176
IB
101 archive { "${cf_home}/${front_version}.tar.gz":
102 path => "${cf_home}/${front_version}.tar.gz",
76a321e1 103 source => "https://git.immae.eu/releases/cryptoportfolio/front/front_${front_version}.tar.gz",
76a321e1
IB
104 checksum_type => "sha256",
105 checksum => $front_sha256,
106 cleanup => false,
107 extract => true,
159df176
IB
108 user => "cryptoportfolio",
109 extract_path => $cf_front_app,
110 require => [User[$cf_user], File[$cf_front_app]],
76a321e1
IB
111 }
112
159df176 113 file { "${cf_home}/front":
76a321e1 114 ensure => "link",
159df176
IB
115 target => $cf_front_app,
116 require => Archive["/opt/cryptoportfolio/${front_version}.tar.gz"]
117 }
118
119 exec { "go-get-dep":
120 user => $cf_user,
121 environment => ["HOME=${cf_home}"],
122 creates => "${cf_home}/go/bin/dep",
123 command => "/usr/bin/go get -u github.com/golang/dep/cmd/dep",
124 require => User[$cf_user],
125 }
126
127 exec { "go-cryptoportfolio-dependencies":
128 cwd => $cf_front_app,
129 user => $cf_user,
130 environment => ["HOME=${cf_home}"],
131 creates => "${cf_front_app}/vendor",
132 command => "${cf_home}/go/bin/dep ensure",
133 require => [Exec["go-get-dep"], Archive["${cf_home}/${front_version}.tar.gz"]],
134 }
135
136 exec { "go-cryptoportfolio-app":
137 cwd => $cf_front_app_api_workdir,
138 user => $cf_user,
139 environment => ["HOME=${cf_home}"],
140 creates => $cf_front_app_api_bin,
141 command => "/usr/bin/make build",
142 require => Exec["go-cryptoportfolio-dependencies"],
143 }
144
145 file { "/etc/systemd/system/cryptoportfolio-app.service":
146 mode => "0644",
147 owner => "root",
148 group => "root",
149 content => template("role/cryptoportfolio/cryptoportfolio-app.service.erb"),
150 } ~> exec { 'systemctl deamon-reload':
151 command => '/usr/bin/systemctl daemon-reload',
152 refreshonly => true
153 }
154
155 service { 'cryptoportfolio-app':
156 enable => true,
157 ensure => "running",
158 require => [File["/etc/systemd/system/cryptoportfolio-app.service"]],
159 }
160
161 file { $cf_front_app_api_conf:
162 owner => $cf_user,
163 group => $cf_group,
164 mode => "0600",
165 content => template("role/cryptoportfolio/api_conf.toml.erb"),
166 }
167
168 file { $cf_front_app_static_conf:
169 owner => $cf_user,
170 group => $cf_group,
171 mode => "0600",
172 content => template("role/cryptoportfolio/static_conf.env.erb"),
173 }
174
175 exec { "web-cryptoportfolio-dependencies":
176 cwd => "${cf_front_app}/cmd/web",
177 environment => ["HOME=${cf_home}"],
178 command => "/usr/bin/make install",
179 creates => "${cf_front_app}/cmd/web/node_modules",
180 require => [Package["npm"], Package["nodejs"], Package["yarn"]]
181 }
182
183 exec { "web-cryptoportfolio-build":
184 cwd => "${cf_front_app}/cmd/web",
185 environment => ["HOME=${cf_home}"],
186 command => "/usr/bin/make static ENV=${cf_env}",
187 creates => "${cf_front_app}/cmd/web/build/static",
188 require => [File[$cf_front_app_static_conf], Exec["web-cryptoportfolio-dependencies"]]
76a321e1
IB
189 }
190 }
191
57ae81ea 192}