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 unified Heroku buildpack output style #745

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
68 changes: 68 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,71 @@ jobs:
working-directory: ${{ matrix.buildpack-directory }}
# Runs only tests annotated with the `ignore` attribute (which in this repo, are the integration tests).
run: cargo test --locked -- --ignored --test-threads 16

print-pack-getting-started-output:
runs-on: ${{ matrix.target == 'aarch64-unknown-linux-musl' && 'pub-hk-ubuntu-24.04-arm-medium' || 'ubuntu-24.04' }}
strategy:
matrix:
target: ["aarch64-unknown-linux-musl", "x86_64-unknown-linux-musl"]
guide: ["heroku/java-getting-started", "heroku/gradle-getting-started", "heroku/scala-getting-started"]
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
- name: Install musl-tools
run: sudo apt-get install -y --no-install-recommends musl-tools
- name: Update Rust toolchain
run: rustup update
- name: Install Rust linux-musl target
run: rustup target add ${{ matrix.target }}
- name: Rust Cache
uses: Swatinem/[email protected]
- name: Install Pack CLI
uses: buildpacks/github-actions/[email protected]
- name: Pull builder and run images
run: |
docker pull "heroku/builder:24"
docker pull "heroku/heroku:24"
- name: Clone getting started guide
uses: actions/checkout@v4
with:
repository: ${{ matrix.guide }}
path: tmp/guide
- name: Install libcnb-cargo for `cargo libcnb package` command
run: cargo install libcnb-cargo
- name: Compile buildpack
run: cargo libcnb package --target ${{ matrix.target }}
- name: "PRINT: Getting started guide output"
run: |
set -euo pipefail

PACK_CMD="pack build my-image --force-color --builder heroku/builder:24 --trust-extra-buildpacks --path tmp/guide --pull-policy never "
case "${{ matrix.guide }}" in
"heroku/java-getting-started")
PACK_CMD+=" --buildpack packaged/${{ matrix.target }}/debug/heroku_jvm "
PACK_CMD+=" --buildpack packaged/${{ matrix.target }}/debug/heroku_java "
PACK_CMD+=" --buildpack packaged/${{ matrix.target }}/debug/heroku_maven "
;;
"heroku/gradle-getting-started")
PACK_CMD+=" --buildpack packaged/${{ matrix.target }}/debug/heroku_jvm "
PACK_CMD+=" --buildpack packaged/${{ matrix.target }}/debug/heroku_gradle "
;;
"heroku/scala-getting-started")
PACK_CMD+=" --buildpack packaged/${{ matrix.target }}/debug/heroku_jvm "
PACK_CMD+=" --buildpack packaged/${{ matrix.target }}/debug/heroku_sbt "
PACK_CMD+=" --buildpack packaged/${{ matrix.target }}/debug/heroku_scala "
;;
*)
echo "Unknown guide: ${{ matrix.guide }}"
exit 1
;;
esac

echo "Running command: $PACK_CMD"
bash -c "$PACK_CMD"
echo ""
echo "With CACHE example"
echo ""
bash -c "$PACK_CMD"
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ This buildpack relies on [heroku/libcnb.rs][libcnb] to compile buildpacks. All
[libcnb.rs dependencies][libcnb-deps] will need to be setup prior to building
or testing this buildpack.

### Clone

This project uses submodules, to clone all code run:

```
$ git clone --recursive https://github.com/heroku/buildpacks-jvm
```

### Building

