1 class role::cryptoportfolio {
2 include "base_installation"
4 include "profile::postgresql"
5 include "profile::apache"
7 $password_seed = lookup("base_installation::puppet_pass_seed") |$key| { {} }
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"
14 $cf_user = "cryptoportfolio"
15 $cf_group = "cryptoportfolio"
16 $cf_home = "/opt/cryptoportfolio"
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")
27 $cf_front_app_static_conf = "${cf_front_app}/cmd/web/env/prod.env"
29 postgresql::server::db { $cf_pg_db:
31 password => postgresql_password($cf_pg_user, $cf_pg_password)
34 postgresql::server::pg_hba_rule { 'allow localhost TCP access to cryptoportfolio user':
36 database => $cf_pg_db,
38 address => '127.0.0.1/32',
42 postgresql::server::pg_hba_rule { 'allow localhost ip6 TCP access to cryptoportfolio user':
44 database => $cf_pg_db,
51 apache::vhost { $cf_front_app_host:
54 manage_docroot => false,
55 proxy_dest => "http://localhost:8000",
56 proxy_preserve_host => true,
58 "/maintenance_immae.html",
59 "/googleb6d69446ff4ca3e5.html",
60 "/.well-known/acme-challenge"
62 no_proxy_uris_match => [
63 '^/licen[cs]es?_et_tip(ping)?$',
64 '^/licen[cs]es?_and_tip(ping)?$',
79 $front_version = lookup("cryptoportfolio::front_version") |$key| { {} }
80 $front_sha256 = lookup("cryptoportfolio::front_sha256") |$key| { {} }
82 unless empty($front_version) {
83 ensure_packages(["go", "npm", "nodejs", "yarn"])
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",
94 ensure => "directory",
98 require => User[$cf_user],
101 archive { "${cf_home}/${front_version}.tar.gz":
102 path => "${cf_home}/${front_version}.tar.gz",
103 source => "https://git.immae.eu/releases/cryptoportfolio/front/front_${front_version}.tar.gz",
104 checksum_type => "sha256",
105 checksum => $front_sha256,
108 user => "cryptoportfolio",
109 extract_path => $cf_front_app,
110 require => [User[$cf_user], File[$cf_front_app]],
113 file { "${cf_home}/front":
115 target => $cf_front_app,
116 require => Archive["/opt/cryptoportfolio/${front_version}.tar.gz"]
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],
127 exec { "go-cryptoportfolio-dependencies":
128 cwd => $cf_front_app,
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"]],
136 exec { "go-cryptoportfolio-app":
137 cwd => $cf_front_app_api_workdir,
139 environment => ["HOME=${cf_home}"],
140 creates => $cf_front_app_api_bin,
141 command => "/usr/bin/make build",
142 require => Exec["go-cryptoportfolio-dependencies"],
145 file { "/etc/systemd/system/cryptoportfolio-app.service":
149 content => template("role/cryptoportfolio/cryptoportfolio-app.service.erb"),
150 } ~> exec { 'systemctl deamon-reload':
151 command => '/usr/bin/systemctl daemon-reload',
155 service { 'cryptoportfolio-app':
158 require => [File["/etc/systemd/system/cryptoportfolio-app.service"]],
161 file { $cf_front_app_api_conf:
165 content => template("role/cryptoportfolio/api_conf.toml.erb"),
168 file { $cf_front_app_static_conf:
172 content => template("role/cryptoportfolio/static_conf.env.erb"),
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"]]
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"]]