From 7372e6f57de10ef565d60d4bbe8c72757b7129f2 Mon Sep 17 00:00:00 2001 From: Blog Manager Robot Date: Sun, 16 Oct 2022 23:09:19 +0000 Subject: [PATCH] Extend blog creation to create blogs. --- Web/lib/MJB/Web.pm | 10 ++++++++++ Web/lib/MJB/Web/Controller/Blog.pm | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Web/lib/MJB/Web.pm b/Web/lib/MJB/Web.pm index 6ced3fd..1640bfb 100644 --- a/Web/lib/MJB/Web.pm +++ b/Web/lib/MJB/Web.pm @@ -1,6 +1,7 @@ package MJB::Web; use Mojo::Base 'Mojolicious', -signatures; use MJB::DB; +use MJB::Backend::Jekyll; sub startup ($self) { my $config = $self->plugin('NotYAMLConfig', { file => -e 'mjb.yml' @@ -21,6 +22,15 @@ sub startup ($self) { return state $db = MJB::DB->connect($config->{database}->{mjb}); }); + $self->helper( jekyll => sub ($c, $domain) { + return MJB::Backend::Jekyll->new( + root => '/home/manager/mjb/Web/repos', # Make a config option. + domain => $domain, + init_from => 'https://store.myjekyllblog.com/symkat/symkat.jekyllblog.com.git', + repo => 'git@store.myjekyllblog.com:mjb/' . $domain . '.git', + ); + }); + # Minion plugin & tasks $self->plugin( Minion => { Pg => $self->config->{database}->{minion} } ); diff --git a/Web/lib/MJB/Web/Controller/Blog.pm b/Web/lib/MJB/Web/Controller/Blog.pm index 925be19..4d4a57c 100644 --- a/Web/lib/MJB/Web/Controller/Blog.pm +++ b/Web/lib/MJB/Web/Controller/Blog.pm @@ -26,6 +26,9 @@ sub do_create ($c) { return if $c->stash->{errors}; $domain = $domain ? $domain : $subdomain . '.' . $c->config->{customer_domain}; + + # Create the Jekyll repo for the site + my $jekyll = $c->jekyll($domain)->init; my $blog = try { $c->db->storage->schema->txn_do( sub { @@ -39,6 +42,10 @@ sub do_create ($c) { domain_id => $domain_record->id, }); + $blog->create_related( 'repoes', { + url => $jekyll->repo, + }); + return $blog; }); } catch { @@ -50,11 +57,19 @@ sub do_create ($c) { $domain = $domain ? $domain : $subdomain . '.' . $c->config->{hosted_domain}; - # Create the Jekyll repo for the site # Configure DNS to point to the blog # Schedule a job to deploy the website + my $ssl_job_id = $c->minion->enqueue( 'create_ssl_cert', [ $blog->id ], { + notes => { '_mjb_bid_' . $blog->id => 1 }, + queue => 'certbot', + }); + + $c->minion->enqueue( 'deploy_blog', [ $blog->id ], { + notes => { '_mjb_bid_' . $blog->id => 1 }, + parents => [ $ssl_job_id ], + }); # Take the user to the management panel for the site