From a2e0b3fe4751dce20168ea3d7a480aed8527b870 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Thu, 28 Jun 2018 19:12:17 +0100 Subject: Make the git gem optional As it's not required or useful currently if Guix isn't available locally. --- app/jobs/govuk_guix/fetch_revision_job.rb | 23 +++++++++++------------ config/boot.rb | 9 ++++++++- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/jobs/govuk_guix/fetch_revision_job.rb b/app/jobs/govuk_guix/fetch_revision_job.rb index d3f11bf..8d77761 100644 --- a/app/jobs/govuk_guix/fetch_revision_job.rb +++ b/app/jobs/govuk_guix/fetch_revision_job.rb @@ -18,8 +18,6 @@ # License along with the GOV.UK Mini Environment Admin. If not, see # . -require 'git' - class GovukGuix::FetchRevisionJob < Que::Job extend EnqueuedJobs include ::ShellUtils @@ -82,8 +80,19 @@ class GovukGuix::FetchRevisionJob < Que::Job run_remotely_on_host: remote_host ) else + require 'git' + @repository_directory = 'tmp/cache/govuk-guix' + repository = if File.exist? @repository_directory + Git.open(@repository_directory, log: Rails.logger) + else + Git.clone( + self.class.repository_remote_location, + @repository_directory + ) + end + repository.fetch sha = repository.object(commit_hash).sha @@ -92,16 +101,6 @@ class GovukGuix::FetchRevisionJob < Que::Job end end - def repository - @_repository ||= begin - if File.exist? @repository_directory - Git.open(@repository_directory, log: Rails.logger) - else - Git.clone(self.class.repository_remote_location, @repository_directory) - end - end - end - def available_services(store_path) command_output = run_command( "#{store_path}/bin/govuk", diff --git a/config/boot.rb b/config/boot.rb index d620a68..f39a63d 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,5 +1,11 @@ require 'pathname' +def activate_gem_if_available(name) + gem name +rescue Gem::MissingSpecError + false +end + gem 'rails' gem 'sass-rails' @@ -11,4 +17,5 @@ gem 'plek' gem 'que' gem 'ruby-terraform' gem 'with_advisory_lock' -gem 'git' + +activate_gem_if_available 'git' -- cgit v1.2.3