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