Merge pull request #916 from nickhammond/buildpacks
Add pack option to the builder options for cloud native buildpacks
This commit is contained in:
@@ -84,6 +84,10 @@ module Kamal::Commands
|
||||
args.compact.unshift :docker
|
||||
end
|
||||
|
||||
def pack(*args)
|
||||
args.compact.unshift :pack
|
||||
end
|
||||
|
||||
def git(*args, path: nil)
|
||||
[ :git, *([ "-C", path ] if path), *args.compact ]
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@ require "active_support/core_ext/string/filters"
|
||||
|
||||
class Kamal::Commands::Builder < Kamal::Commands::Base
|
||||
delegate :create, :remove, :dev, :push, :clean, :pull, :info, :inspect_builder, :validate_image, :first_mirror, to: :target
|
||||
delegate :local?, :remote?, :cloud?, to: "config.builder"
|
||||
delegate :local?, :remote?, :pack?, :cloud?, to: "config.builder"
|
||||
|
||||
include Clone
|
||||
|
||||
@@ -17,6 +17,8 @@ class Kamal::Commands::Builder < Kamal::Commands::Base
|
||||
else
|
||||
remote
|
||||
end
|
||||
elsif pack?
|
||||
pack
|
||||
elsif cloud?
|
||||
cloud
|
||||
else
|
||||
@@ -36,6 +38,10 @@ class Kamal::Commands::Builder < Kamal::Commands::Base
|
||||
@hybrid ||= Kamal::Commands::Builder::Hybrid.new(config)
|
||||
end
|
||||
|
||||
def pack
|
||||
@pack ||= Kamal::Commands::Builder::Pack.new(config)
|
||||
end
|
||||
|
||||
def cloud
|
||||
@cloud ||= Kamal::Commands::Builder::Cloud.new(config)
|
||||
end
|
||||
|
||||
@@ -6,6 +6,7 @@ class Kamal::Commands::Builder::Base < Kamal::Commands::Base
|
||||
delegate :argumentize, to: Kamal::Utils
|
||||
delegate \
|
||||
:args, :secrets, :dockerfile, :target, :arches, :local_arches, :remote_arches, :remote,
|
||||
:pack?, :pack_builder, :pack_buildpacks,
|
||||
:cache_from, :cache_to, :ssh, :provenance, :sbom, :driver, :docker_driver?,
|
||||
to: :builder_config
|
||||
|
||||
|
||||
46
lib/kamal/commands/builder/pack.rb
Normal file
46
lib/kamal/commands/builder/pack.rb
Normal file
@@ -0,0 +1,46 @@
|
||||
class Kamal::Commands::Builder::Pack < Kamal::Commands::Builder::Base
|
||||
def push(export_action = "registry")
|
||||
combine \
|
||||
build,
|
||||
export(export_action)
|
||||
end
|
||||
|
||||
def remove;end
|
||||
|
||||
def info
|
||||
pack :builder, :inspect, pack_builder
|
||||
end
|
||||
alias_method :inspect_builder, :info
|
||||
|
||||
private
|
||||
def build
|
||||
pack(:build,
|
||||
config.repository,
|
||||
"--platform", platform,
|
||||
"--creation-time", "now",
|
||||
"--builder", pack_builder,
|
||||
buildpacks,
|
||||
"-t", config.absolute_image,
|
||||
"-t", config.latest_image,
|
||||
"--env", "BP_IMAGE_LABELS=service=#{config.service}",
|
||||
*argumentize("--env", args),
|
||||
*argumentize("--env", secrets, sensitive: true),
|
||||
"--path", build_context)
|
||||
end
|
||||
|
||||
def export(export_action)
|
||||
return unless export_action == "registry"
|
||||
|
||||
combine \
|
||||
docker(:push, config.absolute_image),
|
||||
docker(:push, config.latest_image)
|
||||
end
|
||||
|
||||
def platform
|
||||
"linux/#{local_arches.first}"
|
||||
end
|
||||
|
||||
def buildpacks
|
||||
(pack_buildpacks << "paketo-buildpacks/image-labels").map { |buildpack| [ "--buildpack", buildpack ] }
|
||||
end
|
||||
end
|
||||
@@ -61,6 +61,10 @@ class Kamal::Configuration::Builder
|
||||
!!builder_config["cache"]
|
||||
end
|
||||
|
||||
def pack?
|
||||
!!builder_config["pack"]
|
||||
end
|
||||
|
||||
def args
|
||||
builder_config["args"] || {}
|
||||
end
|
||||
@@ -85,6 +89,14 @@ class Kamal::Configuration::Builder
|
||||
builder_config.fetch("driver", "docker-container")
|
||||
end
|
||||
|
||||
def pack_builder
|
||||
builder_config["pack"]["builder"] if pack?
|
||||
end
|
||||
|
||||
def pack_buildpacks
|
||||
builder_config["pack"]["buildpacks"] if pack?
|
||||
end
|
||||
|
||||
def local_disabled?
|
||||
builder_config["local"] == false
|
||||
end
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#
|
||||
# Options go under the builder key in the root configuration.
|
||||
builder:
|
||||
|
||||
# Arch
|
||||
#
|
||||
# The architectures to build for — you can set an array or just a single value.
|
||||
@@ -31,6 +30,19 @@ builder:
|
||||
# Defaults to true:
|
||||
local: true
|
||||
|
||||
# Buildpack configuration
|
||||
#
|
||||
# The build configuration for using pack to build a Cloud Native Buildpack image.
|
||||
#
|
||||
# For additional buildpack customization options you can create a project descriptor
|
||||
# file(project.toml) that the Pack CLI will automatically use.
|
||||
# See https://buildpacks.io/docs/for-app-developers/how-to/build-inputs/use-project-toml/ for more information.
|
||||
pack:
|
||||
builder: heroku/builder:24
|
||||
buildpacks:
|
||||
- heroku/ruby
|
||||
- heroku/procfile
|
||||
|
||||
# Builder cache
|
||||
#
|
||||
# The type must be either 'gha' or 'registry'.
|
||||
|
||||
@@ -8,6 +8,8 @@ class Kamal::Configuration::Validator::Builder < Kamal::Configuration::Validator
|
||||
|
||||
error "Builder arch not set" unless config["arch"].present?
|
||||
|
||||
error "buildpacks only support building for one arch" if config["pack"] && config["arch"].is_a?(Array) && config["arch"].size > 1
|
||||
|
||||
error "Cannot disable local builds, no remote is set" if config["local"] == false && config["remote"].blank?
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user