From 503ad56e7aeae6050ef98477b3a60f6b4c9f59cf Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 6 Jan 2019 11:27:50 +0000 Subject: Add support for archiving mini environments --- app/controllers/mini_environments_controller.rb | 6 ++- .../backends/terraform_aws/backend_methods.rb | 5 +- .../backends/terraform_libvirt/backend_methods.rb | 5 +- app/views/mini_environments/index.html.erb | 24 ++++++--- app/views/mini_environments/show.html.erb | 57 ++++++++++++++-------- ...90106112141_add_archived_to_mini_environment.rb | 5 ++ db/structure.sql | 6 ++- 7 files changed, 74 insertions(+), 34 deletions(-) create mode 100644 db/migrate/20190106112141_add_archived_to_mini_environment.rb diff --git a/app/controllers/mini_environments_controller.rb b/app/controllers/mini_environments_controller.rb index 4dc8f39..ff811b0 100644 --- a/app/controllers/mini_environments_controller.rb +++ b/app/controllers/mini_environments_controller.rb @@ -144,7 +144,7 @@ class MiniEnvironmentsController < ApplicationController action = params.require(:commit) case action - when 'Destroy' + when 'Stop' MiniEnvironmentJob.enqueue(@mini_environment.id, :destroy) flash[:notice] = 'Destroying mini environment' @@ -156,6 +156,10 @@ class MiniEnvironmentsController < ApplicationController MiniEnvironmentJob.enqueue(@mini_environment.id, :refresh) flash[:notice] = 'Refreshing the mini environment state information' + when 'Archive' + @mini_environment.update(archived: true) + + flash[:notice] = 'Archiving mini environment' else flash[:error] = "Unknown action #{action}" end diff --git a/app/models/backends/terraform_aws/backend_methods.rb b/app/models/backends/terraform_aws/backend_methods.rb index b7545d1..59ba5d4 100644 --- a/app/models/backends/terraform_aws/backend_methods.rb +++ b/app/models/backends/terraform_aws/backend_methods.rb @@ -84,7 +84,10 @@ module Backends::TerraformAws::BackendMethods [ GovukGuix::Revision.where(archived: false).pluck(:store_path), available_data_snapshots.pluck(:store_path), - mini_environments.pluck(:backend_data).map { |x| x&.dig('build_output') } + mini_environments + .where(archived: false) + .pluck(:backend_data) + .map { |x| x&.dig('build_output') } ].flatten.compact end diff --git a/app/models/backends/terraform_libvirt/backend_methods.rb b/app/models/backends/terraform_libvirt/backend_methods.rb index 20ae379..54fb5a1 100644 --- a/app/models/backends/terraform_libvirt/backend_methods.rb +++ b/app/models/backends/terraform_libvirt/backend_methods.rb @@ -58,7 +58,10 @@ module Backends::TerraformLibvirt::BackendMethods [ GovukGuix::Revision.where(archived: false).pluck(:store_path), available_data_snapshots.pluck(:store_path), - mini_environments.pluck(:backend_data).map { |x| x.dig('build_output') } + mini_environments + .where(archived: false) + .pluck(:backend_data) + .map { |x| x.dig('build_output') } ].flatten.compact end diff --git a/app/views/mini_environments/index.html.erb b/app/views/mini_environments/index.html.erb index 3d57c5b..7fb634b 100644 --- a/app/views/mini_environments/index.html.erb +++ b/app/views/mini_environments/index.html.erb @@ -43,18 +43,26 @@ License along with the GOV.UK Mini Environment Admin. If not, see

<%= mini_environment.name %>

- <% if status[:running] %> -
+ <% else %> - + <% if status[:running] %> + + <% else %> + + <% end %> <% end %>
diff --git a/app/views/mini_environments/show.html.erb b/app/views/mini_environments/show.html.erb index 5a6de0b..be7494a 100644 --- a/app/views/mini_environments/show.html.erb +++ b/app/views/mini_environments/show.html.erb @@ -39,32 +39,40 @@ License along with the GOV.UK Mini Environment Admin. If not, see updated at <%= status[:updated_at] %>
- <% if status[:running] %> -
+ <% else %> - - <% end %> + <% if status[:running] %> + + <% else %> + + <% end %> - <% if status[:running] %> -
- - View - + <% if status[:running] %> +
+ + View + + <% end %> <% end %>
"> + "mini_environment/#{@mini_environment.id}" + ) %>"> View Terraform state information
@@ -79,19 +87,26 @@ License along with the GOV.UK Mini Environment Admin. If not, see