Skip to content

Commit

Permalink
Merge branch 'main' into schneems/layer-type-clone
Browse files Browse the repository at this point in the history
  • Loading branch information
edmorley authored Sep 22, 2023
2 parents ede048a + 7f64bf2 commit 3b63ca5
Show file tree
Hide file tree
Showing 77 changed files with 648 additions and 356 deletions.
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/target/
/packaged/
target/
.DS_Store
.idea

# Since libcnb.rs is a library, we don't commit the lockfile so that CI tests the latest
# in-range dependencies, which is what users will use when installing from scratch.
Cargo.lock
**/fixtures/*/target/
**/fixtures/*/packaged/

# The default output directory of `cargo libcnb package`.
packaged/
15 changes: 11 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- `libcnb`:
- `LayerTypes` now implements `Copy` and `Clone`. ([#670](https://github.com/heroku/libcnb.rs/pull/670)).
- `libcnb-data`:
- `ExecDProgramOutputKey`, `ProcessType`, `LayerName`, `BuildpackId` and `StackId` now implement `Ord` and `PartialOrd`. ([#658](https://github.com/heroku/libcnb.rs/pull/658))
- Add `generic::GenericMetadata` as a generic metadata type. Also makes it the default for `BuildpackDescriptor`, `SingleBuildpackDescriptor`, `MetaBuildpackDescriptor` and `LayerContentMetadata`. ([#664](https://github.com/heroku/libcnb.rs/pull/664))
- `libcnb`:
- Struct `LayerTypes` now implements `Copy` and `Clone`. This allows injection of layer types into the struct implementing the `Layer` trait ([#670](https://github.com/heroku/libcnb.rs/pull/670)).
- Added `generic::GenericMetadata` as a generic metadata type. Also makes it the default for `BuildpackDescriptor`, `SingleBuildpackDescriptor`, `CompositeBuildpackDescriptor` and `LayerContentMetadata`. ([#664](https://github.com/heroku/libcnb.rs/pull/664))
- `libcnb-test`:
- Added the `BuildpackReference::WorkspaceBuildpack` enum variant. This allows for the testing of any libcnb.rs or composite buildpack in the Cargo workspace, instead of only the buildpack of the current crate. **Note: The testing of composite buildpacks requires `pack` CLI version `>=0.30`.** ([#666](https://github.com/heroku/libcnb.rs/pull/666))

### Changed

- Renamed `libcnb-data`'s `Buildpackage` to `PackageDescriptor`. This required changes in many other names across multiple libcnb.rs crates for consistency. See the PR diff for details, but renames should be straightforward and unsurprising. ([#656](https://github.com/heroku/libcnb.rs/pull/656))
- `libcnb-data`:
- Renamed the `buildpackage` module to `package_descriptor`, and the `Buildpackage*` types within it to `PackageDescriptor*`. ([#656](https://github.com/heroku/libcnb.rs/pull/656))
- Renamed multiple types to match the new composite vs component buildpack [upstream terminology](https://github.com/buildpacks/spec/blob/main/buildpack.md#cnb-terminology). Renamed `SingleBuildpackDescriptor` to `ComponentBuildpackDescriptor`, `MetaBuildpackDescriptor` to `CompositeBuildpackDescriptor` and `BuildpackDescriptor::{Single,Meta}` to `BuildpackDescriptor::{Component,Composite}`. ([#682](https://github.com/heroku/libcnb.rs/pull/682))
- `libcnb-cargo`:
- No longer outputs paths for non-libcnb.rs and non-meta buildpacks. ([#657](https://github.com/heroku/libcnb.rs/pull/657))
- Build output for humans changed slightly, output intended for machines/scripting didn't change. ([#657](https://github.com/heroku/libcnb.rs/pull/657))
- When performing buildpack detection, standard ignore files (`.ignore` and `.gitignore`) will be respected. ([#673](https://github.com/heroku/libcnb.rs/pull/673))
- `libcnb-test`:
- Renamed `BuildpackReference::Crate` to `BuildpackReference::CurrentCrate`. ([#666](https://github.com/heroku/libcnb.rs/pull/666))

## [0.14.0] - 2023-08-18

Expand Down
34 changes: 18 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,14 @@ impl Buildpack for HelloWorldBuildpack {
BuildResultBuilder::new()
.launch(
LaunchBuilder::new().process(
ProcessBuilder::new(process_type!("web"), ["echo"])
.arg("Hello World!")
.default(true)
.build(),
)
.build(),
LaunchBuilder::new()
.process(
ProcessBuilder::new(process_type!("web"), ["echo"])
.arg("Hello World!")
.default(true)
.build(),
)
.build(),
)
.build()
}
Expand All @@ -178,22 +179,23 @@ In your project directory, run `cargo libcnb package` to start packaging:

```shell
$ cargo libcnb package
🔍 Locating buildpacks...
📦 [1/1] Building libcnb-examples/my-buildpack
Determining automatic cross-compile settings...
Building binaries (x86_64-unknown-linux-musl)...
🚚 Preparing package directory...
🖥️ Gathering Cargo configuration (for x86_64-unknown-linux-musl)
🏗️ Building buildpack dependency graph...
🔀 Determining build order...
🚚 Building 1 buildpacks...
📦 [1/1] Building libcnb-examples/my-buildpack (./)
# Omitting compilation output...
Finished dev [unoptimized] target(s) in 8.92s
Writing buildpack directory...
Successfully wrote buildpack directory: packaged/x86_64-unknown-linux-musl/debug/libcnb-examples_my-buildpack (4.06 MiB)
Finished dev [unoptimized] target(s) in 8.24s
Successfully wrote buildpack directory: packaged/x86_64-unknown-linux-musl/debug/libcnb-examples_my-buildpack (4.09 MiB)
✨ Packaging successfully finished!

💡 To test your buildpack locally with pack, run:
pack build my-image-name \
--buildpack /home/ponda.baba/my-buildpack/packaged/x86_64-unknown-linux-musl/debug/libcnb-examples_my-buildpack \
--buildpack packaged/x86_64-unknown-linux-musl/debug/libcnb-examples_my-buildpack \
--path /path/to/application

/home/ponda.baba/my-buildpack/packaged/x86_64-unknown-linux-musl/debug/libcnb-examples_my-buildpack
/Users/example/src/my-buildpack/packaged/x86_64-unknown-linux-musl/debug/libcnb-examples_my-buildpack
```

If you get errors with hints about how to install required tools to cross-compile from your host platform to the
Expand Down
2 changes: 1 addition & 1 deletion examples/execd/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use libcnb_test::{assert_contains, assert_empty, BuildConfig, TestRunner};
#[ignore = "integration test"]
fn basic() {
TestRunner::default().build(
BuildConfig::new("heroku/builder:22", "test-fixtures/empty-app"),
BuildConfig::new("heroku/builder:22", "tests/fixtures/empty-app"),
|context| {
let command_output = context.run_shell_command("env");
assert_empty!(command_output.stderr);
Expand Down
4 changes: 2 additions & 2 deletions examples/ruby-sample/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ impl Buildpack for RubyBuildpack {
LaunchBuilder::new()
.process(
ProcessBuilder::new(process_type!("web"), ["bundle"])
.args(vec!["exec", "ruby", "app.rb"])
.args(["exec", "ruby", "app.rb"])
.default(true)
.build(),
)
.process(
ProcessBuilder::new(process_type!("worker"), ["bundle"])
.args(vec!["exec", "ruby", "worker.rb"])
.args(["exec", "ruby", "worker.rb"])
.build(),
)
.build(),
Expand Down
6 changes: 3 additions & 3 deletions examples/ruby-sample/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::{fs, io};
#[test]
#[ignore = "integration test"]
fn basic() {
let config = BuildConfig::new("heroku/buildpacks:20", "test-fixtures/simple-ruby-app");
let config = BuildConfig::new("heroku/buildpacks:20", "tests/fixtures/simple-ruby-app");

TestRunner::default().build(&config, |context| {
assert_contains!(context.pack_stdout, "---> Ruby Buildpack");
Expand Down Expand Up @@ -60,7 +60,7 @@ fn basic() {
#[ignore = "integration test"]
fn missing_gemfile_lock() {
TestRunner::default().build(
BuildConfig::new("heroku/buildpacks:20", "test-fixtures/simple-ruby-app")
BuildConfig::new("heroku/buildpacks:20", "tests/fixtures/simple-ruby-app")
.app_dir_preprocessor(|path| fs::remove_file(path.join("Gemfile.lock")).unwrap())
.expected_pack_result(PackResult::Failure),
|context| {
Expand All @@ -80,7 +80,7 @@ where

stream.write_all(format!("{}\n", payload.as_ref()).as_bytes())?;

let mut buffer = vec![];
let mut buffer = Vec::new();
stream.read_to_end(&mut buffer)?;

Ok(String::from_utf8_lossy(&buffer).to_string())
Expand Down
45 changes: 34 additions & 11 deletions libcnb-cargo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,45 @@ $ cargo install libcnb-cargo

## Usage

Currently, there is only one sub-command: `package`. It allows users to package their Rust buildpack in a spec-compliant
manner and helps with cross-compilation. Using it is fairly simple, run `cargo libcnb package` inside the buildpack's
Currently, there is only one sub-command: `package`. It allows users to package their
Rust buildpack in a spec-compliant manner and helps with cross-compilation.

```shell
$ cargo libcnb package --help
Packages a libcnb.rs Cargo project as a Cloud Native Buildpack

Usage: cargo libcnb package [OPTIONS]

Options:
--no-cross-compile-assistance Disable cross-compile assistance
--release Build in release mode, with optimizations
--target <TARGET> Build for the target triple [default: x86_64-unknown-linux-musl]
--package-dir <PACKAGE_DIR> Directory for packaged buildpacks, defaults to 'packaged' in Cargo workspace root
-h, --help Print help
```
Using it is fairly simple, run `cargo libcnb package` inside the buildpack's
project directory:
```shell
$ cargo libcnb package
INFO - Reading buildpack metadata...
INFO - Found buildpack libcnb-examples/my-buildpack with version 0.1.0.
INFO - Determining automatic cross-compile settings...
INFO - Building binaries (x86_64-unknown-linux-musl)...
🚚 Preparing package directory...
🖥️ Gathering Cargo configuration (for x86_64-unknown-linux-musl)
🏗️ Building buildpack dependency graph...
🔀 Determining build order...
🚚 Building 1 buildpacks...
📦 [1/1] Building libcnb-examples/my-buildpack (./)
# Omitting compilation output...
Finished dev [unoptimized + debuginfo] target(s) in 4.29s
INFO - Writing buildpack directory...
INFO - Successfully wrote buildpack directory: target/buildpack/debug/libcnb-examples_my-buildpack (3.26 MiB)
INFO - Packaging successfully finished!
INFO - Hint: To test your buildpack locally with pack, run: pack build my-image --buildpack target/buildpack/debug/libcnb-examples_my-buildpack --path /path/to/application
Finished dev [unoptimized] target(s) in 8.24s
Successfully wrote buildpack directory: packaged/x86_64-unknown-linux-musl/debug/libcnb-examples_my-buildpack (4.09 MiB)
✨ Packaging successfully finished!
💡 To test your buildpack locally with pack, run:
pack build my-image-name \
--buildpack packaged/x86_64-unknown-linux-musl/debug/libcnb-examples_my-buildpack \
--path /path/to/application
/Users/example/src/my-buildpack/packaged/x86_64-unknown-linux-musl/debug/libcnb-examples_my-buildpack
```
[Latest Version]: https://img.shields.io/crates/v/libcnb-cargo.svg
Expand Down
9 changes: 4 additions & 5 deletions libcnb-cargo/src/package/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub(crate) fn execute(args: &PackageArgs) -> Result<(), Error> {

eprintln!("🖥️ Gathering Cargo configuration (for {})", args.target);
let cargo_build_env = if args.no_cross_compile_assistance {
vec![]
Vec::new()
} else {
match cross_compile_assistance(&args.target) {
CrossCompileAssistance::Configuration { cargo_env } => cargo_env,
Expand All @@ -51,7 +51,7 @@ pub(crate) fn execute(args: &PackageArgs) -> Result<(), Error> {
);
eprintln!("This is not an error, but without proper cross-compile settings in your Cargo manifest and locally installed toolchains, compilation might fail.");
eprintln!("To disable this warning, pass --no-cross-compile-assistance.");
vec![]
Vec::new()
}
CrossCompileAssistance::HelpText(help_text) => {
eprintln!("{help_text}");
Expand All @@ -61,9 +61,8 @@ pub(crate) fn execute(args: &PackageArgs) -> Result<(), Error> {
};

eprintln!("🏗️ Building buildpack dependency graph...");
let buildpack_dependency_graph =
build_libcnb_buildpacks_dependency_graph(&workspace_root_path, &[&package_dir])
.map_err(Error::CannotBuildBuildpackDependencyGraph)?;
let buildpack_dependency_graph = build_libcnb_buildpacks_dependency_graph(&workspace_root_path)
.map_err(Error::CannotBuildBuildpackDependencyGraph)?;

eprintln!("🔀 Determining build order...");
let root_nodes = buildpack_dependency_graph
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
api = "0.8"

[buildpack]
id = "multiple-buildpacks/meta-one"
name = "Meta-buildpack Test"
id = "multiple-buildpacks/composite-one"
name = "Composite Buildpack Test"
version = "0.0.0"
homepage = "https://example.com"
description = "Official test example"
Expand Down
Loading

0 comments on commit 3b63ca5

Please sign in to comment.