aboutsummaryrefslogtreecommitdiff
path: root/app/jobs/govuk_guix/fetch_revision_job.rb
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2018-02-18 11:23:41 +0000
committerChristopher Baines <mail@cbaines.net>2018-03-29 07:41:09 +0100
commitbc1ffc5214ab3f563b60523d9c349fab7974e634 (patch)
tree1caa1ed8bf2fb96c4d340aeffd53cd50a8799980 /app/jobs/govuk_guix/fetch_revision_job.rb
parent700b8b0a112fa976b9850418a7f0c71d95b6dd79 (diff)
downloadgovuk-mini-environment-admin-bc1ffc5214ab3f563b60523d9c349fab7974e634.tar
govuk-mini-environment-admin-bc1ffc5214ab3f563b60523d9c349fab7974e634.tar.gz
Add some govuk-guix related jobs
And various other views and routes.
Diffstat (limited to 'app/jobs/govuk_guix/fetch_revision_job.rb')
-rw-r--r--app/jobs/govuk_guix/fetch_revision_job.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/app/jobs/govuk_guix/fetch_revision_job.rb b/app/jobs/govuk_guix/fetch_revision_job.rb
new file mode 100644
index 0000000..b1cb171
--- /dev/null
+++ b/app/jobs/govuk_guix/fetch_revision_job.rb
@@ -0,0 +1,49 @@
+require 'ruby_terraform'
+require 'git'
+require 'open3'
+
+class GovukGuix::FetchRevisionJob < GovukGuix::Job
+ @retry_interval = 30
+
+ def run(commit_hash)
+ repository.fetch
+
+ repository.checkout(commit_hash)
+
+ command = [
+ "#{repository_directory}/guix-pre-inst-env",
+ "guix",
+ "build",
+ "-e",
+ "(begin (use-modules (gds packages govuk)) (current-govuk-guix))"
+ ]
+
+ run_command(command) do |output|
+ store_path = output.last.strip
+ logger.debug("FetchRevisionJob: store_path: #{store_path}")
+
+ GovukGuix::Revision.create(
+ commit_hash: commit_hash,
+ store_path: store_path
+ )
+ end
+ end
+
+ def repository
+ @_repository ||= begin
+ if File.exists? repository_directory
+ Git.open(repository_directory, :log => Rails.logger)
+ else
+ Git.clone(repository_remote_location, repository_directory)
+ end
+ end
+ end
+
+ def repository_directory
+ 'tmp/cache/govuk-guix'
+ end
+
+ def repository_remote_location
+ 'git@git.cbaines.net:gds/govuk-guix'
+ end
+end