macOS bundle + download.

This commit is contained in:
Kaitlyn Parkhurst 2021-06-26 09:12:13 -07:00
parent ece040e2b5
commit 903e377eb5
6 changed files with 81 additions and 2 deletions

1
.gitignore vendored
View file

@ -5,5 +5,6 @@ Web/devel
Web/tmp
Web/pans
Web/cpanfile.snapshot
Web/public/download
Ansible/playbook*
data/

View file

@ -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');

View file

@ -15,7 +15,8 @@ sub view ($c) {
$c->stash(
node => $node,
jobs => $jobs,
);
( $c->param('pending') ? ( pending => $c->param('pending') ) : () ),
);
}
1;

View file

@ -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;

View file

@ -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 );

View file

@ -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.</p>
%% if ( $pending ) {
<div style="margin-top: 2em" class="alert alert-success" role="alert">
<p>Your configuration is being built, it should be available at the following
link in a few seconds.</p>
<a _target="blank" href="[% $c.url_for( '/download/' ~ $pending ) %]">Download Configuration</a>
</div>
%% }
<div class="accordion" id="accordionExample">
<div class="accordion-item">
<h2 class="accordion-header" id="headingOne">
@ -45,7 +56,14 @@
</h2>
<div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo" data-bs-parent="#accordionExample">
<div class="accordion-body">
<strong>This is the second item's accordion body.</strong> 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 <code>.accordion-body</code>, though the transition does limit overflow.
<p>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.</p>
<form method="post" action="[% $c.url_for( 'deploy_macos' ) %]">
<input type="hidden" name="node_id" value="[% $node.id %]" />
<input type="submit" class="btn btn-primary" value="Create Bundle" />
</form>
</div>
</div>
</div>