Class: Shiplane::ConvertDockerfile

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/shiplane/convert_dockerfile.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_folder, artifact_context, compose_context) ⇒ ConvertDockerfile

Returns a new instance of ConvertDockerfile.



10
11
12
13
14
# File 'lib/shiplane/convert_dockerfile.rb', line 10

def initialize(project_folder, artifact_context, compose_context)
  @project_folder = project_folder
  @artifact_context = artifact_context
  @compose_context = compose_context
end

Instance Attribute Details

#artifact_contextObject

Returns the value of attribute artifact_context.



6
7
8
# File 'lib/shiplane/convert_dockerfile.rb', line 6

def artifact_context
  @artifact_context
end

#compose_contextObject

Returns the value of attribute compose_context.



6
7
8
# File 'lib/shiplane/convert_dockerfile.rb', line 6

def compose_context
  @compose_context
end

#project_folderObject

Returns the value of attribute project_folder.



6
7
8
# File 'lib/shiplane/convert_dockerfile.rb', line 6

def project_folder
  @project_folder
end

Class Method Details

.convert_output!(project_folder, artifact_context, compose_context) ⇒ Object



56
57
58
# File 'lib/shiplane/convert_dockerfile.rb', line 56

def self.convert_output!(project_folder, artifact_context, compose_context)
  new(project_folder, artifact_context, compose_context).convert_output!
end

Instance Method Details

#appnameObject



16
17
18
# File 'lib/shiplane/convert_dockerfile.rb', line 16

def appname
  @appname ||= project_config['appname']
end

#convert_output!Object



50
51
52
53
54
# File 'lib/shiplane/convert_dockerfile.rb', line 50

def convert_output!
  puts "Converting Dockerfile..."
  File.write(dockerfile_filepath, converted_output)
  puts "Dockerfile Converted..."
end

#converted_outputObject



42
43
44
45
46
47
48
# File 'lib/shiplane/convert_dockerfile.rb', line 42

def converted_output
  @converted_output ||= [
    File.read(dockerfile_filepath),
    File.read(dockerfile_production_stages_filepath),
    # "ENTRYPOINT #{entrypoint}",
  ].join("\n\n")
end

#dockerfile_filepathObject



30
31
32
# File 'lib/shiplane/convert_dockerfile.rb', line 30

def dockerfile_filepath
  @dockerfile_filepath ||= File.join(project_folder, dockerfile_name)
end

#dockerfile_nameObject



24
25
26
27
28
# File 'lib/shiplane/convert_dockerfile.rb', line 24

def dockerfile_name
  @dockerfile_name ||= compose_context.fetch('build', {}).fetch('context', '.').tap do |filename|
    filename.gsub!(/^\.$/, 'Dockerfile')
  end
end

#dockerfile_production_stages_filepathObject



34
35
36
# File 'lib/shiplane/convert_dockerfile.rb', line 34

def dockerfile_production_stages_filepath
  @dockerfile_production_stages_filepath ||= File.join(Dir.pwd, build_config.fetch('settings_folder', '.shiplane'), Shiplane::DEFAULT_PRODUCTION_DOCKERFILE_STAGES_FILEPATH)
end

#entrypointObject



38
39
40
# File 'lib/shiplane/convert_dockerfile.rb', line 38

def entrypoint
  @entrypoint ||= artifact_context.fetch('command', compose_context.fetch('command', "bin/rails s"))
end

#shiplane_configObject



20
21
22
# File 'lib/shiplane/convert_dockerfile.rb', line 20

def shiplane_config
  @shiplane_config ||= Shiplane::Configuration.new
end