Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use struct API when setting default envs #344

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions buildpacks/ruby/src/steps/default_env.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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},
Expand All @@ -9,7 +10,6 @@ use libcnb::{
use rand::Rng;

// Set default environment values
#[allow(deprecated)]
pub(crate) fn default_env(
context: &BuildContext<RubyBuildpack>,
platform_env: &Env,
Expand All @@ -24,25 +24,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))
}
Expand Down