Skip to content

Commit

Permalink
Only inherit build plan entries targeting static-web-server (#21)
Browse files Browse the repository at this point in the history
* Only inherit build plan entries targetting static-web-server

* Update to newest heroku/nodejs
  • Loading branch information
mars authored Oct 21, 2024
1 parent 107390c commit 3c2d82c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
13 changes: 12 additions & 1 deletion buildpacks/static-web-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,18 @@ Other buildpacks can return a [Build Plan](https://github.com/buildpacks/spec/bl

Configuration defined in an app's `project.toml` takes precedence over this inherited Build Plan configuration.

This example sets a doc root & index, but any [configuration](#configuration) options are supported:
This example sets `root` & `index` in the build plan, using supported [configuration](#configuration) options:

```toml
[[requires]]
name = "static-web-server"

[requires.metadata]
root = "wwwroot"
index = "index.htm"
```

Example using [libcnb.rs](https://github.com/heroku/libcnb.rs):

```rust
fn detect(&self, context: DetectContext<Self>) -> libcnb::Result<DetectResult, Self::Error> {
Expand Down
10 changes: 6 additions & 4 deletions buildpacks/static-web-server/src/config_web_server.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::caddy_config::CaddyConfig;
use crate::heroku_web_server_config::HerokuWebServerConfig;
use crate::{StaticWebServerBuildpack, StaticWebServerBuildpackError};
use crate::{StaticWebServerBuildpack, StaticWebServerBuildpackError, BUILD_PLAN_ID};
use libcnb::data::layer_name;
use libcnb::layer::LayerRef;
use libcnb::{build::BuildContext, layer::UncachedLayerDefinition};
Expand All @@ -26,9 +26,11 @@ pub(crate) fn config_web_server(
// When a key is defined multiple times, the last one wins.
let mut build_plan_config = Table::new();
context.buildpack_plan.entries.iter().for_each(|e| {
e.metadata.iter().for_each(|(k, v)| {
build_plan_config.insert(k.to_owned(), v.to_owned());
});
if e.name == BUILD_PLAN_ID {
e.metadata.iter().for_each(|(k, v)| {
build_plan_config.insert(k.to_owned(), v.to_owned());
});
}
});

let project_config = read_project_config(context.app_dir.as_ref())
Expand Down
5 changes: 3 additions & 2 deletions buildpacks/static-web-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use test_support as _;
use ureq as _;

const BUILDPACK_NAME: &str = "Heroku Static Web Server Buildpack";
const BUILD_PLAN_ID: &str = "static-web-server";
const WEB_SERVER_NAME: &str = "caddy";
const WEB_SERVER_VERSION: &str = "2.8.4";

Expand All @@ -37,8 +38,8 @@ impl Buildpack for StaticWebServerBuildpack {

fn detect(&self, _context: DetectContext<Self>) -> libcnb::Result<DetectResult, Self::Error> {
let plan_builder = BuildPlanBuilder::new()
.provides("static-web-server")
.requires(Require::new("static-web-server"));
.provides(BUILD_PLAN_ID)
.requires(Require::new(BUILD_PLAN_ID));

DetectResultBuilder::pass()
.build_plan(plan_builder.build())
Expand Down
2 changes: 1 addition & 1 deletion meta-buildpacks/website-nodejs/buildpack.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type = "MIT"

[[order.group]]
id = "heroku/nodejs"
version = "3.2.13"
version = "3.2.15"

[[order.group]]
id = "heroku/static-web-server"
Expand Down

0 comments on commit 3c2d82c

Please sign in to comment.