1. Run `cargo check` to download dependencies and ensure there are no
Expand Down
2 changes: 1 addition & 1 deletion buildpacks/gradle/src/gradle_command/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) fn start(
) -> Result<(), GradleCommandError<()>> {
let output = Command::new(gradle_wrapper_executable_path)
.args([
// Fixes an issue when when running under Apple Rosetta emulation
// Fixes an issue when running under Apple Rosetta emulation
"-Djdk.lang.Process.launchMechanism=vfork",
"--daemon",
GRADLE_TASK_NAME_HEROKU_START_DAEMON,
Expand Down
36 changes: 25 additions & 11 deletions buildpacks/gradle/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use crate::gradle_command::GradleCommandError;
use crate::layers::gradle_home::handle_gradle_home_layer;
use crate::GradleBuildpackError::{GradleBuildIoError, GradleBuildUnexpectedStatusError};
use buildpacks_jvm_shared as shared;
use buildpacks_jvm_shared::output::{
print_buildpack_name, print_section, print_subsection, track_timing,
};
#[cfg(test)]
use buildpacks_jvm_shared_test as _;
use libcnb::build::{BuildContext, BuildResult, BuildResultBuilder};
Expand Down Expand Up @@ -75,7 +78,8 @@ impl Buildpack for GradleBuildpack {
}

fn build(&self, context: BuildContext<Self>) -> libcnb::Result<BuildResult, Self::Error> {
log_header("Gradle Buildpack");
print_buildpack_name("Heroku Gradle Buildpack");

let buildpack_config = GradleBuildpackConfig::from(&context);

let gradle_wrapper_executable_path = Some(context.app_dir.join("gradlew"))
Expand All @@ -88,16 +92,26 @@ impl Buildpack for GradleBuildpack {
let mut gradle_env = Env::from_current();
handle_gradle_home_layer(&context, &mut gradle_env)?;

log_header("Starting Gradle Daemon");
gradle_command::start_daemon(&gradle_wrapper_executable_path, &gradle_env)
.map_err(GradleBuildpackError::StartGradleDaemonError)?;

let project_tasks = gradle_command::tasks(&context.app_dir, &gradle_env)
.map_err(|command_error| command_error.map_parse_error(|_| ()))
.map_err(GradleBuildpackError::GetTasksError)?;

let dependency_report = gradle_command::dependency_report(&context.app_dir, &gradle_env)
.map_err(GradleBuildpackError::GetDependencyReportError)?;
print_section("Running Gradle build");

track_timing(|| {
print_subsection("Starting Gradle daemon");
gradle_command::start_daemon(&gradle_wrapper_executable_path, &gradle_env)
.map_err(GradleBuildpackError::StartGradleDaemonError)
})?;

let project_tasks = track_timing(|| {
print_subsection("Querying tasks");
gradle_command::tasks(&context.app_dir, &gradle_env)
.map_err(|command_error| command_error.map_parse_error(|_| ()))
.map_err(GradleBuildpackError::GetTasksError)
})?;

let dependency_report = track_timing(|| {
print_subsection("Querying dependency report");
gradle_command::dependency_report(&context.app_dir, &gradle_env)
.map_err(GradleBuildpackError::GetDependencyReportError)
})?;

let task_name = buildpack_config
.gradle_task
Expand Down
5 changes: 5 additions & 0 deletions buildpacks/jvm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- JDK overlays are now properly sourced from the `.jdk-overlay` directory instead of `.jdk_overlay`. ([#763](https://github.com/heroku/buildpacks-jvm/pull/763))

### Changed

- Buildpack output changed to a new format. ([#000](https://github.com/heroku/buildpacks-jvm/pull/000))

## [6.0.4] - 2024-12-05

### Added
Expand All @@ -24,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Default version for **OpenJDK 17** is now `17.0.13`. ([#747](https://github.com/heroku/buildpacks-jvm/pull/747))
- Default version for **OpenJDK 21** is now `21.0.5`. ([#747](https://github.com/heroku/buildpacks-jvm/pull/747))
- Default version for **OpenJDK 23** is now `23.0.1`. ([#747](https://github.com/heroku/buildpacks-jvm/pull/747))
- Buildpack output changed to a new format. ([#745](https://github.com/heroku/buildpacks-jvm/pull/745))

## [6.0.3] - 2024-09-26

Expand Down
65 changes: 40 additions & 25 deletions buildpacks/jvm/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::openjdk_artifact::HerokuOpenJdkVersionRequirement;
use crate::{OpenJdkArtifactRequirementParseError, OpenJdkBuildpackError};
use crate::openjdk_artifact::{
HerokuOpenJdkVersionRequirement, OpenJdkArtifactRequirementParseError,
};
use crate::version_resolver::VersionResolveError;
use crate::OpenJdkBuildpackError;
use buildpacks_jvm_shared::log::{log_please_try_again, log_please_try_again_error};
use buildpacks_jvm_shared::system_properties::ReadSystemPropertiesError;
use indoc::formatdoc;
Expand All @@ -8,19 +11,6 @@ use libherokubuildpack::log::log_error;
#[allow(clippy::too_many_lines)]
pub(crate) fn on_error_jvm_buildpack(error: OpenJdkBuildpackError) {
match error {
OpenJdkBuildpackError::OpenJdkArtifactRequirementParseError(OpenJdkArtifactRequirementParseError::UnknownDistribution(distribution)) => log_error(
format!("Unsupported distribution: {distribution}"),
formatdoc! {"
Please check your system.properties file to ensure the java.runtime.version
string does not contain an unsupported distribution prefix.

You can also remove the system.properties file from your application to install
the default OpenJDK version.

Thanks,
Heroku
"},
),
OpenJdkBuildpackError::CannotCreateOpenJdkTempDir(error) => log_please_try_again_error(
"Unexpected IO error",
"Could not create temporary directory for the OpenJDK download due to an unexpected I/O error.",
Expand Down Expand Up @@ -112,15 +102,6 @@ pub(crate) fn on_error_jvm_buildpack(error: OpenJdkBuildpackError) {
Details: {error}
", error = error },
),
OpenJdkBuildpackError::OpenJdkArtifactRequirementParseError(OpenJdkArtifactRequirementParseError::OpenJdkVersionParseError(error)) => log_error(
"Invalid OpenJDK version selector",
formatdoc! {"
The OpenJDK version selector you specified in your system.properties file is invalid.
Please specify a valid version selector in your system.properties file.

Details: {error}
", error = error },
),
OpenJdkBuildpackError::OpenJdkTarballChecksumError { expected, actual } => log_please_try_again(
"Corrupted OpenJDK download",
formatdoc! {"
Expand All @@ -129,6 +110,40 @@ pub(crate) fn on_error_jvm_buildpack(error: OpenJdkBuildpackError) {
Expected: {expected}
Actual: {actual}
", expected = hex::encode(expected), actual = hex::encode(actual) }
)
),
OpenJdkBuildpackError::ResolveVersionError(VersionResolveError::OpenJdkArtifactRequirementParseError(OpenJdkArtifactRequirementParseError::UnknownDistribution(distribution))) => log_error(
format!("Unsupported distribution: {distribution}"),
formatdoc! {"
Please check your system.properties file to ensure the java.runtime.version
string does not contain an unsupported distribution prefix.

You can also remove the system.properties file from your application to install
the default OpenJDK version.

Thanks,
Heroku
"}),
OpenJdkBuildpackError::ResolveVersionError(VersionResolveError::OpenJdkArtifactRequirementParseError(OpenJdkArtifactRequirementParseError::OpenJdkVersionParseError(_))) => {
log_error(
"Invalid OpenJDK version selector",
formatdoc! {"
The OpenJDK version selector you specified in your system.properties file is invalid.
Please specify a valid version selector in your system.properties file.

Details: {error:?}
", error = error },
);
}
OpenJdkBuildpackError::ResolveVersionError(VersionResolveError::ReadSystemPropertiesError(error)) => {
log_error(
"Invalid system.properties file",
formatdoc! {"
The contents of your system.properties file cannot be parsed. Please use a valid
system.properties file and try again.

Details: {error:?}
", error = error },
);
}
}
}
Loading