Class: OpenStax::Aws::BuildImageCommand1

Inherits:
Object
  • Object
show all
Defined in:
lib/openstax/aws/build_image_command_1.rb

Instance Method Summary collapse

Constructor Details

#initialize(ami_name_base:, region:, verbose: false, debug: false, github_org:, repo:, branch: nil, sha: nil, deployment_sha: nil, packer_absolute_file_path:, playbook_absolute_file_path:, dry_run: true) ⇒ BuildImageCommand1

A standardized way to use Packer to build images.



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
# File 'lib/openstax/aws/build_image_command_1.rb', line 7

def initialize(ami_name_base:, region:,
               verbose: false, debug: false,
               github_org:, repo:, branch: nil, sha: nil,
               deployment_sha: nil,
               packer_absolute_file_path: , playbook_absolute_file_path:,
               dry_run: true)
  if sha.nil?
    branch ||= 'master'

    sha = OpenStax::Aws::GitHelper.sha_for_branch_name(
            org_slash_repo: "#{github_org}/#{repo}",
            branch: branch
          )
  end

  ami_name = "#{ami_name_base}@#{sha[0..6]} #{Time.now.utc.strftime("%y%m%d%H%MZ")}"

  @packer = OpenStax::Aws::PackerFactory.new_packer(
    absolute_file_path: packer_absolute_file_path,
    dry_run: dry_run
  )

  @packer.only("amazon-ebs")

  @packer.var("region", region)
  @packer.var("ami_name", ami_name)
  @packer.var("sha", sha)
  @packer.var("deployment_sha", deployment_sha) unless deployment_sha.nil?
  @packer.var("playbook_file", playbook_absolute_file_path)
  @packer.var("ami_description", {
    sha: sha,
    deployment_sha: deployment_sha,
    github_org: github_org,
    repo: repo
  }.to_json)

  @packer.verbose! if verbose
  @packer.debug! if debug
end

Instance Method Details

#runObject



47
48
49
# File 'lib/openstax/aws/build_image_command_1.rb', line 47

def run
  @packer.run
end

#to_sObject



51
52
53
# File 'lib/openstax/aws/build_image_command_1.rb', line 51

def to_s
  @packer.to_s
end