Class: LambdaLayerCake::RakeHelper

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/moonbase_alpha/rake_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ RakeHelper

Returns a new instance of RakeHelper.



7
8
9
# File 'lib/moonbase_alpha/rake_helper.rb', line 7

def initialize(root)
  @root = root
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



5
6
7
# File 'lib/moonbase_alpha/rake_helper.rb', line 5

def root
  @root
end

Instance Method Details

#build_versionObject



48
49
50
51
52
53
# File 'lib/moonbase_alpha/rake_helper.rb', line 48

def build_version
  @build_version ||= begin
    t = Time.now
    "build-#{t.strftime("%Y-%m-%d-%H-%M-%S")}"
  end
end

#configObject



40
41
42
# File 'lib/moonbase_alpha/rake_helper.rb', line 40

def config
  Rails.configuration.moonbase_alpha
end

#docker_build_definitions!Object



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
# File 'lib/moonbase_alpha/rake_helper.rb', line 11

def docker_build_definitions!
  desc "Build Docker Image"
  task :build do
    dockerfile_path = File.expand_path(__dir__ + "/../../templates/Dockerfile")

    raise "Must specify a repository in moonbase_alpha.yml" if repository.blank?

    tag = "#{repository}:#{build_version}"

    cmd = %W{docker build -f #{dockerfile_path} 
      --build-arg RUNTIME_VERSION=#{RUBY_VERSION} 
      --build-arg BLDTIME_PKGS=#{config.build_packages.join(" ")}
      --build-arg COMPILE_ASSETS=#{config.compile_assets.to_s}
      -t #{tag}
      #{root}}
    system(*cmd) or raise 
  end

  desc "Output the last version built"
  task :latest_tag do
    puts latest_tag
  end

  desc "Output the image name for the latest build"
  task :latest_image do
    puts "#{repository}:#{latest_tag}"
  end
end

#latest_tagObject



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/moonbase_alpha/rake_helper.rb', line 55

def latest_tag
  @latest_tag ||= begin
    cmd = %W{ 
      docker image list
      --format {{.Tag}}
      #{repository}
    }

    IO.popen(cmd) do |versions|
      versions.readlines.select {|v| v =~ /\Abuild-/ }.sort.last
    end
  end
end

#repositoryObject



44
45
46
# File 'lib/moonbase_alpha/rake_helper.rb', line 44

def repository
  config.repository
end