From 903e377eb5a3868fe06656b9addadff820a3bbc0 Mon Sep 17 00:00:00 2001
From: Kaitlyn Parkhurst
Date: Sat, 26 Jun 2021 09:12:13 -0700
Subject: [PATCH] macOS bundle + download.
---
.gitignore | 1 +
Web/lib/MeshMage/Web.pm | 8 +++++
.../MeshMage/Web/Controller/Dashboard/Node.pm | 3 +-
.../MeshMage/Web/Controller/Deploy/MacOS.pm | 15 ++++++++
Web/lib/MeshMage/Web/Plugin/MinionTasks.pm | 36 +++++++++++++++++++
Web/templates/dashboard/node/view.html.tx | 20 ++++++++++-
6 files changed, 81 insertions(+), 2 deletions(-)
create mode 100644 Web/lib/MeshMage/Web/Controller/Deploy/MacOS.pm
diff --git a/.gitignore b/.gitignore
index 477eefb..0de464a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,5 +5,6 @@ Web/devel
Web/tmp
Web/pans
Web/cpanfile.snapshot
+Web/public/download
Ansible/playbook*
data/
diff --git a/Web/lib/MeshMage/Web.pm b/Web/lib/MeshMage/Web.pm
index 86ba445..f1c63f1 100644
--- a/Web/lib/MeshMage/Web.pm
+++ b/Web/lib/MeshMage/Web.pm
@@ -2,6 +2,7 @@ package MeshMage::Web;
use Mojo::Base 'Mojolicious', -signatures;
use MeshMage::DB;
use Minion;
+use Mojo::File qw( curfile );
# This method will run once at server start
sub startup ($self) {
@@ -24,6 +25,11 @@ sub startup ($self) {
);
$self->helper( db => sub { return $db } );
+ # The location we'll stick files for download.
+ $self->helper( download_dir => sub {
+ sprintf( "%s/%s", $self->static->paths->[0], 'download/' )
+ });
+
# Setup Minion Job Queue
# NOTE: https://docs.mojolicious.org/Mojolicious/Plugin/Minion/Admin When auth exists,
# make sure that this plugin uses the same protection as other machine bits.
@@ -58,6 +64,8 @@ sub startup ($self) {
$r->get ('/deploy/manual/:node_id' ) ->to('Deploy::Manual#deploy')->name('deploy_manual');
$r->post ('/deploy/manual' ) ->to('Deploy::Manual#create');
+
+ $r->post ('/deploy/macos' ) ->to('Deploy::MacOS#create')->name('deploy_macos');
# Manage SSH Keys
$r->get ('/sshkeys') ->to('Sshkeys#index');
diff --git a/Web/lib/MeshMage/Web/Controller/Dashboard/Node.pm b/Web/lib/MeshMage/Web/Controller/Dashboard/Node.pm
index 6c885df..e3ff111 100644
--- a/Web/lib/MeshMage/Web/Controller/Dashboard/Node.pm
+++ b/Web/lib/MeshMage/Web/Controller/Dashboard/Node.pm
@@ -15,7 +15,8 @@ sub view ($c) {
$c->stash(
node => $node,
jobs => $jobs,
- );
+ ( $c->param('pending') ? ( pending => $c->param('pending') ) : () ),
+ );
}
1;
diff --git a/Web/lib/MeshMage/Web/Controller/Deploy/MacOS.pm b/Web/lib/MeshMage/Web/Controller/Deploy/MacOS.pm
new file mode 100644
index 0000000..a75ccb4
--- /dev/null
+++ b/Web/lib/MeshMage/Web/Controller/Deploy/MacOS.pm
@@ -0,0 +1,15 @@
+package MeshMage::Web::Controller::Deploy::MacOS;
+use Mojo::Base 'Mojolicious::Controller', -signatures;
+
+sub create ($c) {
+
+ my $node = $c->db->resultset('Node')->find( $c->param('node_id') );
+
+ my $job_id = $c->minion->enqueue( create_macos_intel_bundle => [ $node->id ],
+ { notes => { $node->hostname => 1 } }
+ );
+
+ $c->redirect_to( $c->url_for( 'view_node', node_id => $node->id ) );
+}
+
+1;
diff --git a/Web/lib/MeshMage/Web/Plugin/MinionTasks.pm b/Web/lib/MeshMage/Web/Plugin/MinionTasks.pm
index 7b75650..91bc218 100644
--- a/Web/lib/MeshMage/Web/Plugin/MinionTasks.pm
+++ b/Web/lib/MeshMage/Web/Plugin/MinionTasks.pm
@@ -5,6 +5,7 @@ use File::Path qw( make_path );
use File::Temp;
use Try::Tiny;
use Net::Subnet;
+use Mojo::File;
sub register ( $self, $app, $config ) {
@@ -99,6 +100,41 @@ sub register ( $self, $app, $config ) {
$job->finish() unless shift;
};
});
+
+ $app->minion->add_task( create_macos_intel_bundle => sub ( $job, $node_id ) {
+ my $node = $job->app->db->resultset('Node')->find( $node_id );
+ my $domain = $node->hostname;
+ my $net_id = $node->network->id;
+
+ # TODO - This might need machine-specific configuration, let's abide that.
+ #
+ # Make Nebula Configuration File For Packing
+ Mojo::File->new( $job->app->filepath_for(nebula => $net_id, "$domain.yml"))
+ ->spurt( $job->app->make_nebula_config( $node ));
+
+ # Make a temp dir, and inside it put a nebula dir, we'll
+ # end up taring up the nebula directory as the bundle.
+ my $tempdir = File::Temp->newdir();
+ my $dir = "$tempdir/nebula";
+ make_path( $dir );
+
+ my $net_path = $job->app->filepath_for( nebula => $net_id );
+ my $neb_path = $job->app->nebula_for('darwin/amd64' ); # TODO - This can accept a platform, and
+ # and then we can use one bundle task
+ # for everything.
+
+ Mojo::File->new( "$net_path/$domain.crt" )->copy_to( $dir );
+ Mojo::File->new( "$net_path/$domain.key" )->copy_to( $dir );
+ Mojo::File->new( "$net_path/$domain.yml" )->copy_to( $dir );
+ Mojo::File->new( "$net_path/ca.crt" )->copy_to( $dir );
+ Mojo::File->new( "$neb_path" )->copy_to( $dir );
+
+ # my $outfile = $job->app->filepath_for( nebula => $net_id, "${domain}_macos_intel.tgz" )VC
+ my $outfile = $job->app->download_dir . "${domain}_macos_intel.tgz";
+
+ my $command = [qw( tar -C ), $tempdir, '-czf', $outfile, 'nebula' ];
+ run3( $command );
+ });
$app->minion->add_task( deploy_node => sub ( $job, $node_id, $key_id, $deploy_ip, $platform ) {
my $node = $job->app->db->resultset('Node')->find( $node_id );
diff --git a/Web/templates/dashboard/node/view.html.tx b/Web/templates/dashboard/node/view.html.tx
index 4a7efce..c1f9ea9 100644
--- a/Web/templates/dashboard/node/view.html.tx
+++ b/Web/templates/dashboard/node/view.html.tx
@@ -18,6 +18,17 @@
actual server or personal computer to connect to the network. Select the
type of node this is to get configure the machine to connect to the network.
+
+%% if ( $pending ) {
+
+
Your configuration is being built, it should be available at the following
+ link in a few seconds.
+
+
Download Configuration
+
+%% }
+
+
-
This is the second item's accordion body. It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the
.accordion-body
, though the transition does limit overflow.
+
To configure your macOS Laptop or Desktop, a bundle of files will be provided and instructions to set up the machine.
+ Click the button below to start building the bundle, once it is complete, the build button will be replaced with
+ a link to download and setup.
+
+