diff options
author | Christopher Baines <mail@cbaines.net> | 2019-01-06 11:27:50 +0000 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2019-01-06 11:55:15 +0000 |
commit | 503ad56e7aeae6050ef98477b3a60f6b4c9f59cf (patch) | |
tree | dcb700d7c33b7300d5d86ebf480dd486dcf67c24 | |
parent | 1c097bf9041939b286c1d2f764f65bcf017cd117 (diff) | |
download | govuk-mini-environment-admin-503ad56e7aeae6050ef98477b3a60f6b4c9f59cf.tar govuk-mini-environment-admin-503ad56e7aeae6050ef98477b3a60f6b4c9f59cf.tar.gz |
Add support for archiving mini environments
-rw-r--r-- | app/controllers/mini_environments_controller.rb | 6 | ||||
-rw-r--r-- | app/models/backends/terraform_aws/backend_methods.rb | 5 | ||||
-rw-r--r-- | app/models/backends/terraform_libvirt/backend_methods.rb | 5 | ||||
-rw-r--r-- | app/views/mini_environments/index.html.erb | 24 | ||||
-rw-r--r-- | app/views/mini_environments/show.html.erb | 57 | ||||
-rw-r--r-- | db/migrate/20190106112141_add_archived_to_mini_environment.rb | 5 | ||||
-rw-r--r-- | db/structure.sql | 6 |
7 files changed, 74 insertions, 34 deletions
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 <h2><%= mini_environment.name %></h2> </div> <div class="col-md-2"> - <% if status[:running] %> - <div class="alert alert-success text-center" + <% if mini_environment.archived? %> + <div class="alert alert-info text-center" role="alert" style="margin-bottom: 0px;"> - Mini environment running + Mini environment archived </div> <% else %> - <div class="alert alert-warning text-center" - role="alert" - style="margin-bottom: 0px;"> - Mini environment down - </div> + <% if status[:running] %> + <div class="alert alert-success text-center" + role="alert" + style="margin-bottom: 0px;"> + Mini environment running + </div> + <% else %> + <div class="alert alert-warning text-center" + role="alert" + style="margin-bottom: 0px;"> + Mini environment down + </div> + <% end %> <% end %> </div> </div> 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 <small>updated at <%= status[:updated_at] %></small> </div> <div class="panel-body"> - <% if status[:running] %> - <div class="alert alert-success text-center" + <% if @mini_environment.archived? %> + <div class="alert alert-info text-center" role="alert" style="margin-bottom: 0px;"> - Mini environment running + Mini environment archived </div> <% else %> - <div class="alert alert-warning text-center" - role="alert" - style="margin-bottom: 0px;"> - Mini environment down - </div> - <% end %> + <% if status[:running] %> + <div class="alert alert-success text-center" + role="alert" + style="margin-bottom: 0px;"> + Mini environment running + </div> + <% else %> + <div class="alert alert-warning text-center" + role="alert" + style="margin-bottom: 0px;"> + Mini environment down + </div> + <% end %> - <% if status[:running] %> - <br> - <a class="btn btn-primary btn-lg btn-block" - href="<%= @mini_environment.backend.signon_url(@mini_environment) %>"> - View - </a> + <% if status[:running] %> + <br> + <a class="btn btn-primary btn-lg btn-block" + href="<%= @mini_environment.backend.signon_url(@mini_environment) %>"> + View + </a> + <% end %> <% end %> <br> <a href="<%= terraform_http_backend_show_history_path( - "mini_environment/#{@mini_environment.id}" - ) %>"> + "mini_environment/#{@mini_environment.id}" + ) %>"> View Terraform state information </a> </div> @@ -79,19 +87,26 @@ License along with the GOV.UK Mini Environment Admin. If not, see <ul class="list-group"> <% if status[:running] %> <li class="list-group-item"> - <%= submit_tag("Destroy", + <%= submit_tag("Stop", role: 'button', - class: 'btn btn-lg btn-danger btn-block') + class: 'btn btn-lg btn-warning btn-block') %> </li> <% else %> <li class="list-group-item"> <%= submit_tag('Start', - disabled: !@mini_environment.backend_data.present?, + disabled: !@mini_environment.backend_data.present? || @mini_environment.archived?, role: 'button', class: 'btn btn-lg btn-success btn-block') %> </li> + <li class="list-group-item"> + <%= submit_tag("Archive", + disabled: @mini_environment.archived?, + role: 'button', + class: 'btn btn-lg btn-danger btn-block') + %> + </li> <% end %> <li class="list-group-item"> <%= submit_tag('Refresh', @@ -133,7 +148,7 @@ License along with the GOV.UK Mini Environment Admin. If not, see <% end %> at the revision specified in the revision of GOV.UK Guix (<a - href="<%= govuk_guix_revision_path @mini_environment.govuk_guix_revision %>" + href="<%= govuk_guix_revision_path @mini_environment.govuk_guix_revision %>" >show revision details</a>): <% multi_column = (uncustomised_services.length > 6) %> diff --git a/db/migrate/20190106112141_add_archived_to_mini_environment.rb b/db/migrate/20190106112141_add_archived_to_mini_environment.rb new file mode 100644 index 0000000..75527a7 --- /dev/null +++ b/db/migrate/20190106112141_add_archived_to_mini_environment.rb @@ -0,0 +1,5 @@ +class AddArchivedToMiniEnvironment < ActiveRecord::Migration[5.2] + def change + add_column :mini_environments, :archived, :boolean, default: false, null: false + end +end diff --git a/db/structure.sql b/db/structure.sql index f766762..5e5aaba 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -338,7 +338,8 @@ CREATE TABLE public.mini_environments ( backend_id bigint, backend_data jsonb, signon_users jsonb, - data_snapshot_id bigint + data_snapshot_id bigint, + archived boolean DEFAULT false NOT NULL ); @@ -877,6 +878,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20180603120426'), ('20180621065525'), ('20180621220505'), -('20180623083735'); +('20180623083735'), +('20190106112141'); |