Skip to content

Commit

Permalink
Remove experimental CNB support (#1464)
Browse files Browse the repository at this point in the history
The buildpack in this repo is primarily a classic Heroku buildpack,
however, as part of the initial exploration into CNBs had experimental
CNB support added some time ago.

However, the maintained Ruby CNB now exists in a separate repo:
https://github.com/heroku/buildpacks-ruby

The experimental CNB support in this repo doesn't actually work any more
since the buildpack API version it implements (v0.2) isn't supported by
modern `lifecycle` versions - and attempts at building encounter this
error:

```
ERROR: failed to set API for Buildpack 'heroku/ruby@0.1.4': buildpack API version '0.2' is incompatible with the lifecycle
```

In addition, it's not even possible to use this repo with a CNB build
without having cloned it locally, since:
1. The CNB parts are no longer published
2. The old CNB release assets were deleted a year or so ago:
   https://github.com/heroku/heroku-buildpack-ruby/releases
3. Pack/lifecycle doesn't support cloning Git URLs.
4. Attempting to use a buildpack URL pointing at the GitHub gzip archive
   fails due to GitHub's nesting of the repo inside a subdirectory:

```
$ pack build --builder heroku/builder:22 --buildpack https://github.com/heroku/heroku-buildpack-ruby/archive/refs/heads/main.tar.gz ruby-test
...
Downloading from https://github.com/heroku/heroku-buildpack-ruby/archive/refs/heads/main.tar.gz
93.2 KB/-1 B
ERROR: failed to build: downloading buildpack: extracting from https://github.com/heroku/heroku-buildpack-ruby/archive/refs/heads/main.tar.gz: reading buildpack: reading buildpack.toml: could not find entry path 'buildpack.toml': not exist
```

Given both the Buildpack API error, and the GitHub URL issues no one is
using the CNB implementation here, and so its dead code that should be
removed to prevent confusion (eg over where the CNB lives).

A deprecation warning was previously added in #1445 (though as above
it's unlikely anyone even saw that message, since the build was already
erroring before it gets that far).
  • Loading branch information
edmorley authored Jun 13, 2024
1 parent 8559194 commit a373fb3
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 481 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
- name: Run ShellCheck bin top level
run: |
shellcheck bin/support/bash_functions.sh bin/support/download_ruby -x &&
shellcheck bin/build bin/compile bin/detect bin/release bin/test bin/test-compile -x
shellcheck bin/compile bin/detect bin/release bin/test bin/test-compile -x
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

