From 0a4ec3790f89873bf37a1362a6f7e70b103e9bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 18 Feb 2018 12:20:24 +0100 Subject: Add nginx --- modules/nginx | 1 + modules/role/manifests/cryptoportfolio.pp | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 160000 modules/nginx (limited to 'modules') diff --git a/modules/nginx b/modules/nginx new file mode 160000 index 0000000..a7f40a8 --- /dev/null +++ b/modules/nginx @@ -0,0 +1 @@ +Subproject commit a7f40a8893e394cc57695ff81ea53254bcf1ff3a diff --git a/modules/role/manifests/cryptoportfolio.pp b/modules/role/manifests/cryptoportfolio.pp index 4b03e16..16c2f96 100644 --- a/modules/role/manifests/cryptoportfolio.pp +++ b/modules/role/manifests/cryptoportfolio.pp @@ -26,5 +26,13 @@ class role::cryptoportfolio { auth_method => 'md5', order => "b0", } + ensure_packages("go") + + class { 'nginx': } + + nginx::resource::server { 'cryptoportfolio.immae.eu': + listen_port => 80, + proxy => 'http://localhost:8000', + } } -- cgit v1.2.3 From f67c5285ae3847366129228576a1b41aad7cf05d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 18 Feb 2018 12:29:12 +0100 Subject: Add missing packages --- modules/role/manifests/cryptoportfolio.pp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/role/manifests/cryptoportfolio.pp b/modules/role/manifests/cryptoportfolio.pp index 16c2f96..4643f9e 100644 --- a/modules/role/manifests/cryptoportfolio.pp +++ b/modules/role/manifests/cryptoportfolio.pp @@ -27,12 +27,12 @@ class role::cryptoportfolio { order => "b0", } - ensure_packages("go") - class { 'nginx': } nginx::resource::server { 'cryptoportfolio.immae.eu': listen_port => 80, proxy => 'http://localhost:8000', } + + ensure_packages(["go", "npm", "nodejs", "yarn"]) } -- cgit v1.2.3 From 76a321e1b7da9f122f35a9722d9f8f331b06f8aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 18 Feb 2018 15:02:03 +0100 Subject: Create cryptoportfolio user --- modules/archive | 1 + modules/role/manifests/cryptoportfolio.pp | 48 +++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 160000 modules/archive (limited to 'modules') diff --git a/modules/archive b/modules/archive new file mode 160000 index 0000000..9af5cad --- /dev/null +++ b/modules/archive @@ -0,0 +1 @@ +Subproject commit 9af5cad2bbaafe0498032c38a37835e4ccba7d22 diff --git a/modules/role/manifests/cryptoportfolio.pp b/modules/role/manifests/cryptoportfolio.pp index 4643f9e..046b79e 100644 --- a/modules/role/manifests/cryptoportfolio.pp +++ b/modules/role/manifests/cryptoportfolio.pp @@ -35,4 +35,52 @@ class role::cryptoportfolio { } ensure_packages(["go", "npm", "nodejs", "yarn"]) + + user { "cryptoportfolio": + name => "cryptoportfolio", + ensure => "present", + managehome => true, + home => "/opt/cryptoportfolio", + system => true, + password => '!!', + } + + $front_version = lookup("cryptoportfolio::front_version") |$key| { {} } + $front_sha256 = lookup("cryptoportfolio::front_sha256") |$key| { {} } + + unless empty($front_version) { + file { "/opt/cryptoportfolio/front": + ensure => directory, + mode => "0700", + owner => "cryptoportfolio", + group => "cryptoportfolio", + } + + file { "/opt/cryptoportfolio/front/${front_version}": + ensure => directory, + mode => "0700", + owner => "cryptoportfolio", + group => "cryptoportfolio", + require => File["/opt/cryptoportfolio/front"], + } + + archive { "/opt/cryptoportfolio/front/${front_version}.tar.gz": + path => "/opt/cryptoportfolio/front/${front_version}.tar.gz", + source => "https://git.immae.eu/releases/cryptoportfolio/front/front_${front_version}.tar.gz", + creates => "/opt/cryptoportfolio/front/${front_version}/README.md", + checksum_type => "sha256", + checksum => $front_sha256, + cleanup => false, + extract => true, + extract_path => "/opt/cryptoportfolio/front/${front_version}", + require => File["/opt/cryptoportfolio/front/${front_version}"], + } + + file { "/opt/cryptoportfolio/front/current": + ensure => "link", + target => "/opt/cryptoportfolio/front/${front_version}", + require => Archive["/opt/cryptoportfolio/front/${front_version}.tar.gz"] + } + } + } -- cgit v1.2.3 From 1dca26e507d12b9a38e8740e2c310c8bee4e173c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 18 Feb 2018 15:32:21 +0100 Subject: Fix aura packager --- modules/aur/manifests/aura.pp | 4 ++++ modules/aur/manifests/package.pp | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/aur/manifests/aura.pp b/modules/aur/manifests/aura.pp index 1683cf8..3e06f0a 100644 --- a/modules/aur/manifests/aura.pp +++ b/modules/aur/manifests/aura.pp @@ -6,6 +6,10 @@ class aur::aura( ensure => "present" } + sudo::conf { 'aur-builder': + content => "aur-builder ALL=(root) NOPASSWD: /usr/bin/aura *" + } + ensure_packages(['base-devel'], { 'install_options' => '--needed' }) ensure_packages(['gmp', 'pcre'], { 'install_options' => '--asdeps' }) diff --git a/modules/aur/manifests/package.pp b/modules/aur/manifests/package.pp index 2fd346e..5b55f24 100644 --- a/modules/aur/manifests/package.pp +++ b/modules/aur/manifests/package.pp @@ -7,7 +7,7 @@ define aur::package ( exec { "pacman::aur::install::${name}": cwd => "/tmp", require => Class[aur::aura], - command => "/usr/bin/aura -A ${name}", + command => "/usr/bin/sudo /usr/bin/aura --noconfirm -A ${name}", user => "aur-builder", unless => "/usr/bin/aura -Qk ${name}", logoutput => 'on_failure', @@ -18,7 +18,7 @@ define aur::package ( exec { "pacman::aur::remove::${name}": cwd => "/tmp", require => Class[aur::aura], - command => "/usr/bin/aura -Rs ${name}", + command => "/usr/bin/sudo /usr/bin/aura --noconfirm -Rs ${name}", user => "aur-builder", onlyif => "/usr/bin/aura -Qi ${name}", logoutput => 'on_failure', -- cgit v1.2.3 From 159df176f990fd1f819efcfd431677b78f367697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 18 Feb 2018 15:30:02 +0100 Subject: Install and configure api and assets --- modules/role/manifests/cryptoportfolio.pp | 157 ++++++++++++++++----- .../templates/cryptoportfolio/api_conf.toml.erb | 16 +++ .../cryptoportfolio-app.service.erb | 14 ++ .../templates/cryptoportfolio/static_conf.env.erb | 4 + 4 files changed, 159 insertions(+), 32 deletions(-) create mode 100644 modules/role/templates/cryptoportfolio/api_conf.toml.erb create mode 100644 modules/role/templates/cryptoportfolio/cryptoportfolio-app.service.erb create mode 100644 modules/role/templates/cryptoportfolio/static_conf.env.erb (limited to 'modules') diff --git a/modules/role/manifests/cryptoportfolio.pp b/modules/role/manifests/cryptoportfolio.pp index 046b79e..0f26527 100644 --- a/modules/role/manifests/cryptoportfolio.pp +++ b/modules/role/manifests/cryptoportfolio.pp @@ -5,23 +5,43 @@ class role::cryptoportfolio { $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 => 'cryptoportfolio', - user => 'cryptoportfolio', + 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 => 'cryptoportfolio', - user => 'cryptoportfolio', + database => $cf_pg_db, + user => $cf_pg_user, address => '::1/128', auth_method => 'md5', order => "b0", @@ -29,18 +49,16 @@ class role::cryptoportfolio { class { 'nginx': } - nginx::resource::server { 'cryptoportfolio.immae.eu': + nginx::resource::server { $cf_front_app_host: listen_port => 80, proxy => 'http://localhost:8000', } - ensure_packages(["go", "npm", "nodejs", "yarn"]) - - user { "cryptoportfolio": - name => "cryptoportfolio", + user { $cf_user: + name => $cf_user, ensure => "present", managehome => true, - home => "/opt/cryptoportfolio", + home => $cf_home, system => true, password => '!!', } @@ -49,37 +67,112 @@ class role::cryptoportfolio { $front_sha256 = lookup("cryptoportfolio::front_sha256") |$key| { {} } unless empty($front_version) { - file { "/opt/cryptoportfolio/front": - ensure => directory, - mode => "0700", - owner => "cryptoportfolio", - group => "cryptoportfolio", - } + ensure_packages(["go", "npm", "nodejs", "yarn"]) - file { "/opt/cryptoportfolio/front/${front_version}": - ensure => directory, + 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 => "cryptoportfolio", - group => "cryptoportfolio", - require => File["/opt/cryptoportfolio/front"], + owner => $cf_user, + group => $cf_group, + require => User[$cf_user], } - archive { "/opt/cryptoportfolio/front/${front_version}.tar.gz": - path => "/opt/cryptoportfolio/front/${front_version}.tar.gz", + 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", - creates => "/opt/cryptoportfolio/front/${front_version}/README.md", checksum_type => "sha256", checksum => $front_sha256, cleanup => false, extract => true, - extract_path => "/opt/cryptoportfolio/front/${front_version}", - require => File["/opt/cryptoportfolio/front/${front_version}"], + user => "cryptoportfolio", + extract_path => $cf_front_app, + require => [User[$cf_user], File[$cf_front_app]], } - file { "/opt/cryptoportfolio/front/current": + file { "${cf_home}/front": ensure => "link", - target => "/opt/cryptoportfolio/front/${front_version}", - require => Archive["/opt/cryptoportfolio/front/${front_version}.tar.gz"] + 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"]] } } diff --git a/modules/role/templates/cryptoportfolio/api_conf.toml.erb b/modules/role/templates/cryptoportfolio/api_conf.toml.erb new file mode 100644 index 0000000..13550c9 --- /dev/null +++ b/modules/role/templates/cryptoportfolio/api_conf.toml.erb @@ -0,0 +1,16 @@ +log_level="info" +mode="<%= @cf_env %>" +log_out="stdout" + +[db] +user="<%= @cf_pg_user %>" +password="<%= @cf_pg_password %>" +database="<%= @cf_pg_db %>" +address="<%= @cf_pg_host %>" + +[api] +domain="<%= @cf_front_app_host %>" +jwt_secret="<%= @cf_front_app_api_secret %>" + +[app] +public_dir="../web/build/static" diff --git a/modules/role/templates/cryptoportfolio/cryptoportfolio-app.service.erb b/modules/role/templates/cryptoportfolio/cryptoportfolio-app.service.erb new file mode 100644 index 0000000..a521c0e --- /dev/null +++ b/modules/role/templates/cryptoportfolio/cryptoportfolio-app.service.erb @@ -0,0 +1,14 @@ +[Unit] +Description=Cryptoportfolio app + +[Service] +Type=simple + +WorkingDirectory=<%= @cf_front_app_api_workdir %> +User=<%= @cf_user %> +Group=<%= @cf_group %> +UMask=007 + +ExecStart=<%= @cf_front_app_api_bin %> -conf <%= @cf_front_app_api_conf %> + +Restart=on-failure diff --git a/modules/role/templates/cryptoportfolio/static_conf.env.erb b/modules/role/templates/cryptoportfolio/static_conf.env.erb new file mode 100644 index 0000000..db9759d --- /dev/null +++ b/modules/role/templates/cryptoportfolio/static_conf.env.erb @@ -0,0 +1,4 @@ +API_HOST="<%= @cf_front_app_host %>" +API_PORT="<%= @cf_front_app_port %>" +API_HTTPS="<%= @cf_front_app_ssl %>" + -- cgit v1.2.3