aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2018-06-28 19:12:17 +0100
committerChristopher Baines <mail@cbaines.net>2018-06-28 19:12:17 +0100
commita2e0b3fe4751dce20168ea3d7a480aed8527b870 (patch)
treead150dfd9b9205a8065d29ad4c259f50a6570695
parent373f1d131aebd9dc9c7cc6cf22a9f615627f2eef (diff)
downloadgovuk-mini-environment-admin-a2e0b3fe4751dce20168ea3d7a480aed8527b870.tar
govuk-mini-environment-admin-a2e0b3fe4751dce20168ea3d7a480aed8527b870.tar.gz
Make the git gem optional
As it's not required or useful currently if Guix isn't available locally.
-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'