aboutsummaryrefslogtreecommitdiff
path: root/app/jobs/govuk_guix/fetch_revision_job.rb
blob: b1cb171a580a65ff22a374f60adb7dc73301b5ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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