diff --git a/Web/lib/MJB/Web/Controller/Blog.pm b/Web/lib/MJB/Web/Controller/Blog.pm index 9de1be6..aada3da 100644 --- a/Web/lib/MJB/Web/Controller/Blog.pm +++ b/Web/lib/MJB/Web/Controller/Blog.pm @@ -37,7 +37,12 @@ sub do_create ($c) { } # Create the Jekyll repo for the site - my $jekyll = $c->jekyll($domain)->init; + # This is where a job to build it on the build server should happen... + + #my $jekyll = $c->jekyll($domain)->init; + + my $repo = $c->config->{store_repo_base} . "$domain.git"; + my $blog = try { $c->db->storage->schema->txn_do( sub { @@ -52,7 +57,7 @@ sub do_create ($c) { }); $blog->create_related( 'repoes', { - url => $jekyll->repo, + url => $repo, }); return $blog; @@ -64,7 +69,12 @@ sub do_create ($c) { # Choose a web server to deploy to return if $c->stash->{errors}; - # Configure DNS to point to the blog + # Create the blog and add it to git. + my $create_job_id = $c->minion->enqueue( 'create_blog', [ $blog->id ], { + notes => { '_bid_' . $blog->id => 1 }, + priority => $blog->build_priority, + }); + $blog->create_related( 'builds', { job_id => $create_job_id } ); # Schedule a job to deploy the website my $ssl_job_id = $c->minion->enqueue( 'create_ssl_cert', [ $blog->id ], { diff --git a/Web/lib/MJB/Web/Task/CreateBlog.pm b/Web/lib/MJB/Web/Task/CreateBlog.pm index 9ef84c0..d11af31 100644 --- a/Web/lib/MJB/Web/Task/CreateBlog.pm +++ b/Web/lib/MJB/Web/Task/CreateBlog.pm @@ -1,16 +1,36 @@ package MJB::Web::Task::CreateBlog; use Mojo::Base 'Minion::Job', -signatures; -use Mojo::File qw( curfile ); +use Mojo::File qw( tempdir ); use File::Copy::Recursive qw( dircopy ); -use IPC::Run3; sub run ( $job, $blog_id ) { my $blog = $job->app->db->blog( $blog_id ); + $job->note( _mds_template => 'create_blog' ); - # Create clone of standard jekyll blog in repos/user_id/blog_id - # Set the git configuration for the clone so that it goes to gitea. - # TODO: add gitea user with ssh key? + my $dir = tempdir; + + $job->system_command( [qw( podman run -ti --rm -v .:/srv/jekyll -e JEKYLL_ROOTLESS=1 docker.io/jekyll/jekyll new blog ) ], { + chdir => $dir->to_string, + }); + + my $blog_root = $dir->child('blog'); + + $job->system_command( [ qw( git remote add origin ), $blog->repo->url ], { + chdir => $blog_root->to_string, + }); + + $job->system_command( [ qw( git add * ) ], { + chdir => $blog_root->to_string, + }); + + $job->system_command( [ qw( git commit -m ), "Created blog!" ], { + chdir => $blog_root->to_string, + }); + + $job->system_command( [ qw( git push origin master ) ], { + chdir => $blog_root->to_string, + }); }