Class: JetsGemLayer::TaskHelper

Inherits:
Object
  • Object
show all
Includes:
Jets::AwsServices, Rake::DSL
Defined in:
lib/jets_gem_layer/task_helper.rb

Constant Summary collapse

INPUT_FILES =

Files used to generate the gem layer

Rake::FileList.new(
  ['Gemfile', 'Gemfile.lock'].collect { |f| File.join(Jets.root, f) }
)
LOCAL_TMP_DIR =
'tmp/jets_gem_layer'
OUTPUT_DIR =
File.expand_path(File.join(Jets.root, "#{LOCAL_TMP_DIR}/"))

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.arnObject



19
20
21
# File 'lib/jets_gem_layer/task_helper.rb', line 19

def self.arn
  @arn ||= new.arn
end

.installObject



15
16
17
# File 'lib/jets_gem_layer/task_helper.rb', line 15

def self.install
  new.install
end

Instance Method Details

#arnObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jets_gem_layer/task_helper.rb', line 23

def arn
  # We do not want to do any of this when running in the lambda environment
  # as it is only required for deployment.
  @arn ||= if ENV['LAMBDA_TASK_ROOT']
             'no-op-while-running-in-lambda'
           else
             published_arn
           end

  @arn ||= 'no-matching-gem-layer-found'
end

#build_layerObject



76
77
78
79
80
# File 'lib/jets_gem_layer/task_helper.rb', line 76

def build_layer
  FileUtils.mkdir_p(inputs_dir)
  FileUtils.cp(INPUT_FILES.existing, inputs_dir)
  system(*docker_run_cmd) or raise
end

#installObject



35
36
37
38
39
40
41
42
# File 'lib/jets_gem_layer/task_helper.rb', line 35

def install
  namespace :gem_layer do
    install_build_and_publish
    install_build
    install_publish
    install_clean
  end
end

#install_buildObject



53
54
55
56
57
58
59
60
# File 'lib/jets_gem_layer/task_helper.rb', line 53

def install_build
  desc 'Build the gem layer zip file'
  task :build do
    Rake::Task['gem_layer:clean'].invoke
    build_layer
    zip_layer
  end
end

#install_build_and_publishObject



44
45
46
47
48
49
50
51
# File 'lib/jets_gem_layer/task_helper.rb', line 44

def install_build_and_publish
  desc 'Build and publish a gem layer version'
  task :build_and_publish do
    Rake::Task['gem_layer:build'].invoke
    Rake::Task['gem_layer:publish'].invoke
    Rake::Task['gem_layer:clean'].invoke
  end
end

#install_cleanObject



69
70
71
72
73
74
# File 'lib/jets_gem_layer/task_helper.rb', line 69

def install_clean
  desc 'Clean tmp files'
  task :clean do
    FileUtils.rm_r(working_dir) if File.exist?(working_dir)
  end
end

#install_publishObject



62
63
64
65
66
67
# File 'lib/jets_gem_layer/task_helper.rb', line 62

def install_publish
  desc 'Publish a built layer zip file'
  task :publish do
    publish_layer
  end
end

#publish_layerObject



93
94
95
96
97
98
99
100
# File 'lib/jets_gem_layer/task_helper.rb', line 93

def publish_layer
  aws_lambda.publish_layer_version(
    layer_name:, # required
    description: layer_version_description,
    content: { zip_file: File.read(zip_file_path) }
  )
  puts "#{layer_name} published for #{layer_version_description}..."
end

#zip_layerObject



82
83
84
85
86
87
88
89
90
91
# File 'lib/jets_gem_layer/task_helper.rb', line 82

def zip_layer
  pwd = Dir.pwd
  begin
    Dir.chdir(outputs_dir)
    system(*%W[zip -r #{File.join(working_dir, "#{layer_name}.zip")} lib ruby], out: File::NULL) or raise
    puts 'Layer zipped successfully...'
  ensure
    Dir.chdir(pwd)
  end
end