X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=modules%2Frole%2Fmanifests%2Fcryptoportfolio.pp;h=d2323a45bc0213f8fdd933e577c9db7f4a80975a;hb=e345248bd85980f6fefe7bc62251cc5b97f64854;hp=2755fee82934e133ba9715c6ce5fa9ab787bc388;hpb=ee0a29d96bbc401d97819e5723a083d33c32bb17;p=perso%2FImmae%2FProjets%2FPuppet.git diff --git a/modules/role/manifests/cryptoportfolio.pp b/modules/role/manifests/cryptoportfolio.pp index 2755fee..d2323a4 100644 --- a/modules/role/manifests/cryptoportfolio.pp +++ b/modules/role/manifests/cryptoportfolio.pp @@ -1,14 +1,194 @@ class role::cryptoportfolio { include "base_installation" + include "profile::tools" include "profile::postgresql" + include "profile::apache" $password_seed = lookup("base_installation::puppet_pass_seed") |$key| { {} } - postgresql::server::db { 'cryptoportfolio': - user => 'cryptoportfolio', - password => postgresql_password('cryptoportfolio', generate_password(24, $password_seed, "postgres_cryptoportfolio")), + $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", + } + + letsencrypt::certonly { $cf_front_app_host: ; + default: * => $::profile::apache::letsencrypt_certonly_default; + } + + class { 'apache::mod::headers': } + apache::vhost { $cf_front_app_host: + port => '443', + docroot => false, + manage_docroot => false, + proxy_dest => "http://localhost:8000", + request_headers => 'set X-Forwarded-Proto "https"', + ssl => true, + ssl_cert => "/etc/letsencrypt/live/$cf_front_app_host/cert.pem", + ssl_key => "/etc/letsencrypt/live/$cf_front_app_host/privkey.pem", + ssl_chain => "/etc/letsencrypt/live/$cf_front_app_host/chain.pem", + require => Letsencrypt::Certonly[$cf_front_app_host], + proxy_preserve_host => true; + default: * => $::profile::apache::apache_vhost_default; + } + + 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"]] + } } - ensure_packages("go") }