From 1c097bf9041939b286c1d2f764f65bcf017cd117 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 6 Jan 2019 11:18:05 +0000 Subject: Support archiving govuk-guix revisions --- app/controllers/govuk_guix/revisions_controller.rb | 9 +++++++++ .../backends/terraform_aws/backend_methods.rb | 2 +- .../backends/terraform_libvirt/backend_methods.rb | 2 +- app/views/govuk_guix/revisions/show.html.erb | 21 ++++++++++++++++++++- app/views/setup/show.html.erb | 1 + 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/app/controllers/govuk_guix/revisions_controller.rb b/app/controllers/govuk_guix/revisions_controller.rb index 14a3161..e4e1b52 100644 --- a/app/controllers/govuk_guix/revisions_controller.rb +++ b/app/controllers/govuk_guix/revisions_controller.rb @@ -23,6 +23,15 @@ class GovukGuix::RevisionsController < ApplicationController @revision = GovukGuix::Revision.find(params['id']) end + def destroy + @revision = GovukGuix::Revision.find(params['id']) + + @revision.update(archived: true) + flash[:info] = "Archived #{@revision.commit_hash}..." + + render :show + end + def enqueue_fetch_revision revision = params.require('revision') diff --git a/app/models/backends/terraform_aws/backend_methods.rb b/app/models/backends/terraform_aws/backend_methods.rb index d6665a1..b7545d1 100644 --- a/app/models/backends/terraform_aws/backend_methods.rb +++ b/app/models/backends/terraform_aws/backend_methods.rb @@ -82,7 +82,7 @@ module Backends::TerraformAws::BackendMethods def in_use_store_paths [ - GovukGuix::Revision.pluck(:store_path), + 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') } ].flatten.compact diff --git a/app/models/backends/terraform_libvirt/backend_methods.rb b/app/models/backends/terraform_libvirt/backend_methods.rb index 85cd427..20ae379 100644 --- a/app/models/backends/terraform_libvirt/backend_methods.rb +++ b/app/models/backends/terraform_libvirt/backend_methods.rb @@ -56,7 +56,7 @@ module Backends::TerraformLibvirt::BackendMethods def in_use_store_paths [ - GovukGuix::Revision.pluck(:store_path), + 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') } ].flatten.compact diff --git a/app/views/govuk_guix/revisions/show.html.erb b/app/views/govuk_guix/revisions/show.html.erb index d2ab03f..f59b343 100644 --- a/app/views/govuk_guix/revisions/show.html.erb +++ b/app/views/govuk_guix/revisions/show.html.erb @@ -31,7 +31,26 @@ License along with the GOV.UK Mini Environment Admin. If not, see

Store path

-
<%= @revision.store_path %>
+ <% if @revision.archived? %> + +
<%= @revision.store_path %>
+
+ (Archived) + <% else %> +
<%= @revision.store_path %>
+ + <%= form_with( + url: govuk_guix_revision_path(@revision), + local: true, + method: "delete" + ) do %> + <%= submit_tag('Archive', + role: 'button', + style: 'margin-bottom: 5px;', + class: 'btn btn-lg btn-danger btn-block') + %> + <% end %> + <% end %>
diff --git a/app/views/setup/show.html.erb b/app/views/setup/show.html.erb index 01b1f32..2eb7402 100644 --- a/app/views/setup/show.html.erb +++ b/app/views/setup/show.html.erb @@ -109,6 +109,7 @@ License along with the GOV.UK Mini Environment Admin. If not, see <%= revision.commit_hash %> + <% if revision.archived? %>(Archived)<% end %> <%= revision.created_at %> <% end %> -- cgit v1.2.3