aboutsummaryrefslogtreecommitdiff
path: root/app/jobs/govuk_guix/fetch_revision_job.rb
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2018-06-23 09:21:30 +0100
committerChristopher Baines <mail@cbaines.net>2018-06-23 12:58:05 +0100
commit7fb0c23b891b8734cb04a9690cd030a134f5cd4d (patch)
treeeaac05016a75763698f821bb19816ca63b9acab3 /app/jobs/govuk_guix/fetch_revision_job.rb
parent7302c52a0011556527e5cbb6b0e996bd5bf49508 (diff)
downloadgovuk-mini-environment-admin-7fb0c23b891b8734cb04a9690cd030a134f5cd4d.tar
govuk-mini-environment-admin-7fb0c23b891b8734cb04a9690cd030a134f5cd4d.tar.gz
Add initial support for fetching govuk-guix revisions on remote hosts
This begins to remote the restriction of having to have Guix installed locally.
Diffstat (limited to 'app/jobs/govuk_guix/fetch_revision_job.rb')
-rw-r--r--app/jobs/govuk_guix/fetch_revision_job.rb61
1 files changed, 49 insertions, 12 deletions
diff --git a/app/jobs/govuk_guix/fetch_revision_job.rb b/app/jobs/govuk_guix/fetch_revision_job.rb
index 2787156..d3f11bf 100644
--- a/app/jobs/govuk_guix/fetch_revision_job.rb
+++ b/app/jobs/govuk_guix/fetch_revision_job.rb
@@ -24,26 +24,22 @@ class GovukGuix::FetchRevisionJob < Que::Job
extend EnqueuedJobs
include ::ShellUtils
- REPOSITORY_DIRECTORY = 'tmp/cache/govuk-guix'.freeze
-
@retry_interval = 30
- def run(commit_hash)
- repository.fetch
-
- sha = repository.object(commit_hash).sha
+ def run(commit_hash, options = {})
+ remote_host = options[:run_remotely_on_host]
- repository.checkout(sha)
+ fetch_and_checkout(commit_hash, remote_host)
command = [
- "#{REPOSITORY_DIRECTORY}/guix-pre-inst-env",
+ "#{@repository_directory}/guix-pre-inst-env",
'guix',
'build',
'-e',
'(begin (use-modules (gds packages govuk)) (current-govuk-guix))'
]
- output = run_command(*command)
+ output = run_command(*command, run_remotely_on_host: remote_host)
store_path = output.last.strip
logger.debug(self.class) { "store_path: #{store_path}" }
@@ -55,12 +51,53 @@ class GovukGuix::FetchRevisionJob < Que::Job
)
end
+ def fetch_and_checkout(commit_hash, remote_host)
+ if remote_host
+ @repository_directory = '/tmp/govuk-guix'
+
+ run_command(
+ "/bin/sh",
+ "-c",
+ "if cd '#{@repository_directory}';"\
+ "then git fetch;"\
+ "else "\
+ "git clone #{self.class.repository_remote_location} '#{@repository_directory}';"\
+ "fi",
+ run_remotely_on_host: remote_host
+ )
+
+ sha = run_command(
+ "/bin/sh",
+ "-c",
+ "cd '#{@repository_directory}';"\
+ "git rev-list -n 1 '#{commit_hash}'",
+ run_remotely_on_host: remote_host
+ ).last.strip
+
+ run_command(
+ "/bin/sh",
+ "-c",
+ "cd '#{@repository_directory}';"\
+ "git checkout #{sha}",
+ run_remotely_on_host: remote_host
+ )
+ else
+ @repository_directory = 'tmp/cache/govuk-guix'
+
+ repository.fetch
+
+ sha = repository.object(commit_hash).sha
+
+ repository.checkout(sha)
+ end
+ end
+
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(self.class.repository_remote_location, REPOSITORY_DIRECTORY)
+ Git.clone(self.class.repository_remote_location, @repository_directory)
end
end
end