Class: BoringBuilder::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/boringbuilder/project.rb

Constant Summary collapse

DEFAULT_EXCLUDES =
%w[
  .env
  .env.*
  .bundle/cache
  .git
  coverage
  dist
  log
  node_modules
  tmp
  vendor/bundle
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Project

Returns a new instance of Project.



20
21
22
# File 'lib/boringbuilder/project.rb', line 20

def initialize(configuration)
  @configuration = configuration
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



18
19
20
# File 'lib/boringbuilder/project.rb', line 18

def configuration
  @configuration
end

Instance Method Details

#app_nameObject



48
49
50
# File 'lib/boringbuilder/project.rb', line 48

def app_name
  @app_name ||= root.basename.to_s.downcase.gsub(/[^a-z0-9]+/, "-").gsub(/\A-+|-+\z/, "")
end

#application_pathObject



93
94
95
# File 'lib/boringbuilder/project.rb', line 93

def application_path
  application.path
end

#application_userObject



97
98
99
# File 'lib/boringbuilder/project.rb', line 97

def application_user
  application.user
end

#artifactObject



121
122
123
124
125
126
127
128
# File 'lib/boringbuilder/project.rb', line 121

def artifact
  @artifact ||= begin
    configured = configuration.artifact
    add_configured_entries(configured)
    add_default_entries(configured) if configured.empty?
    configured
  end
end

#artifact_pathsObject



89
90
91
# File 'lib/boringbuilder/project.rb', line 89

def artifact_paths
  artifact.entries.filter_map { |entry| entry.source if entry.origin == :container }.map(&:to_s)
end

#assets?Boolean

Returns:

  • (Boolean)


77
78
79
80
81
# File 'lib/boringbuilder/project.rb', line 77

def assets?
  return configuration.assets unless configuration.assets.nil?

  root.join("app/assets").directory? || root.join("config/manifest.js").file?
end

#bootsnap?Boolean

Returns:

  • (Boolean)


83
84
85
86
87
# File 'lib/boringbuilder/project.rb', line 83

def bootsnap?
  return configuration.bootsnap unless configuration.bootsnap.nil?

  root.join("Gemfile.lock").read.match?(/^    bootsnap \(/)
end

#container(client, progress: DaggerRuby::Progress.silent) ⇒ Object



33
34
35
36
37
38
# File 'lib/boringbuilder/project.rb', line 33

def container(client, progress: DaggerRuby::Progress.silent)
  return Pipeline.new(self, client, progress: progress).build(&configuration.pipeline) if custom_pipeline?

  builder = rails? ? RailsBuild : RubyBuild
  builder.new(self, client, progress: progress).container
end

#custom_pipeline?Boolean

Returns:

  • (Boolean)


152
153
154
# File 'lib/boringbuilder/project.rb', line 152

def custom_pipeline?
  !configuration.pipeline.nil?
end

#frameworkObject



64
65
66
# File 'lib/boringbuilder/project.rb', line 64

def framework
  application.framework
end

#hanami?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/boringbuilder/project.rb', line 60

def hanami?
  application.hanami?
end

#locked?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/boringbuilder/project.rb', line 68

def locked?
  root.join("Gemfile.lock").file?
end

#output_pathObject



130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/boringbuilder/project.rb', line 130

def output_path
  return configuration.output if configuration.output

  suffix = {
    directory: "rootfs",
    tar: "tar",
    tar_zst: "tar.zst",
    oci: "oci.tar",
    docker: "docker.tar"
  }.fetch(configuration.format)
  platform = configuration.platform&.tr("/", "-") || "native"
  root.join("dist", "#{app_name}-#{platform}.#{suffix}")
end

#planObject



40
41
42
# File 'lib/boringbuilder/project.rb', line 40

def plan
  ProjectPlan.new(self).to_h
end

#rails?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/boringbuilder/project.rb', line 52

def rails?
  application.rails?
end

#rootObject



44
45
46
# File 'lib/boringbuilder/project.rb', line 44

def root
  configuration.root
end

#ruby?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/boringbuilder/project.rb', line 56

def ruby?
  application.ruby?
end

#ruby_versionObject



72
73
74
75
# File 'lib/boringbuilder/project.rb', line 72

def ruby_version
  @ruby_version ||= mise_ruby_version || tool_versions_ruby_version || ruby_version_file ||
                    gemfile_ruby_version || locked_ruby_version || RUBY_VERSION
end

#runtime_commandObject



105
106
107
# File 'lib/boringbuilder/project.rb', line 105

def runtime_command
  application.runtime_command
end

#runtime_entrypointObject



109
110
111
# File 'lib/boringbuilder/project.rb', line 109

def runtime_entrypoint
  application.runtime_entrypoint
end

#runtime_environmentObject



101
102
103
# File 'lib/boringbuilder/project.rb', line 101

def runtime_environment
  application.runtime_environment
end

#runtime_portObject



113
114
115
# File 'lib/boringbuilder/project.rb', line 113

def runtime_port
  application.runtime_port
end

#source(client) ⇒ Object



144
145
146
# File 'lib/boringbuilder/project.rb', line 144

def source(client)
  client.host.directory(root.to_s, exclude: DEFAULT_EXCLUDES, gitignore: true)
end

#source_file(client, path) ⇒ Object



148
149
150
# File 'lib/boringbuilder/project.rb', line 148

def source_file(client, path)
  client.host.file(root.join(path).to_s)
end

#validate!Object



24
25
26
27
28
29
30
31
# File 'lib/boringbuilder/project.rb', line 24

def validate!
  configuration.validate!
  validate_lockfile!
  validate_application!
  validate_native_javascript!
  Exporters::Resolver.new(self, nil).validate!
  self
end

#web?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/boringbuilder/project.rb', line 117

def web?
  application.web?
end