From 5103f0caba1f877aa429ec7254ec7047f94dce70 Mon Sep 17 00:00:00 2001 From: Max Lehman Date: Sun, 17 Mar 2019 05:11:55 -0700 Subject: [PATCH] Implement snapshot view and rollback functionality. --- META6.json | 2 +- bin/guestctl | 20 ++++++++++++++++---- lib/App/Guestctl/Common.pm6 | 12 +++++++----- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/META6.json b/META6.json index 615a22c..382321a 100644 --- a/META6.json +++ b/META6.json @@ -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" : [ diff --git a/bin/guestctl b/bin/guestctl index 15b518a..21b615c 100755 --- a/bin/guestctl +++ b/bin/guestctl @@ -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 { when *.all.defined { @@ -48,15 +48,27 @@ multi MAIN($guest, GuestAction $action) { transparent-run , cwd => $guest-dir; } + when (Snapshots, Any) { + my @snapshots = run(<>, :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 <>, :proceed; + transparent-run <>, cwd => $guest-dir; + } + when (Commit, Running) { my $container-id = run(<>, :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 <>, cwd => $guest-dir, :proceed; - transparent-run <>, cwd => $guest-dir, :proceed; - transparent-run <>, cwd => $guest-dir, :proceed; + transparent-run <>, :proceed; + transparent-run <>, :proceed; + transparent-run <>, cwd => $guest-dir; } default { diff --git a/lib/App/Guestctl/Common.pm6 b/lib/App/Guestctl/Common.pm6 index 06592e5..b780304 100644 --- a/lib/App/Guestctl/Common.pm6 +++ b/lib/App/Guestctl/Common.pm6 @@ -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", -- 2.38.4