From 85abd2fdbad83430df4824843764719064afb9b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sat, 3 Mar 2018 22:24:19 +0100 Subject: Fetch node informations from LDAP environment, hostname --- bin/install_script.sh | 12 ++++++-- environments/integration/data/common.yaml | 25 ++++++++++++++++ .../integration/data/roles/cryptoportfolio.yaml | 7 +++++ .../integration/data/types/vps-ovhssd-1.yaml | 10 +++++++ environments/integration/hiera.yaml | 19 ++++++++++++ .../production/data/nodes/vps464408.novalocal.yaml | 1 - environments/production/data/nodes/vps494082.yaml | 5 ---- .../production/data/roles/cryptoportfolio.yaml | 4 +++ .../production/data/types/vps-ovhssd-1.yaml | 1 + environments/production/hiera.yaml | 9 ------ modules/base_installation/manifests/init.pp | 1 + modules/base_installation/manifests/params.pp | 1 + .../base_installation/manifests/system_config.pp | 34 ++++++++++++---------- .../templates/puppet/host_ldap.info.erb | 4 ++- .../templates/puppet/puppet.conf.erb | 4 ++- modules/profile/manifests/apache.pp | 8 ++++- modules/role/manifests/cryptoportfolio.pp | 2 +- python/list_servers.py | 12 ++++++++ 18 files changed, 122 insertions(+), 37 deletions(-) create mode 100644 environments/integration/data/common.yaml create mode 100644 environments/integration/data/roles/cryptoportfolio.yaml create mode 100644 environments/integration/data/types/vps-ovhssd-1.yaml create mode 100644 environments/integration/hiera.yaml delete mode 100644 environments/production/data/nodes/vps464408.novalocal.yaml delete mode 100644 environments/production/data/nodes/vps494082.yaml create mode 100644 python/list_servers.py diff --git a/bin/install_script.sh b/bin/install_script.sh index 49a737f..6b1aa39 100755 --- a/bin/install_script.sh +++ b/bin/install_script.sh @@ -12,6 +12,7 @@ cat < $ARCH_INSTALL_SCRIPT < $ARCH_PUPPET_CONFIGURATION_SCRIPT < $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT < "$base_installation::system_hostname\n", - } + if empty($base_installation::system_hostname) { + $hostname = $base_installation::real_hostname + } else { + $hostname = $base_installation::system_hostname + } - exec { "set_hostname": - command => "/usr/bin/hostnamectl set-hostname $base_installation::system_hostname", - refreshonly => true, - subscribe => File["/etc/hostname"], - returns => [0, 1], - } + file { '/etc/hostname': + content => "$base_installation::system_hostname\n", + } - # TODO: find a way to ensure that /etc/hostname doesn't change - # exec { "set_hostname_firstboot": - # command => "/usr/bin/systemd-firstboot --hostname=$base_installation::system_hostname", - # creates => "/etc/hostname", - # } + exec { "set_hostname": + command => "/usr/bin/hostnamectl set-hostname $base_installation::system_hostname", + refreshonly => true, + subscribe => File["/etc/hostname"], + returns => [0, 1], } + # TODO: find a way to ensure that /etc/hostname doesn't change + # exec { "set_hostname_firstboot": + # command => "/usr/bin/systemd-firstboot --hostname=$base_installation::system_hostname", + # creates => "/etc/hostname", + # } + } diff --git a/modules/base_installation/templates/puppet/host_ldap.info.erb b/modules/base_installation/templates/puppet/host_ldap.info.erb index 525739b..a71c6f3 100644 --- a/modules/base_installation/templates/puppet/host_ldap.info.erb +++ b/modules/base_installation/templates/puppet/host_ldap.info.erb @@ -2,7 +2,6 @@ ldapadd -D "cn=root,<%= @ldap_base %>" -W << 'EOF' dn: <%= @ldap_dn %> cn: <%= @ldap_cn %> -cn: <%= @system_hostname %> objectclass: device objectclass: top objectclass: simpleSecurityObject @@ -12,6 +11,7 @@ objectclass: ipHost <% unless @ips["v4"].nil? -%>ipHostNumber: <%= @ips["v4"]["ipAddress"] %><%- end %> <% unless @ips["v6"].nil? -%>ipHostNumber: <%= @ips["v6"]["ipAddress"] %>/<%= @ips["v6"]["mask"] %><%- end %> <%- end -%> +environment: <%= @environment %> userpassword: {SSHA}<%= Base64.encode64(Digest::SHA1.digest(@ldap_password+@ssha_ldap_seed)+@ssha_ldap_seed).chomp! %> EOF #### Or modify an existing entry: @@ -20,6 +20,8 @@ dn: <%= @ldap_dn %> changetype: modify replace: userPassword userpassword: {SSHA}<%= Base64.encode64(Digest::SHA1.digest(@ldap_password+@ssha_ldap_seed)+@ssha_ldap_seed).chomp! %> +replace: environment +environment: <%= @environment %> <%- unless @ips.empty? -%> - delete: ipHostNumber diff --git a/modules/base_installation/templates/puppet/puppet.conf.erb b/modules/base_installation/templates/puppet/puppet.conf.erb index 3748039..24e67c8 100644 --- a/modules/base_installation/templates/puppet/puppet.conf.erb +++ b/modules/base_installation/templates/puppet/puppet.conf.erb @@ -1,8 +1,10 @@ [main] ssldir = <%= @puppet_ssl_path %> +environment = <%= @environment %> + node_terminus = ldap -certname = <%= @system_hostname %> +certname = <%= @real_hostname %> ldapserver = <%= @ldap_server %> ldaptls = true ldapbase = <%= @ldap_base %> diff --git a/modules/profile/manifests/apache.pp b/modules/profile/manifests/apache.pp index 605b701..8db58da 100644 --- a/modules/profile/manifests/apache.pp +++ b/modules/profile/manifests/apache.pp @@ -49,11 +49,17 @@ class profile::apache { ] } + exec { 'Start-apache': + command => "/usr/bin/systemctl start httpd", + before => Class["::letsencrypt"], + unless => "/usr/bin/systemctl is-active httpd", + } + $letsencrypt_certonly_default = { plugin => "webroot", webroot_paths => ["/srv/http/"], notify => Class['Apache::Service'], - require => [Apache::Vhost["redirect_no_ssl"],Apache::Custom_config["letsencrypt.conf"]], + require => [Exec['Start-apache'],Apache::Vhost["redirect_no_ssl"],Apache::Custom_config["letsencrypt.conf"]], manage_cron => true, } diff --git a/modules/role/manifests/cryptoportfolio.pp b/modules/role/manifests/cryptoportfolio.pp index 32b6ac7..1e39479 100644 --- a/modules/role/manifests/cryptoportfolio.pp +++ b/modules/role/manifests/cryptoportfolio.pp @@ -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" diff --git a/python/list_servers.py b/python/list_servers.py new file mode 100644 index 0000000..9b8bc64 --- /dev/null +++ b/python/list_servers.py @@ -0,0 +1,12 @@ +try: + from ovh import ovh +except ImportError: + # In case it's installed globally + import ovh + +client = ovh.Client() + +vps_list = client.get('/vps/') + +for vps in vps_list: + print(vps) -- cgit v1.2.3 From 2499f7e73946cd5147a1158b48ebe4b06e4e530d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 4 Mar 2018 12:28:24 +0100 Subject: Add helpers and remove logs from cronie --- .../files/cronie/puppet-post-merge | 2 +- .../files/scripts/puppet_reset_and_apply | 14 + .../files/scripts/report_print.rb | 396 +++++++++++++++++++++ modules/base_installation/manifests/cronie.pp | 4 +- modules/base_installation/manifests/puppet.pp | 12 + 5 files changed, 425 insertions(+), 3 deletions(-) create mode 100644 modules/base_installation/files/scripts/puppet_reset_and_apply create mode 100644 modules/base_installation/files/scripts/report_print.rb diff --git a/modules/base_installation/files/cronie/puppet-post-merge b/modules/base_installation/files/cronie/puppet-post-merge index 35fa2d7..ac5e3ff 100644 --- a/modules/base_installation/files/cronie/puppet-post-merge +++ b/modules/base_installation/files/cronie/puppet-post-merge @@ -1,7 +1,7 @@ #!/bin/bash ## Run Puppet locally using puppet apply git submodule update --init -/usr/bin/puppet apply --test `pwd`/manifests/site.pp +/usr/bin/puppet apply `pwd`/manifests/site.pp ## Log status of the Puppet run if [ $? -eq 0 ] diff --git a/modules/base_installation/files/scripts/puppet_reset_and_apply b/modules/base_installation/files/scripts/puppet_reset_and_apply new file mode 100644 index 0000000..ff71aa8 --- /dev/null +++ b/modules/base_installation/files/scripts/puppet_reset_and_apply @@ -0,0 +1,14 @@ +#!/bin/bash + +cd /etc/puppetlabs/code +git fetch origin + +branch="master" +if [ -n "$1" ]; then + branch="$1" +fi + +git reset --hard origin/$1 + +git submodule update --init +puppet apply --test manifests/site.pp diff --git a/modules/base_installation/files/scripts/report_print.rb b/modules/base_installation/files/scripts/report_print.rb new file mode 100644 index 0000000..632374c --- /dev/null +++ b/modules/base_installation/files/scripts/report_print.rb @@ -0,0 +1,396 @@ +#!/usr/bin/env ruby +# This file was modified from its original version at +# https://github.com/ripienaar/puppet-reportprint/ +# +# Copyright 2013-2016 R.I.Pienaar and contributors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'puppet' +require 'pp' +require 'optparse' + +def get_server_reports_dir + Puppet.settings[:reportdir] +end + +class ::Numeric + def bytes_to_human + # Prevent nonsense values being returned for fractions + if self >= 1 + units = ['B', 'KB', 'MB' ,'GB' ,'TB'] + e = (Math.log(self)/Math.log(1024)).floor + # Cap at TB + e = 4 if e > 4 + s = "%.2f " % (to_f / 1024**e) + s.sub(/\.?0*$/, units[e]) + else + "0 B" + end + end +end + +def load_report(path) + YAML.load_file(path) +end + +def report_resources(report) + report.resource_statuses +end + +def resource_with_evaluation_time(report) + report_resources(report).select{|r_name, r| !r.evaluation_time.nil? } +end + +def resource_by_eval_time(report) + report_resources(report).reject{|r_name, r| r.evaluation_time.nil? }.sort_by{|r_name, r| r.evaluation_time rescue 0} +end + +def resources_of_type(report, type) + report_resources(report).select{|r_name, r| r.resource_type == type} +end + +def color(code, msg, reset=false) + colors = { + :red => "", + :green => "", + :yellow => "", + :cyan => "", + :bold => "", + :underline => "", + :reset => "", + } + + colors.merge!( + :changed => colors[:yellow], + :unchanged => colors[:green], + :failed => colors[:red] + ) + + return "%s%s%s%s" % [colors.fetch(code, ""), msg, colors[:reset], reset ? colors.fetch(reset, "") : ""] if @options[:color] + + msg +end + +def print_report_summary(report) + puts color(:bold, "Report for %s in environment %s at %s" % [color(:underline, report.host, :bold), color(:underline, report.environment, :bold), color(:underline, report.time, :bold)]) + puts + puts " Report File: %s" % @options[:report] + puts " Report Status: %s" % report.status + puts " Puppet Version: %s" % report.puppet_version + puts " Report Format: %s" % report.report_format + puts " Configuration Version: %s" % report.configuration_version + puts " UUID: %s" % report.transaction_uuid rescue nil + puts " Log Lines: %s %s" % [report.logs.size, @options[:logs] ? "" : "(show with --log)"] + + puts +end + +def print_report_motd(report, motd_path) + motd = [] + header = "# #{report.host} #" + headline = "#" * header.size + motd << headline << header << headline << '' + + motd << "Last puppet run happened at %s in environment %s." % [report.time, report.environment] + + motd << "The result of this puppet run was %s." % color(report.status.to_sym, report.status) + + if report.metrics.empty? or report.metrics["events"].nil? + motd << 'No Report Metrics.' + else + motd << 'Events:' + report.metrics["events"].values.each do |metric| + i, m, v = metric + motd.last << ' ' << [m, v].join(': ') << '.' + end + end + + motd << '' << '' + + File.write(motd_path, motd.join("\n")) +end + +def print_report_metrics(report) + if report.metrics.empty? + puts color(:bold, "No Report Metrics") + puts + return + end + + puts color(:bold, "Report Metrics:") + puts + + padding = report.metrics.map{|i, m| m.values}.flatten(1).map{|i, m, v| m.size}.sort[-1] + 6 + + report.metrics.sort_by{|i, m| m.label}.each do |i, metric| + puts " %s:" % metric.label + + metric.values.sort_by{|j, m, v| v}.reverse.each do |j, m, v| + puts "%#{padding}s: %s" % [m, v] + end + + puts + end + + puts +end + +def print_summary_by_type(report) + summary = {} + + report_resources(report).each do |resource| + if resource[0] =~ /^(.+?)\[/ + name = $1 + + summary[name] ||= 0 + summary[name] += 1 + else + STDERR.puts "ERROR: Cannot parse type %s" % resource[0] + end + end + + puts color(:bold, "Resources by resource type:") + puts + + summary.sort_by{|k, v| v}.reverse.each do |type, count| + puts " %4d %s" % [count, type] + end + + puts +end + +def print_slow_resources(report, number=20) + if report.report_format < 4 + puts color(:red, " Cannot print slow resources for report versions %d" % report.report_format) + puts + return + end + + resources = resource_by_eval_time(report) + + number = resources.size if resources.size < number + + puts color(:bold, "Slowest %d resources by evaluation time:" % number) + puts + + resources[(0-number)..-1].reverse.each do |r_name, r| + puts " %7.2f %s" % [r.evaluation_time, r_name] + end + + puts +end + +def print_logs(report) + puts color(:bold, "%d Log lines:" % report.logs.size) + puts + + report.logs.each do |log| + puts " %s" % log.to_report + end + + puts +end + +def print_summary_by_containment_path(report, number=20) + resources = resource_with_evaluation_time(report) + + containment = Hash.new(0) + + resources.each do |r_name, r| + r.containment_path.each do |containment_path| + #if containment_path !~ /\[/ + containment[containment_path] += r.evaluation_time + #end + end + end + + number = containment.size if containment.size < number + + puts color(:bold, "%d most time consuming containment" % number) + puts + + containment.sort_by{|c, s| s}[(0-number)..-1].reverse.each do |c_name, evaluation_time| + puts " %7.2f %s" % [evaluation_time, c_name] + end + + puts +end + +def print_files(report, number=20) + resources = resources_of_type(report, "File") + + files = {} + + resources.each do |r_name, r| + if r_name =~ /^File\[(.+)\]$/ + file = $1 + + if File.exist?(file) && File.readable?(file) && File.file?(file) && !File.symlink?(file) + files[file] = File.size?(file) || 0 + end + end + end + + number = files.size if files.size < number + + puts color(:bold, "%d largest managed files" % number) + " (only those with full path as resource name that are readable)" + puts + + files.sort_by{|f, s| s}[(0-number)..-1].reverse.each do |f_name, size| + puts " %9s %s" % [size.bytes_to_human, f_name] + end + + puts +end + +def get_reports_for_node(nodename) + Dir.glob("%s/%s/*.yaml" % [get_server_reports_dir, nodename]).sort_by{|p|File.basename(p, ".*")} +end + +def load_report_for_node(nodename, report) + report_path = "%s/%s/%s.yaml" % [get_server_reports_dir, nodename, report] + puts report_path + load_report(report_path) unless report_path.nil? +end + +def load_report_by_id(report) + report_glob = "%s/*/%s.yaml" % [get_server_reports_dir, report] + Dir.glob(report_glob).map do |report_path| + puts report_path + load_report(report_path) unless report_path.nil? + end.first +end + +def load_last_report_for_node(nodename) + report_path = get_reports_for_node(nodename).last + load_report(report_path) unless report_path.nil? +end + +def print_reports_for_node(nodename) + puts color(:bold, "Reports for %s" % nodename) + get_reports_for_node(nodename).each do |report_path| + prefix = File.basename(report_path, ".*") + report = load_report(report_path) + print_report_oneliner(report, prefix) + end +end + +def print_report_oneliner(report, prefix) + puts "%s: %s" % [prefix, color(report.status.to_sym, report.status)] +end + +def print_node_oneliner(nodename) + report = load_last_report_for_node(nodename) + print_report_oneliner(report, report.name) unless report.nil? +end + +def print_server_nodes_status + puts color(:bold, 'Nodes list') + dir = get_server_reports_dir + puts color(:bold, 'No nodes found!') unless Puppet::FileSystem.exist?(dir) + Dir.glob("%s/*/" % dir).each do |node_path| + print_node_oneliner(File.basename(node_path)) + end +end + +def initialize_puppet + require 'puppet/util/run_mode' + Puppet.settings.preferred_run_mode = :agent + Puppet.settings.initialize_global_settings([]) + Puppet.settings.initialize_app_defaults(Puppet::Settings.app_defaults_for_run_mode(Puppet.run_mode)) +end + +initialize_puppet + +opt = OptionParser.new + +@options = { + :logs => false, + :history => false, + :server => false, + :node => nil, + :motd => false, + :motd_path => '/etc/motd', + :count => 20, + :report => Puppet[:lastrunreport], + :reportid => nil, + :color => STDOUT.tty?} + +opt.on("--logs", "Show logs") do |val| + @options[:logs] = val +end + +opt.on("--nodelist", "(Puppet Server) List Puppet nodes and the status of their last report") do |val| + @options[:server] = val +end + +opt.on("--node [NODE]", "(Puppet Server) Use last report of a node") do |val| + @options[:node] = val +end + +opt.on("--history", "(with --node) Print the reports history for a node") do |val| + @options[:history] = val +end + +opt.on("--motd", "Produce an output suitable for MOTD") do |val| + @options[:motd] = val +end + +opt.on("--motd-path [PATH]", "Path to the MOTD file to overwrite with the --motd option") do |val| + @options[:motd_path] = val +end + +opt.on("--count [RESOURCES]", Integer, "Number of resources to show evaluation times for") do |val| + @options[:count] = val +end + +opt.on("--report [REPORT]", "Path to the Puppet last run report") do |val| + abort("Could not find report %s" % val) unless File.readable?(val) + @options[:report] = val +end + +opt.on("--report-id [REPORTID]", "(with --node) ID of the report to load") do |val| + @options[:reportid] = val +end + +opt.on("--[no-]color", "Colorize the report") do |val| + @options[:color] = val +end + +opt.parse! + +report = load_report(@options[:report]) unless @options[:server] or @options[:node] +if @options[:node] and not @options[:history] and not @options[:reportid] + report = load_last_report_for_node(@options[:node]) +elsif @options[:node] and @options[:reportid] + report = load_report_for_node(@options[:node], @options[:reportid]) +elsif @options[:reportid] + report = load_report_by_id(@options[:reportid]) +end + +if @options[:server] + print_server_nodes_status +elsif @options[:node] and @options[:history] + print_reports_for_node(@options[:node]) +elsif @options[:motd] + print_report_motd(report, @options[:motd_path]) +else + print_report_summary(report) + print_report_metrics(report) + print_summary_by_type(report) + print_slow_resources(report, @options[:count]) + print_files(report, @options[:count]) + print_summary_by_containment_path(report, @options[:count]) + print_logs(report) if @options[:logs] +end diff --git a/modules/base_installation/manifests/cronie.pp b/modules/base_installation/manifests/cronie.pp index 4df0e37..72f2d8f 100644 --- a/modules/base_installation/manifests/cronie.pp +++ b/modules/base_installation/manifests/cronie.pp @@ -19,13 +19,13 @@ class base_installation::cronie inherits base_installation { } cron { 'puppet-apply': ensure => present, - command => "cd $base_installation::puppet_code_path ; puppet apply --test $base_installation::puppet_code_path/manifests/site.pp", + command => "cd $base_installation::puppet_code_path ; puppet apply $base_installation::puppet_code_path/manifests/site.pp", user => root, minute => '*/20' } cron { 'puppet-apply-reboot': ensure => present, - command => "cd $base_installation::puppet_code_path ; puppet apply --test $base_installation::puppet_code_path/manifests/site.pp", + command => "cd $base_installation::puppet_code_path ; puppet apply $base_installation::puppet_code_path/manifests/site.pp", user => root, special => "reboot" } diff --git a/modules/base_installation/manifests/puppet.pp b/modules/base_installation/manifests/puppet.pp index a8dc641..b3ce492 100644 --- a/modules/base_installation/manifests/puppet.pp +++ b/modules/base_installation/manifests/puppet.pp @@ -27,6 +27,18 @@ class base_installation::puppet ( } ### + file { '/usr/local/sbin/i_puppet_reset_and_apply': + mode => "0755", + ensure => present, + source => "puppet:///modules/base_installation/scripts/puppet_reset_and_apply" + } + + file { '/usr/local/sbin/i_puppet_report_print': + mode => "0755", + ensure => present, + source => "puppet:///modules/base_installation/scripts/report_print.rb" + } + unless empty(find_file($password_seed)) { $ldap_password = generate_password(24, $password_seed, "ldap") $ssha_ldap_seed = generate_password(5, $password_seed, "ldap_seed") -- cgit v1.2.3 From a545a4222ee6a4bcdee9c73a8f4abe0e38f1bdad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 4 Mar 2018 19:09:25 +0100 Subject: Upgrade bot version --- environments/integration/data/roles/cryptoportfolio.yaml | 8 ++++---- environments/production/data/roles/cryptoportfolio.yaml | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/environments/integration/data/roles/cryptoportfolio.yaml b/environments/integration/data/roles/cryptoportfolio.yaml index 7464b3d..e55d15b 100644 --- a/environments/integration/data/roles/cryptoportfolio.yaml +++ b/environments/integration/data/roles/cryptoportfolio.yaml @@ -1,7 +1,7 @@ --- classes: role::cryptoportfolio: ~ -cryptoportfolio::front_version: v0.0.2 -cryptoportfolio::front_sha256: 2ace0197a34f9f130523eecf8a43aa4f411cdca09de33838e074f25a7e1d6c5e -cryptoportfolio::bot_version: v0.2-4-gf70bb85 -cryptoportfolio::bot_sha256: e9850a667e0672cdd0363bb93124b59610c4d67e3ed9908b004a9d15c2276340 +cryptoportfolio::front_version: v0.0.2-3-g6200f9a +cryptoportfolio::front_sha256: 69d31251ecd4fcea46d93dfee0184b1171019a765b6744b84f6eec6b10e5818f +cryptoportfolio::bot_version: v0.4-2-g123411c +cryptoportfolio::bot_sha256: c344653c6523ed4902e4e4270740c434b45c87876d827d2a695c6732a99cd59b diff --git a/environments/production/data/roles/cryptoportfolio.yaml b/environments/production/data/roles/cryptoportfolio.yaml index 7464b3d..e55d15b 100644 --- a/environments/production/data/roles/cryptoportfolio.yaml +++ b/environments/production/data/roles/cryptoportfolio.yaml @@ -1,7 +1,7 @@ --- classes: role::cryptoportfolio: ~ -cryptoportfolio::front_version: v0.0.2 -cryptoportfolio::front_sha256: 2ace0197a34f9f130523eecf8a43aa4f411cdca09de33838e074f25a7e1d6c5e -cryptoportfolio::bot_version: v0.2-4-gf70bb85 -cryptoportfolio::bot_sha256: e9850a667e0672cdd0363bb93124b59610c4d67e3ed9908b004a9d15c2276340 +cryptoportfolio::front_version: v0.0.2-3-g6200f9a +cryptoportfolio::front_sha256: 69d31251ecd4fcea46d93dfee0184b1171019a765b6744b84f6eec6b10e5818f +cryptoportfolio::bot_version: v0.4-2-g123411c +cryptoportfolio::bot_sha256: c344653c6523ed4902e4e4270740c434b45c87876d827d2a695c6732a99cd59b -- cgit v1.2.3 From 383fa18a98e98e5e85f35bef17938957c52ee216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 4 Mar 2018 20:49:34 +0100 Subject: Fix front app not building correctly --- modules/role/manifests/cryptoportfolio.pp | 107 +++++++++++++----------------- 1 file changed, 47 insertions(+), 60 deletions(-) diff --git a/modules/role/manifests/cryptoportfolio.pp b/modules/role/manifests/cryptoportfolio.pp index 1e39479..c940f33 100644 --- a/modules/role/manifests/cryptoportfolio.pp +++ b/modules/role/manifests/cryptoportfolio.pp @@ -263,7 +263,6 @@ class role::cryptoportfolio { } } - # FIXME: incorrect build for go app # FIXME: restore backup unless empty($front_version) { ensure_packages(["go", "npm", "nodejs", "yarn"]) @@ -284,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 => $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]], - } - 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": @@ -360,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_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 => $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, } } } -- cgit v1.2.3 From 3f868d0b4f48e75aeed56a13f3c4053bac9108f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 4 Mar 2018 20:56:38 +0100 Subject: Rename archive files --- modules/role/manifests/cryptoportfolio.pp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/role/manifests/cryptoportfolio.pp b/modules/role/manifests/cryptoportfolio.pp index c940f33..5fb0438 100644 --- a/modules/role/manifests/cryptoportfolio.pp +++ b/modules/role/manifests/cryptoportfolio.pp @@ -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, @@ -230,7 +230,7 @@ class role::cryptoportfolio { content => template("role/cryptoportfolio/bot_config.ini.erb"), require => [ User[$cf_user], - Archive["${cf_home}/${bot_version}.tar.gz"], + Archive["${cf_home}/trader_${bot_version}.tar.gz"], ], } @@ -244,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"] ], } @@ -258,7 +258,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"] ], } } @@ -313,8 +313,8 @@ 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_version}.tar.gz": - path => "${cf_home}/${front_version}.tar.gz", + 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, -- cgit v1.2.3 From c17e63ed33a5260ea5bf0f869d7dce39676526cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 4 Mar 2018 21:05:42 +0100 Subject: Fix user for build --- modules/role/manifests/cryptoportfolio.pp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/role/manifests/cryptoportfolio.pp b/modules/role/manifests/cryptoportfolio.pp index 5fb0438..6c760b5 100644 --- a/modules/role/manifests/cryptoportfolio.pp +++ b/modules/role/manifests/cryptoportfolio.pp @@ -203,7 +203,7 @@ class role::cryptoportfolio { checksum => $bot_sha256, cleanup => false, extract => true, - user => "cryptoportfolio", + user => $cf_user, username => $facts["ec2_metadata"]["hostname"], password => generate_password(24, $password_seed, "ldap"), extract_path => $cf_bot_app, @@ -373,6 +373,7 @@ class role::cryptoportfolio { exec { "web-cryptoportfolio-dependencies": cwd => "${cf_front_app}/cmd/web", + user => $cf_user, environment => ["HOME=${cf_home}"], command => "/usr/bin/make install", refreshonly => true, @@ -380,6 +381,7 @@ class role::cryptoportfolio { } ~> exec { "web-cryptoportfolio-build": cwd => "${cf_front_app}/cmd/web", + user => $cf_user, environment => ["HOME=${cf_home}"], path => ["${cf_front_app}/cmd/web/node_modules/.bin/", "/usr/bin"], command => "/usr/bin/make static ENV=${cf_env}", -- cgit v1.2.3