aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2018-06-19 21:19:09 +0100
committerChristopher Baines <mail@cbaines.net>2018-06-19 21:19:09 +0100
commited4ef0f9c9d5093a9996b9a9073a7cbd903112e2 (patch)
tree0a45118459113765e7e24de0a3d7eb5733923ff4
parent447b95bdac6cdd5134e0f5f12fd62d65e2130dbc (diff)
downloadgovuk-mini-environment-admin-ed4ef0f9c9d5093a9996b9a9073a7cbd903112e2.tar
govuk-mini-environment-admin-ed4ef0f9c9d5093a9996b9a9073a7cbd903112e2.tar.gz
Refactor the FetchRevisionJob
Move the repository directory in to a constant, and make the repository remote location configurable. Also, fix an issue with parsing the JSON output from the available-services command, as there were some messages appearing prior to the JSON output.
-rw-r--r--app/jobs/govuk_guix/fetch_revision_job.rb24
1 files changed, 14 insertions, 10 deletions
diff --git a/app/jobs/govuk_guix/fetch_revision_job.rb b/app/jobs/govuk_guix/fetch_revision_job.rb
index c2c3c17..c747c13 100644
--- a/app/jobs/govuk_guix/fetch_revision_job.rb
+++ b/app/jobs/govuk_guix/fetch_revision_job.rb
@@ -23,6 +23,8 @@ require 'git'
class GovukGuix::FetchRevisionJob < GovukGuix::Job
extend EnqueuedJobs
+ REPOSITORY_DIRECTORY = 'tmp/cache/govuk-guix'.freeze
+
@retry_interval = 30
def run(commit_hash)
@@ -33,7 +35,7 @@ class GovukGuix::FetchRevisionJob < GovukGuix::Job
repository.checkout(sha)
command = [
- "#{repository_directory}/guix-pre-inst-env",
+ "#{REPOSITORY_DIRECTORY}/guix-pre-inst-env",
'guix',
'build',
'-e',
@@ -54,10 +56,10 @@ class GovukGuix::FetchRevisionJob < GovukGuix::Job
def repository
@_repository ||= begin
- if File.exist? repository_directory
- Git.open(repository_directory, log: Rails.logger)
+ if File.exist? REPOSITORY_DIRECTORY
+ Git.open(REPOSITORY_DIRECTORY, log: Rails.logger)
else
- Git.clone(repository_remote_location, repository_directory)
+ Git.clone(self.class.repository_remote_location, REPOSITORY_DIRECTORY)
end
end
end
@@ -70,14 +72,16 @@ class GovukGuix::FetchRevisionJob < GovukGuix::Job
"--json"
)
- JSON.parse(command_output.join)
- end
+ json_start = command_output.find_index { |line| line.starts_with?('[') }
+ json_output = command_output[json_start..command_output.length].join
- def repository_directory
- 'tmp/cache/govuk-guix'
+ JSON.parse(json_output)
end
- def repository_remote_location
- 'git@git.cbaines.net:gds/govuk-guix'
+ def self.repository_remote_location
+ ENV.fetch(
+ 'GOVUK_GUIX_REPOSITORY_REMOTE',
+ 'https://github.com/alphagov/govuk-guix.git'
+ )
end
end