]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blobdiff - modules/role/manifests/cryptoportfolio.pp
Rename archive files
[perso/Immae/Projets/Puppet.git] / modules / role / manifests / cryptoportfolio.pp
index ee1c74f10f36a06a0d0ca71a00d462e09b7dfb24..5fb0438956091c9420f3d9878c947c1bad25edb0 100644 (file)
@@ -26,7 +26,7 @@ class role::cryptoportfolio {
   $cf_group = "cryptoportfolio"
   $cf_home = "/opt/cryptoportfolio"
   $cf_env = "prod"
-  $cf_front_app_host = "cryptoportfolio.immae.eu"
+  $cf_front_app_host = lookup("base_installation::system_hostname") |$key| { "example.com" }
   $cf_front_app_port = ""
   $cf_front_app_ssl = "true"
   $cf_front_app = "${cf_home}/go/src/immae.eu/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front"
@@ -196,8 +196,8 @@ class role::cryptoportfolio {
       require => User[$cf_user],
     }
 
-    archive { "${cf_home}/${bot_version}.tar.gz":
-      path          => "${cf_home}/${bot_version}.tar.gz",
+    archive { "${cf_home}/trader_${bot_version}.tar.gz":
+      path          => "${cf_home}/trader_${bot_version}.tar.gz",
       source        => "https://git.immae.eu/releases/cryptoportfolio/trader/trader_${bot_version}.tar.gz",
       checksum_type => "sha256",
       checksum      => $bot_sha256,
@@ -227,7 +227,11 @@ class role::cryptoportfolio {
       owner   => $cf_user,
       group   => $cf_group,
       mode    => "0600",
-      content => template("role/cryptoportfolio/bot_config.ini.erb")
+      content => template("role/cryptoportfolio/bot_config.ini.erb"),
+      require => [
+        User[$cf_user],
+        Archive["${cf_home}/trader_${bot_version}.tar.gz"],
+      ],
     }
 
     cron { "py-cryptoportfolio-before":
@@ -240,7 +244,7 @@ class role::cryptoportfolio {
       environment => ["HOME=${cf_home}","PATH=/usr/bin/"],
       require     => [
         File[$cf_bot_app_conf],
-        Archive["${cf_home}/${bot_version}.tar.gz"]
+        Archive["${cf_home}/trader_${bot_version}.tar.gz"]
       ],
     }
 
@@ -250,14 +254,16 @@ class role::cryptoportfolio {
       user        => "cryptoportfolio",
       weekday     => 1, # Monday
       hour        => 1,
+      minute      => 0,
       environment => ["HOME=${cf_home}","PATH=/usr/bin/"],
       require     => [
         File[$cf_bot_app_conf],
-        Archive["${cf_home}/${bot_version}.tar.gz"]
+        Archive["${cf_home}/trader_${bot_version}.tar.gz"]
       ],
     }
   }
 
+  # FIXME: restore backup
   unless empty($front_version) {
     ensure_packages(["go", "npm", "nodejs", "yarn"])
 
@@ -277,56 +283,10 @@ class role::cryptoportfolio {
       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",
-      username      => $facts["ec2_metadata"]["hostname"],
-      password      => generate_password(24, $password_seed, "ldap"),
-      extract_path  => $cf_front_app,
-      require       => [User[$cf_user], File[$cf_front_app]],
-    }
-
     file { "${cf_home}/front":
       ensure  => "link",
       target  => $cf_front_app,
       before => File[$cf_front_app],
-    } ~>
-    exec { "remove old ${cf_front_app} directory":
-      refreshonly => true,
-      user        => $cf_user,
-      command     => "/usr/bin/rm -rf ${cf_front_app}",
-      before      => File[$cf_front_app],
-    }
-
-    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":
@@ -353,43 +313,77 @@ class role::cryptoportfolio {
       command     => "/usr/bin/pg_dump --schema-only --clean --no-publications $cf_pg_db > /var/lib/postgres/${cf_pg_db}.schema",
     }
 
+    archive { "${cf_home}/front_${front_version}.tar.gz":
+      path          => "${cf_home}/front_${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          => $cf_user,
+      username      => $facts["ec2_metadata"]["hostname"],
+      password      => generate_password(24, $password_seed, "ldap"),
+      extract_path  => $cf_front_app,
+      require       => [User[$cf_user], File[$cf_front_app]],
+      notify        => [
+        Exec["web-cryptoportfolio-dependencies"],
+        Exec["go-get-dep"],
+      ]
+    }
+
+    # Api
     file { $cf_front_app_api_conf:
       owner   => $cf_user,
       group   => $cf_group,
       mode    => "0600",
       content => template("role/cryptoportfolio/api_conf.toml.erb"),
+      before  => Exec["go-cryptoportfolio-app"],
+    }
+
+    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",
+      refreshonly => true,
+    } ~>
+    exec { "go-cryptoportfolio-dependencies":
+      cwd         => $cf_front_app,
+      user        => $cf_user,
+      environment => ["HOME=${cf_home}"],
+      command     => "${cf_home}/go/bin/dep ensure",
+      refreshonly => true,
+    } ~>
+    exec { "go-cryptoportfolio-app":
+      cwd         => $cf_front_app_api_workdir,
+      user        => $cf_user,
+      environment => ["HOME=${cf_home}"],
+      command     => "/usr/bin/make build",
+      refreshonly => true,
     }
 
+    # Static pages
     file { $cf_front_app_static_conf:
       owner   => $cf_user,
       group   => $cf_group,
       mode    => "0600",
       content => template("role/cryptoportfolio/static_conf.env.erb"),
-      notify  => Exec["remove build ${cf_front_app}/cmd/web/build/"],
+      before  => Exec["web-cryptoportfolio-build"],
     }
 
     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",
-      notify      => Exec["remove build ${cf_front_app}/cmd/web/build/"],
-      require     => [Package["npm"], Package["nodejs"], Package["yarn"]]
-    }
-
-    exec { "remove build ${cf_front_app}/cmd/web/build/":
-      command     => "/usr/bin/rm -rf '${cf_front_app}/cmd/web/build/'",
       refreshonly => true,
-      before      => Exec["web-cryptoportfolio-build"]
-    }
-
+      require     => [Package["npm"], Package["nodejs"], Package["yarn"]]
+    } ~>
     exec { "web-cryptoportfolio-build":
       cwd         => "${cf_front_app}/cmd/web",
       environment => ["HOME=${cf_home}"],
       path        => ["${cf_front_app}/cmd/web/node_modules/.bin/", "/usr/bin"],
       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"]]
+      refreshonly => true,
     }
   }
 }