ca4eddb5a9e458118c7a3e4304806370ab894dfc — 0xFORDCOMMA 8 months ago 850cd39
Implement forward-compatible self-management system.
4 files changed, 23 insertions(+), 5 deletions(-)

M bin/guestctl
A bin/guestctl-meta
M lib/App/Guestctl/Templates.pm6
M resources/templates/dockerfile.tmpl
M bin/guestctl => bin/guestctl +8 -4
@@ 123,8 123,6 @@ multi MAIN("new", $guest) {
         exit 1;
     }
 
-    my $template-dir = $guests-dir.IO.add: ".skeleton";
-
     my $guest-dir = $guests-dir.IO.add: $guest;
     mkdir $guest-dir;
     my $ssh-dir = $guest-dir.add: "ssh";


@@ 159,10 157,16 @@ multi MAIN("new", $guest) {
                          };
 
     my %variables = gen-template-vars @prompt-entries, $guest;
-    my @template-files = load-template-files $template-dir;
 
     # Effectful: instantiate and write out template files in new guest directory.
-    instantiate-template-files @template-files, %variables, $guest-dir;
+    instantiate-template-files load-template-files, %variables, $guest-dir;
+
+    # Set up self-management key and command.
+    transparent-run <<ssh-keygen -t rsa -N "''" -f {$guest-dir.add: "id_meta"}>>, :proceed;
+    my $public-key = $guest-dir.add("ssh/id_meta.pub").slurp;
+    my $management-key-entry = qq{command="nohup env guestctl-meta $guest \${SSH_ORIGINAL_COMMAND} &"} ~ $public-key;
+    my $guest-management-keys-file = "%*ENV<HOME>/.ssh/guest_management_keys".IO;
+    $guest-management-keys-file.spurt: "\n" ~ $management-key-entry, :append;
 
     my ($guest-base-image, $guest-live-image) = "guest-$guest" <<~>> <:base :live>;
     transparent-run <<docker build -t $guest-base-image $guest-dir>>, :proceed;

A bin/guestctl-meta => bin/guestctl-meta +13 -0
@@ 0,0 1,13 @@
+#!/usr/bin/env perl6
+
+multi MAIN($guest, "commit") {
+    run <<guestctl $guest commit>>;
+}
+
+multi MAIN($guest, "rollback", $image-tag) {
+    run <<guestctl $guest rollback $image-tag>>;
+}
+
+multi MAIN($guest, "restart") {
+    run <<guestctl $guest restart>>;
+}

M lib/App/Guestctl/Templates.pm6 => lib/App/Guestctl/Templates.pm6 +1 -1
@@ 35,7 35,7 @@ sub gen-template-vars(@prompt-entries, $guest) is export {
     return %template-vars;
 }
 
-sub load-template-files($template-dir) is export {
+sub load-template-files() is export {
     return ("Dockerfile"         => %?RESOURCES<templates/dockerfile.tmpl>.slurp,
             "docker-compose.yml" => %?RESOURCES<templates/docker-compose.tmpl>.slurp,
             "user"               => %?RESOURCES<templates/user.tmpl>.slurp,

M resources/templates/dockerfile.tmpl => resources/templates/dockerfile.tmpl +1 -0
@@ 9,6 9,7 @@ RUN ssh-keygen -A
 RUN mkdir -p /home/{{ user }}/.ssh
 RUN echo '{{ ssh_key }}' > /home/{{ user }}/.ssh/authorized_keys
 COPY ssh/sshd_config /etc/ssh/sshd_config
+COPY ssh/id_meta /home/{{ user }}/.ssh/id_meta
 
 {{ aux_dockerfile }}