]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blobdiff - modules/role/manifests/cryptoportfolio.pp
Handle postgresql sockets for cryptoportfolio app
[perso/Immae/Projets/Puppet.git] / modules / role / manifests / cryptoportfolio.pp
index 084419edba70087b68640f0dbdf445b58c781f8a..5aaaee3579ac669a20b9ac593317186f38fea938 100644 (file)
-class role::cryptoportfolio {
+class role::cryptoportfolio (
+  String            $user,
+  String            $group,
+  String            $home,
+  Optional[String]  $env                 = "prod",
+  Optional[String]  $webhook_url         = undef,
+  String            $pg_user,
+  String            $pg_user_replication,
+  String            $pg_db,
+  Optional[String]  $pg_hostname          = "/run/postgresql",
+  Optional[String]  $pg_port              = "5432",
+  Optional[String]  $redis_host           = "/run/redis/redis.sock",
+  Optional[String]  $web_host             = undef,
+  Optional[String]  $web_port             = "",
+  Optional[Boolean] $web_ssl              = true,
+  Optional[String]  $front_version        = undef,
+  Optional[String]  $front_sha256         = undef,
+  Optional[String]  $trader_version       = undef,
+  Optional[String]  $trader_sha256        = undef,
+) {
   include "base_installation"
 
+  include "profile::tools"
   include "profile::postgresql"
   include "profile::apache"
+  include "profile::xmr_stak"
+  include "profile::boinc"
 
-  $password_seed = lookup("base_installation::puppet_pass_seed") |$key| { {} }
+  contain "role::cryptoportfolio::postgresql"
+  contain "role::cryptoportfolio::apache"
 
-  $cf_pg_user = "cryptoportfolio"
-  $cf_pg_db = "cryptoportfolio"
-  $cf_pg_password = generate_password(24, $password_seed, "postgres_cryptoportfolio")
-  $cf_pg_host = "localhost:5432"
+  contain "role::cryptoportfolio::notify"
 
-  $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   => '!!',
+  unless empty($trader_version) {
+    if versioncmp($trader_version, "v1.3") >= 0 {
+      include "profile::redis"
+    }
+    contain "role::cryptoportfolio::bot"
   }
 
-  $front_version = lookup("cryptoportfolio::front_version") |$key| { {} }
-  $front_sha256 = lookup("cryptoportfolio::front_sha256") |$key| { {} }
-
+  # FIXME: restore backup
   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"]]
-    }
+    contain "role::cryptoportfolio::front"
   }
-
 }