From 01dc6aaf0b65301d37d26909901fe51629c8823f Mon Sep 17 00:00:00 2001 From: Schneems Date: Wed, 30 Oct 2024 12:35:51 -0500 Subject: [PATCH 1/3] Switch to struct API --- buildpacks/ruby/src/steps/default_env.rs | 47 ++++++++++++++---------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/buildpacks/ruby/src/steps/default_env.rs b/buildpacks/ruby/src/steps/default_env.rs index fa7b4b51..b5679dcc 100644 --- a/buildpacks/ruby/src/steps/default_env.rs +++ b/buildpacks/ruby/src/steps/default_env.rs @@ -1,5 +1,7 @@ use crate::{RubyBuildpack, RubyBuildpackError}; use commons::layer::DefaultEnvLayer; +use libcnb::layer::UncachedLayerDefinition; +use libcnb::layer_env::{LayerEnv, ModificationBehavior}; use libcnb::{ build::BuildContext, data::{layer_name, store::Store}, @@ -24,25 +26,32 @@ pub(crate) fn default_env( } let (default_secret_key_base, store) = fetch_secret_key_base_from_store(&context.store); - - let env_defaults_layer = context // - .handle_layer( - layer_name!("env_defaults"), - DefaultEnvLayer::new( - [ - ("SECRET_KEY_BASE", default_secret_key_base.as_str()), - ("JRUBY_OPTS", "-Xcompile.invokedynamic=false"), - ("RACK_ENV", "production"), - ("RAILS_ENV", "production"), - ("RAILS_SERVE_STATIC_FILES", "enabled"), - ("RAILS_LOG_TO_STDOUT", "enabled"), - ("MALLOC_ARENA_MAX", "2"), - ("DISABLE_SPRING", "1"), - ] - .into_iter(), - ), - )?; - env = env_defaults_layer.env.apply(Scope::Build, &env); + let layer_ref = context.uncached_layer( + layer_name!("env_defaults"), + UncachedLayerDefinition { + build: true, + launch: true, + }, + )?; + let env = layer_ref + .write_env({ + [ + ("SECRET_KEY_BASE", default_secret_key_base.as_str()), + ("JRUBY_OPTS", "-Xcompile.invokedynamic=false"), + ("RACK_ENV", "production"), + ("RAILS_ENV", "production"), + ("RAILS_SERVE_STATIC_FILES", "enabled"), + ("RAILS_LOG_TO_STDOUT", "enabled"), + ("MALLOC_ARENA_MAX", "2"), + ("DISABLE_SPRING", "1"), + ] + .iter() + .fold(LayerEnv::new(), |layer_env, (name, value)| { + layer_env.chainable_insert(Scope::All, ModificationBehavior::Default, name, value) + }) + }) + .and_then(|()| layer_ref.read_env())? + .apply(Scope::Build, &env); Ok((env, store)) } From bfe31afa278462fde20994a30735ec9d40b73f5a Mon Sep 17 00:00:00 2001 From: Schneems Date: Wed, 30 Oct 2024 12:36:13 -0500 Subject: [PATCH 2/3] Remove unused import --- buildpacks/ruby/src/steps/default_env.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/buildpacks/ruby/src/steps/default_env.rs b/buildpacks/ruby/src/steps/default_env.rs index b5679dcc..e5cf82c8 100644 --- a/buildpacks/ruby/src/steps/default_env.rs +++ b/buildpacks/ruby/src/steps/default_env.rs @@ -1,5 +1,4 @@ use crate::{RubyBuildpack, RubyBuildpackError}; -use commons::layer::DefaultEnvLayer; use libcnb::layer::UncachedLayerDefinition; use libcnb::layer_env::{LayerEnv, ModificationBehavior}; use libcnb::{ From b74d649b3fc038c909c6fe946484dafdc4ed4b32 Mon Sep 17 00:00:00 2001 From: Schneems Date: Wed, 30 Oct 2024 12:36:19 -0500 Subject: [PATCH 3/3] Remove deprecation allowance --- buildpacks/ruby/src/steps/default_env.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/buildpacks/ruby/src/steps/default_env.rs b/buildpacks/ruby/src/steps/default_env.rs index e5cf82c8..473770ba 100644 --- a/buildpacks/ruby/src/steps/default_env.rs +++ b/buildpacks/ruby/src/steps/default_env.rs @@ -10,7 +10,6 @@ use libcnb::{ use rand::Rng; // Set default environment values -#[allow(deprecated)] pub(crate) fn default_env( context: &BuildContext, platform_env: &Env,