aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/jobs/govuk_guix/fetch_revision_job.rb23
-rw-r--r--config/boot.rb9
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
# <http://www.gnu.org/licenses/>.
-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'