- Remove experimental CNB support. For official CNB support use [heroku/buildpacks-ruby](https://github.com/heroku/buildpacks-ruby) instead. (https://github.com/heroku/heroku-buildpack-ruby/pull/1464)

## [v271] - 2024-06-03

Expand Down
29 changes: 0 additions & 29 deletions bin/build

This file was deleted.

12 changes: 2 additions & 10 deletions bin/detect
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
#!/bin/sh

if [ -z "$CNB_STACK_ID" ]; then
# v2 API
APP_DIR=$1
else
_PLATFORM_DIR=$1
_PLAN=$2
# v3 API
APP_DIR=$(pwd)
fi
APP_DIR=$1

if [ -f "$APP_DIR/Gemfile" ]; then
echo "Ruby"
exit 0
else
exit 100
exit 1
fi
31 changes: 0 additions & 31 deletions bin/support/ruby_build

This file was deleted.

19 changes: 0 additions & 19 deletions buildpack.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
api = "0.2"

[buildpack]
id = "heroku/ruby"
version = "0.1.4"
name = "Ruby"
homepage = "https://github.com/heroku/heroku-buildpack-ruby"
ruby_version = "3.1.4"

[publish]
Expand All @@ -19,7 +14,6 @@ files = [
"app.json",
"hatchet.json",
"hatchet.lock",
"package.toml",
]

[[publish.Vendor]]
Expand All @@ -33,16 +27,3 @@ dir = "vendor/ruby/heroku-22"
[[publish.Vendor]]
url = "https://heroku-buildpack-ruby.s3.us-east-1.amazonaws.com/heroku-24/amd64/ruby-3.1.4.tgz"
dir = "vendor/ruby/amd64/heroku-24"

[[stacks]]
id = "heroku-20"

[[stacks]]
id = "heroku-22"

[metadata]

[metadata.release]

[metadata.release.docker]
repository = "public.ecr.aws/heroku-buildpacks/heroku-ruby-buildpack"
107 changes: 20 additions & 87 deletions lib/language_pack/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
require "language_pack/shell_helpers"
require "language_pack/cache"
require "language_pack/helpers/bundler_cache"
require "language_pack/helpers/layer"
require "language_pack/metadata"
require "language_pack/fetcher"

Expand All @@ -28,15 +27,14 @@ class LanguagePack::Base
# changes directory to the build_path
# @param [String] the path of the build dir
# @param [String] the path of the cache dir this is nil during detect and release
def initialize(build_path, cache_path = nil, layer_dir=nil)
def initialize(build_path, cache_path = nil)
@build_path = build_path
@stack = ENV.fetch("STACK")
@cache = LanguagePack::Cache.new(cache_path)
@metadata = LanguagePack::Metadata.new(@cache)
@bundler_cache = LanguagePack::BundlerCache.new(@cache, @stack)
@id = Digest::SHA1.hexdigest("#{Time.now.to_f}-#{rand(1000000)}")[0..10]
@fetchers = {:buildpack => LanguagePack::Fetcher.new(VENDOR_URL) }
@layer_dir = layer_dir
@arch = get_arch

Dir.chdir build_path
Expand Down Expand Up @@ -103,24 +101,6 @@ def compile
mcount "success"
end

def build
write_release_toml
Kernel.puts ""
warnings.each do |warning|
Kernel.puts "\e[1m\e[33m###### WARNING:\e[0m"# Bold yellow
Kernel.puts ""
puts warning
Kernel.puts ""
Kernel.puts ""
end
if deprecations.any?
topic "DEPRECATIONS:"
puts @deprecations.join("\n")
end
Kernel.puts ""
mcount "success"
end

def build_release
release = {}
release["addons"] = default_addons
Expand All @@ -130,29 +110,6 @@ def build_release
release
end

def write_release_toml
release = build_release

layer = LanguagePack::Helpers::Layer.new(@layer_dir, "env", launch: true)
FileUtils.mkdir_p("#{layer.path}/env.launch")
release["config_vars"].each do |key, value|
File.open("#{layer.path}/env.launch/#{key.upcase}.override", 'w') do |f|
f.write(value)
end
end

release_toml = release["default_process_types"].map do |type, command|
<<PROCESSES
[[processes]]
type = "#{type}"
command = "#{command}"
PROCESSES
end
File.open("#{@layer_dir}/launch.toml", 'a') do |f|
f.write(release_toml.join("\n"))
end
end

def write_release_yaml
release = build_release
FileUtils.mkdir("tmp") unless File.exists?("tmp")
Expand All @@ -163,11 +120,6 @@ def write_release_yaml
warn_webserver
end

# write out the release. Pick v2a or v3 release format
def write_release
@layer_dir ? write_release_toml : write_release_yaml
end

def warn_webserver
return if File.exist?("Procfile")
msg = "No Procfile detected, using the default web server.\n"
Expand Down Expand Up @@ -209,7 +161,7 @@ def setup_language_pack_environment
end

def add_to_profiled(string, filename: "ruby.sh", mode: "a")
profiled_path = @layer_dir ? "#{@layer_dir}/ruby/profile.d/" : "#{build_path}/.profile.d/"
profiled_path = "#{build_path}/.profile.d/"

FileUtils.mkdir_p profiled_path
File.open("#{profiled_path}/#{filename}", mode) do |file|
Expand All @@ -234,51 +186,32 @@ def add_to_export(string)

# option can be :path, :default, :override
# https://github.com/buildpacks/spec/blob/366ac1aa0be59d11010cc21aa06c16d81d8d43e7/buildpack.md#environment-variable-modification-rules
def export(key, val, layer: nil, option: nil)
if layer
# don't replace if the key is already set
return if ENV[key] && option == :default

filename =
if option.nil? || option == :path
key
elsif option == :default
"#{key}.override"
else
"#{key}.#{option}"
end

FileUtils.mkdir_p("#{layer.path}/env.build")
File.open("#{layer.path}/env.build/#{filename}", "w") do |f|
f.write(val)
end
else
string =
if option == :default
%{export #{key}="${#{key}:-#{val}}"}
elsif option == :path
%{export #{key}="#{val}:$#{key}"}
else
%{export #{key}="#{val.gsub('"','\"')}"}
end

export = File.join(ROOT_DIR, "export")
File.open(export, "a") do |file|
file.puts string
def export(key, val, option: nil)
string =
if option == :default
%{export #{key}="${#{key}:-#{val}}"}
elsif option == :path
%{export #{key}="#{val}:$#{key}"}
else
%{export #{key}="#{val.gsub('"','\"')}"}
end

export = File.join(ROOT_DIR, "export")
File.open(export, "a") do |file|
file.puts string
end
end

def set_export_default(key, val, layer = nil)
export key, val, layer: layer, option: :default
def set_export_default(key, val)
export key, val, option: :default
end

def set_export_override(key, val, layer = nil)
export key, val, layer: layer, option: :override
def set_export_override(key, val)
export key, val, option: :override
end

def set_export_path(key, val, layer = nil)
export key, val, layer: layer, option: :path
def set_export_path(key, val)
export key, val, option: :path
end

def log_internal(*args)
Expand Down
61 changes: 0 additions & 61 deletions lib/language_pack/helpers/layer.rb

This file was deleted.

6 changes: 0 additions & 6 deletions lib/language_pack/rails2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ def compile
super
end

def build
# TODO install plugins into separate layer
install_plugins
super
end

def best_practice_warnings
if env("RAILS_ENV") != "production"
warn(<<-WARNING)
Expand Down
Loading

0 comments on commit a373fb3

Please sign in to comment.