~mclehman/guestctl

5103f0caba1f877aa429ec7254ec7047f94dce70 — Max Lehman 5 years ago 82b8e7a
Implement snapshot view and rollback functionality.
3 files changed, 24 insertions(+), 10 deletions(-)

M META6.json
M bin/guestctl
M lib/App/Guestctl/Common.pm6
M META6.json => META6.json +1 -1
@@ 11,7 11,7 @@
        "templates/docker-compose.tmpl",
        "templates/sshd_config.tmpl"
    ],
    "version" : "0.0.5",
    "version" : "0.1.0",
    "production" : false,
    "perl" : "v6.*",
    "authors" : [

M bin/guestctl => bin/guestctl +16 -4
@@ 6,7 6,7 @@ use App::Guestctl::Templates;
use App::Guestctl::Utils;

# Primary main subroutine for individual guest control.
multi MAIN($guest, GuestAction $action) {
multi MAIN($guest, GuestAction $action, *@args) {
    # Run remotely if properly configured to do so.
    given %*ENV<GUEST_REMOTE_HOST GUEST_REMOTE_EXE> {
        when *.all.defined {


@@ 48,15 48,27 @@ multi MAIN($guest, GuestAction $action) {
            transparent-run <docker-compose restart>, cwd => $guest-dir;
        }

        when (Snapshots, Any) {
            my @snapshots = run(<<docker image list>>, :out).out.slurp.lines.grep(/'guest-' $guest/)>>.split('  ', :skip-empty);
            .say for @snapshots>>[1,3].grep({ .head ~~ /\d+/ }).map: -> ($tag, $time) { $tag ~ "\t" ~ $time };
        }

        when (Rollback, Any) {
            my $rollback-image = "guest-" ~ $guest ~ ":" ~ @args.head;
            my $live-image = "guest-" ~ $guest ~ ":live";
            transparent-run <<docker tag $rollback-image $live-image>>, :proceed;
            transparent-run <<docker-compose up -d --force-recreate>>, cwd => $guest-dir;
        }

        when (Commit, Running) {
            my $container-id = run(<<docker-compose ps -q $guest>>, :out, cwd => $guest-dir).out.slurp.chomp;
            my $commit-epoch-time = now.to-posix.head.Int;
            my $committed-image = "guest-" ~ $guest ~ ":" ~ $commit-epoch-time;
            my $live-image = "guest-" ~ $guest ~ ":live";
            note qq{Committing guest "$guest" to image $committed-image.};
            transparent-run <<docker commit $container-id $committed-image>>, cwd => $guest-dir, :proceed;
            transparent-run <<docker tag $committed-image $live-image>>, cwd => $guest-dir, :proceed;
            transparent-run <<docker-compose up -d>>, cwd => $guest-dir, :proceed;
            transparent-run <<docker commit $container-id $committed-image>>, :proceed;
            transparent-run <<docker tag $committed-image $live-image>>, :proceed;
            transparent-run <<docker-compose up -d>>, cwd => $guest-dir;
        }

        default {

M lib/App/Guestctl/Common.pm6 => lib/App/Guestctl/Common.pm6 +7 -5
@@ 9,11 9,13 @@ enum GuestStatus is export
     Stopped => "down");

enum GuestCommand is export
    (Up      => "up",
     Down    => "down",
     Restart => "restart",
     Status  => "status",
	 Commit  => "commit");
    (Up        => "up",
     Down      => "down",
     Restart   => "restart",
     Status    => "status",
	 Commit    => "commit",
     Snapshots => "snapshots",
     Rollback  => "rollback");

enum ManageCommand is export
    (Update  => "update",