Skip to content

Commit b377e25

Browse files
authored
Use struct API when setting default envs (#344)
* Switch to struct API * Remove unused import * Remove deprecation allowance
1 parent f21dfcc commit b377e25

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

buildpacks/ruby/src/steps/default_env.rs

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{RubyBuildpack, RubyBuildpackError};
2-
use commons::layer::DefaultEnvLayer;
2+
use libcnb::layer::UncachedLayerDefinition;
3+
use libcnb::layer_env::{LayerEnv, ModificationBehavior};
34
use libcnb::{
45
build::BuildContext,
56
data::{layer_name, store::Store},
@@ -9,7 +10,6 @@ use libcnb::{
910
use rand::Rng;
1011

1112
// Set default environment values
12-
#[allow(deprecated)]
1313
pub(crate) fn default_env(
1414
context: &BuildContext<RubyBuildpack>,
1515
platform_env: &Env,
@@ -24,25 +24,32 @@ pub(crate) fn default_env(
2424
}
2525

2626
let (default_secret_key_base, store) = fetch_secret_key_base_from_store(&context.store);
27-
28-
let env_defaults_layer = context //
29-
.handle_layer(
30-
layer_name!("env_defaults"),
31-
DefaultEnvLayer::new(
32-
[
33-
("SECRET_KEY_BASE", default_secret_key_base.as_str()),
34-
("JRUBY_OPTS", "-Xcompile.invokedynamic=false"),
35-
("RACK_ENV", "production"),
36-
("RAILS_ENV", "production"),
37-
("RAILS_SERVE_STATIC_FILES", "enabled"),
38-
("RAILS_LOG_TO_STDOUT", "enabled"),
39-
("MALLOC_ARENA_MAX", "2"),
40-
("DISABLE_SPRING", "1"),
41-
]
42-
.into_iter(),
43-
),
44-
)?;
45-
env = env_defaults_layer.env.apply(Scope::Build, &env);
27+
let layer_ref = context.uncached_layer(
28+
layer_name!("env_defaults"),
29+
UncachedLayerDefinition {
30+
build: true,
31+
launch: true,
32+
},
33+
)?;
34+
let env = layer_ref
35+
.write_env({
36+
[
37+
("SECRET_KEY_BASE", default_secret_key_base.as_str()),
38+
("JRUBY_OPTS", "-Xcompile.invokedynamic=false"),
39+
("RACK_ENV", "production"),
40+
("RAILS_ENV", "production"),
41+
("RAILS_SERVE_STATIC_FILES", "enabled"),
42+
("RAILS_LOG_TO_STDOUT", "enabled"),
43+
("MALLOC_ARENA_MAX", "2"),
44+
("DISABLE_SPRING", "1"),
45+
]
46+
.iter()
47+
.fold(LayerEnv::new(), |layer_env, (name, value)| {
48+
layer_env.chainable_insert(Scope::All, ModificationBehavior::Default, name, value)
49+
})
50+
})
51+
.and_then(|()| layer_ref.read_env())?
52+
.apply(Scope::Build, &env);
4653

4754
Ok((env, store))
4855
}

0 commit comments

Comments
 (0)