From c9647021431355a0485714f874728552161c4515 Mon Sep 17 00:00:00 2001 From: Manager Bot Date: Tue, 1 Nov 2022 18:12:29 +0000 Subject: [PATCH] Testing faster deploy... --- Web/lib/MJB/Web.pm | 3 ++- Web/lib/MJB/Web/Task/SyncBlog.pm | 42 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 Web/lib/MJB/Web/Task/SyncBlog.pm diff --git a/Web/lib/MJB/Web.pm b/Web/lib/MJB/Web.pm index ac7ccd4..f9a817a 100644 --- a/Web/lib/MJB/Web.pm +++ b/Web/lib/MJB/Web.pm @@ -32,7 +32,7 @@ sub startup ($self) { }); $self->helper( deploy_blog => sub ( $c, $blog ) { - my $build_job_id = $c->minion->enqueue( 'deploy_blog', [ $blog->id ], { + my $build_job_id = $c->minion->enqueue( 'sync_blog', [ $blog->id ], { notes => { '_bid_' . $blog->id => 1 }, priority => $blog->build_priority, }); @@ -45,6 +45,7 @@ sub startup ($self) { # Blog deployment related jobs. $self->minion->add_task( purge_blog => 'MJB::Web::Task::PurgeBlog' ); $self->minion->add_task( deploy_blog => 'MJB::Web::Task::DeployBlog' ); + $self->minion->add_task( sync_blog => 'MJB::Web::Task::SyncBlog' ); # SSL cert related jobs. $self->minion->add_task( create_ssl_cert => 'MJB::Web::Task::CreateSSLCert' ); diff --git a/Web/lib/MJB/Web/Task/SyncBlog.pm b/Web/lib/MJB/Web/Task/SyncBlog.pm new file mode 100644 index 0000000..6af4b04 --- /dev/null +++ b/Web/lib/MJB/Web/Task/SyncBlog.pm @@ -0,0 +1,42 @@ +package MJB::Web::Task::SyncBlog; +use Mojo::Base 'MJB::Web::Task', -signatures; +use Mojo::File qw( curfile ); +use File::Copy::Recursive qw( dircopy ); +use IPC::Run3; + +sub run ( $job, $blog_id ) { + $job->note( _mds_template => 'build_static' ); + + my $build_dir = $job->checkout_repo( $blog_id ); + my $blog = $job->app->db->blog( $blog_id ); + + $job->note( is_clone_complete => 1 ); + + # Show the user the commit we're on. + $job->system_command( [ 'git', '-C', $build_dir->child('src')->to_string, 'log', '-1' ] ); + + $build_dir->child('build')->make_path; + + $job->system_command( [qw( podman run -ti --rm -v .:/srv/jekyll -e JEKYLL_ROOTLESS=1 docker.io/jekyll/jekyll jekyll build ) ], { + chdir => $build_dir->child('src')->to_string, + }); + + $job->process_webroot( + $blog, + $build_dir->child('src')->child('_site')->to_string, + $build_dir->child('build')->to_string + ); + + $job->note( is_build_complete => 1 ); + + my $domain = $blog->domain->name; + + foreach my $host ( qw( root@web-west.myjekyllblog.net root@web-east.myjekyllblog.net ) ) { + $job->system_command( [ qw( rsync -rLptgoD -e ), 'ssh -o StrictHostKeyChecking=no', $build_dir->child('build')->to_string, "$host:/var/www/$domain" ) ] ); + } + + $job->note( is_deploy_complete => 1 ); + $job->finish( ); +} + +1;