diff --git a/.gitmodules b/.gitmodules index 5c5e4bbb..4f92e27e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,7 @@ [submodule "buildpacks/gradle/test-apps/heroku-gradle-getting-started"] path = buildpacks/gradle/test-apps/heroku-gradle-getting-started url = https://github.com/heroku/gradle-getting-started.git + +[submodule "buildpacks/leiningen/test-apps/heroku-clojure-getting-started"] + path = buildpacks/leiningen/test-apps/heroku-clojure-getting-started + url = https://github.com/heroku/clojure-getting-started.git diff --git a/Cargo.lock b/Cargo.lock index e24d5be1..eb65e82b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -456,6 +456,25 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "leiningen" +version = "0.0.0" +dependencies = [ + "buildpacks-jvm-shared", + "buildpacks-jvm-shared-test", + "indoc", + "java-properties", + "libcnb", + "libcnb-test", + "libherokubuildpack", + "semver", + "serde", + "shell-words", + "tempfile", + "thiserror", + "ureq", +] + [[package]] name = "libc" version = "0.2.147" diff --git a/Cargo.toml b/Cargo.toml index 0f56647c..d0fd0800 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ members = [ "buildpacks/gradle", "buildpacks/jvm", "buildpacks/jvm-function-invoker", + "buildpacks/leiningen", "buildpacks/maven", "buildpacks/sbt", "shared", diff --git a/buildpacks/leiningen/CHANGELOG.md b/buildpacks/leiningen/CHANGELOG.md new file mode 100644 index 00000000..8907d09c --- /dev/null +++ b/buildpacks/leiningen/CHANGELOG.md @@ -0,0 +1,10 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +* Initial release diff --git a/buildpacks/leiningen/Cargo.toml b/buildpacks/leiningen/Cargo.toml new file mode 100644 index 00000000..fbfd301b --- /dev/null +++ b/buildpacks/leiningen/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "leiningen" +version.workspace = true +rust-version.workspace = true +edition.workspace = true +publish.workspace = true + +[dependencies] +libcnb.workspace = true +libherokubuildpack.workspace = true +indoc = "2" +java-properties = "2" +serde = { version = "1", features = ["derive"] } +tempfile = "3" +thiserror = "1" +semver = { version = "1", features = ["serde"] } +shell-words = "1" +buildpacks-jvm-shared.workspace = true + +[dev-dependencies] +libcnb-test.workspace = true +buildpacks-jvm-shared-test.workspace = true +ureq = "2" diff --git a/buildpacks/leiningen/README.md b/buildpacks/leiningen/README.md new file mode 100644 index 00000000..51df1838 --- /dev/null +++ b/buildpacks/leiningen/README.md @@ -0,0 +1,20 @@ +# Heroku Cloud Native Leiningen Buildpack +[![CI](https://github.com/heroku/buildpacks-jvm/actions/workflows/ci.yml/badge.svg)](https://github.com/heroku/buildpacks-jvm/actions/workflows/ci.yml) + +Heroku's official Cloud Native Buildpack for [Leiningen](https://leiningen.org/) usage in [Clojure](https://clojure.org/) applications. + +## Build Plan + +### Requires + +* `jdk`: To compile Java sources a JDK is required. It can be provided by the `heroku/jvm` ([Source](/buildpacks/jvm), +[Readme](/buildpacks/jvm/README.md)) buildpack. +* `jvm-application`: This is not a strict requirement of the buildpack. Requiring `jvm-application` ensures that this +buildpack can be used even when no other buildpack requires `jvm-application`. + +### Provides + +* `jvm-application`: Allows other buildpacks to depend on a compiled JVM application. + +## License +See [LICENSE](../../LICENSE) file. diff --git a/buildpacks/leiningen/buildpack.toml b/buildpacks/leiningen/buildpack.toml new file mode 100644 index 00000000..84f62482 --- /dev/null +++ b/buildpacks/leiningen/buildpack.toml @@ -0,0 +1,21 @@ +api = "0.9" + +[buildpack] +id = "heroku/leiningen" +version = "3.2.0" +name = "Leiningen" +clear-env = true +homepage = "https://github.com/heroku/buildpacks-jvm" +description = "Official Heroku buildpack for leiningen applications." +keywords = ["java", "clojure", "leiningen"] + +[[buildpack.licenses]] +type = "BSD-3-Clause" + +[[stacks]] +id = "*" + +[metadata] +[metadata.release] +[metadata.release.image] +repository = "docker.io/heroku/buildpack-leiningen" diff --git a/buildpacks/leiningen/lein/lein b/buildpacks/leiningen/lein/lein new file mode 100644 index 00000000..85afebd9 --- /dev/null +++ b/buildpacks/leiningen/lein/lein @@ -0,0 +1,449 @@ +#!/usr/bin/env bash + +# Ensure this file is executable via `chmod a+x lein`, then place it +# somewhere on your $PATH, like ~/bin. The rest of Leiningen will be +# installed upon first run into the ~/.lein/self-installs directory. + +export LEIN_VERSION="2.10.0" +# Must be sha256sum, will be replaced by bin/release +export LEIN_CHECKSUM='d27299bad34075ac2864d0bd0559f835c6e2c476c0b0a283bcbdb574fdadbb34' + +case $LEIN_VERSION in + *SNAPSHOT) SNAPSHOT="YES" ;; + *) SNAPSHOT="NO" ;; +esac + +if [[ "$CLASSPATH" != "" ]]; then + cat <<-'EOS' 1>&2 + WARNING: You have $CLASSPATH set, probably by accident. + It is strongly recommended to unset this before proceeding. + EOS +fi + +if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]]; then + delimiter=";" +else + delimiter=":" +fi + +if [[ "$OSTYPE" == "cygwin" ]]; then + cygwin=true +else + cygwin=false +fi + +function msg { + echo "$@" 1>&2 +} + +function command_not_found { + msg "Leiningen couldn't find $1 in your \$PATH ($PATH), which is required." + exit 1 +} + +function make_native_path { + # ensure we have native paths + if $cygwin && [[ "$1" == /* ]]; then + echo -n "$(cygpath -wp "$1")" + elif [[ "$OSTYPE" == "msys" && "$1" == /?/* ]]; then + echo -n "$(sh -c "(cd $1 2&2 + Failed to download $1 (exit code $2) + It's possible your HTTP client's certificate store does not have the + correct certificate authority needed. This is often caused by an + out-of-date version of libssl. It's also possible that you're behind a + firewall and haven't set HTTP_PROXY and HTTPS_PROXY. + EOS +} + +function checksum_failed_message { + cat <<-EOS 1>&2 + Failed to properly download $1 + The checksum was mismatched. and we could not verify the downloaded + file. We expected a sha256 of + $2 and actually had + $3. + We used '$SHASUM_CMD' to verify the downloaded file. + EOS +} + +function self_install { + if [ -r "$LEIN_JAR" ]; then + cat <<-EOS 1>&2 + The self-install jar already exists at $LEIN_JAR. + If you wish to re-download, delete it and rerun "$0 self-install". + EOS + exit 1 + fi + msg "Downloading Leiningen to $LEIN_JAR now..." + mkdir -p "$(dirname "$LEIN_JAR")" + LEIN_URL="https://github.com/technomancy/leiningen/releases/download/$LEIN_VERSION/leiningen-$LEIN_VERSION-standalone.jar" + $HTTP_CLIENT "$LEIN_JAR.pending" "$LEIN_URL" + local exit_code=$? + if [ $exit_code == 0 ]; then + printf "$LEIN_CHECKSUM $LEIN_JAR.pending\n" > "$LEIN_JAR.pending.shasum" + $SHASUM_CMD -c "$LEIN_JAR.pending.shasum" + if [ $? == 0 ]; then + mv -f "$LEIN_JAR.pending" "$LEIN_JAR" + else + got_sum="$($SHASUM_CMD "$LEIN_JAR.pending" | cut -f 1 -d ' ')" + checksum_failed_message "$LEIN_URL" "$LEIN_CHECKSUM" "$got_sum" + rm "$LEIN_JAR.pending" 2> /dev/null + exit 1 + fi + else + rm "$LEIN_JAR.pending" 2> /dev/null + download_failed_message "$LEIN_URL" "$exit_code" + exit 1 + fi +} + +function run_from_source() { + LEIN_DIR="$(cd $(dirname "$BIN_DIR");pwd -P)" + + # Need to use lein release to bootstrap the leiningen-core library (for aether) + if [ ! -r "$LEIN_DIR/leiningen-core/.lein-bootstrap" ]; then + cat <<-'EOS' 1>&2 + Leiningen is missing its dependencies. + Please run "lein bootstrap" in the leiningen-core/ directory + with a stable release of Leiningen. See CONTRIBUTING.md for details. + EOS + exit 1 + fi + + # If project.clj for lein or leiningen-core changes, we must recalculate + LAST_PROJECT_CHECKSUM=$(cat "$LEIN_DIR/.lein-project-checksum" 2> /dev/null) + PROJECT_CHECKSUM=$(sum "$LEIN_DIR/project.clj" "$LEIN_DIR/leiningen-core/project.clj") + if [ "$PROJECT_CHECKSUM" != "$LAST_PROJECT_CHECKSUM" ]; then + if [ -r "$LEIN_DIR/.lein-classpath" ]; then + rm "$LEIN_DIR/.lein-classpath" + fi + fi + + # Use bin/lein to calculate its own classpath. + if [ ! -r "$LEIN_DIR/.lein-classpath" ] && [ "$1" != "classpath" ]; then + msg "Recalculating Leiningen's classpath." + cd "$LEIN_DIR" + + LEIN_NO_USER_PROFILES=1 "$LEIN_DIR/bin/lein" classpath .lein-classpath + sum "$LEIN_DIR/project.clj" "$LEIN_DIR/leiningen-core/project.clj" > \ + .lein-project-checksum + cd - + fi + + mkdir -p "$LEIN_DIR/target/classes" + export LEIN_JVM_OPTS="$LEIN_JVM_OPTS -Dclojure.compile.path=$LEIN_DIR/target/classes" + add_path CLASSPATH "$LEIN_DIR/leiningen-core/src/" "$LEIN_DIR/leiningen-core/resources/" \ + "$LEIN_DIR/test:$LEIN_DIR/target/classes" "$LEIN_DIR/src" ":$LEIN_DIR/resources" + + if [ -r "$LEIN_DIR/.lein-classpath" ]; then + add_path CLASSPATH "$(cat "$LEIN_DIR/.lein-classpath" 2> /dev/null)" + else + add_path CLASSPATH "$(cat "$LEIN_DIR/leiningen-core/.lein-bootstrap" 2> /dev/null)" + fi +} + +function run_from_checkout() { + add_path CLASSPATH "$LEIN_JAR" + + if [ "$LEIN_USE_BOOTCLASSPATH" != "no" ]; then + LEIN_JVM_OPTS="-Xbootclasspath/a:$LEIN_JAR $LEIN_JVM_OPTS" + fi +} + +function cmd_self_install() { + if [ -r "$BIN_DIR/../src/leiningen/version.clj" ]; then + cat <<-'EOS' 1>&2 + Running self-install from a checkout is not supported. + See CONTRIBUTING.md for SNAPSHOT-specific build instructions. + EOS + exit 1 + fi + msg "Manual self-install is deprecated; it will run automatically when necessary." + self_install +} + +function cmd_up_downgrade() { + if [ "$LEIN_DIR" != "" ]; then + msg "The upgrade task is not meant to be run from a checkout." + exit 1 + fi + if [ $SNAPSHOT = "YES" ]; then + cat <<-'EOS' 1>&2 + The upgrade task is only meant for stable releases. + See the "Bootstrapping" section of CONTRIBUTING.md. + EOS + exit 1 + fi + if [ ! -w "$SCRIPT" ]; then + msg "You do not have permission to upgrade the installation in $SCRIPT" + exit 1 + else + TARGET_VERSION="${2:-stable}" + echo "The script at $SCRIPT will be upgraded to the latest $TARGET_VERSION version." + echo -n "Do you want to continue [Y/n]? " + read RESP + case "$RESP" in + y|Y|"") + echo + msg "Upgrading..." + if hash mktemp 2>/dev/null; then + TARGET="(mktemp -t lein-upgrade.XXXXXXXXX)" + else + TARGET="/tmp/lein-${$}-upgrade" + fi + if $cygwin; then + TARGET=$(cygpath -w "$TARGET") + fi + LEIN_SCRIPT_URL="https://github.com/technomancy/leiningen/raw/$TARGET_VERSION/bin/lein" + $HTTP_CLIENT "$TARGET" "$LEIN_SCRIPT_URL" + if [ $? == 0 ]; then + cmp -s "$TARGET" "$SCRIPT" + if [ $? == 0 ]; then + msg "Leiningen is already up-to-date." + fi + mv "$TARGET" "$SCRIPT" && chmod +x "$SCRIPT" + unset CLASSPATH + exec "$SCRIPT" version + else + download_failed_message "$LEIN_SCRIPT_URL" + fi;; + *) + msg "Aborted." + exit 1;; + esac + fi +} + +function cmd_run { + if $cygwin; then + # When running on Cygwin, use Windows-style paths for java + ORIGINAL_PWD=$(cygpath -w "$ORIGINAL_PWD") + fi + + # apply context specific CLASSPATH entries + if [ -f .lein-classpath ]; then + add_path CLASSPATH "$(cat .lein-classpath)" + fi + + if [ -n "$DEBUG" ]; then + msg "Leiningen's classpath: $CLASSPATH" + fi + + if [ -r .lein-fast-trampoline ]; then + export LEIN_FAST_TRAMPOLINE='y' + fi + + if [ "$LEIN_FAST_TRAMPOLINE" != "" ] && [ -r project.clj ]; then + INPUTS="$* $(cat project.clj) $LEIN_VERSION $(test -f "$LEIN_HOME/profiles.clj" && cat "$LEIN_HOME/profiles.clj") $(test -f profiles.clj && cat profiles.clj)" + + INPUT_CHECKSUM=$(echo "$INPUTS" | $SHASUM_CMD | cut -f 1 -d " ") + # Just don't change :target-path in project.clj, mkay? + TRAMPOLINE_FILE="target/trampolines/$INPUT_CHECKSUM" + else + if hash mktemp 2>/dev/null; then + # Check if mktemp is available before using it + TRAMPOLINE_FILE="$(mktemp -t lein-trampoline-XXXXXXXXXXXXX)" + else + TRAMPOLINE_FILE="/tmp/lein-trampoline-$$" + fi + trap 'rm -f $TRAMPOLINE_FILE' EXIT + fi + + if $cygwin; then + TRAMPOLINE_FILE=$(cygpath -w "$TRAMPOLINE_FILE") + fi + + if [ "$INPUT_CHECKSUM" != "" ] && [ -r "$TRAMPOLINE_FILE" ]; then + if [ -n "$DEBUG" ]; then + msg "Fast trampoline with $TRAMPOLINE_FILE." + fi + exec sh -c "exec $(cat "$TRAMPOLINE_FILE")" + else + export TRAMPOLINE_FILE + "$LEIN_JAVA_CMD" \ + -Dfile.encoding=UTF-8 \ + -Dmaven.wagon.http.ssl.easy=false \ + -Dmaven.wagon.rto=10000 \ + $LEIN_JVM_OPTS \ + -Dleiningen.input-checksum="$INPUT_CHECKSUM" \ + -Dleiningen.original.pwd="$ORIGINAL_PWD" \ + -Dleiningen.script="$SCRIPT" \ + -classpath "$CLASSPATH" \ + clojure.main -m leiningen.core.main "$@" + + EXIT_CODE=$? + + if $cygterm ; then + stty icanon echo > /dev/null 2>&1 + fi + + if [ -r "$TRAMPOLINE_FILE" ] && [ "$LEIN_TRAMPOLINE_WARMUP" = "" ]; then + TRAMPOLINE="$(cat "$TRAMPOLINE_FILE")" + if [ "$INPUT_CHECKSUM" = "" ]; then # not using fast trampoline + rm "$TRAMPOLINE_FILE" + fi + if [ "$TRAMPOLINE" = "" ]; then + exit $EXIT_CODE + else + exec sh -c "exec $TRAMPOLINE" + fi + else + exit $EXIT_CODE + fi + fi +} + +# cd to the project root, if applicable +NOT_FOUND=1 +ORIGINAL_PWD="$PWD" +while [ ! -r "$PWD/project.clj" ] && [ "$PWD" != "/" ] && [ $NOT_FOUND -ne 0 ] +do + cd .. + if [ "$(dirname "$PWD")" = "/" ]; then + NOT_FOUND=0 + cd "$ORIGINAL_PWD" + fi +done + +# User init +export LEIN_HOME="${LEIN_HOME:-"$HOME/.lein"}" + +for f in "/etc/leinrc" "$LEIN_HOME/leinrc" ".leinrc"; do + if [ -e "$f" ]; then + source "$f" + fi +done + +if $cygwin; then + export LEIN_HOME=$(cygpath -w "$LEIN_HOME") +fi + +# normalize $0 on certain BSDs +if [ "$(dirname "$0")" = "." ]; then + SCRIPT="$(which "$(basename "$0")")" + if [ -z "$SCRIPT" ]; then + SCRIPT="$0" + fi +else + SCRIPT="$0" +fi + +# resolve symlinks to the script itself portably +while [ -h "$SCRIPT" ] ; do + ls=$(ls -ld "$SCRIPT") + link=$(expr "$ls" : '.*-> \(.*\)$') + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT="$(dirname "$SCRIPT"$)/$link" + fi +done + +BIN_DIR="$(dirname "$SCRIPT")" + + +LEIN_JAR="${LEIN_JAR:-${LEIN_HOME}/self-installs/leiningen-${LEIN_VERSION}-standalone.jar}" + +export LEIN_JVM_OPTS="${LEIN_JVM_OPTS-"-XX:+TieredCompilation -XX:TieredStopAtLevel=1"}" + +# This needs to be defined before we call HTTP_CLIENT below +if [ "$HTTP_CLIENT" = "" ]; then + if type -p curl >/dev/null 2>&1; then + if [ "$https_proxy" != "" ]; then + CURL_PROXY="-x $https_proxy" + fi + HTTP_CLIENT="curl $CURL_PROXY -f -L -o" + else + HTTP_CLIENT="wget -O" + fi +fi + +# This needs to be defined before we call SHASUM_CMD below +if [ "$SHASUM_CMD" = "" ]; then + if type -p sha256sum >/dev/null 2>&1; then + export SHASUM_CMD="sha256sum" + elif type -p shasum >/dev/null 2>&1; then + export SHASUM_CMD="shasum --algorithm 256" + elif type -p sha256 >/dev/null 2>&1; then + export SHASUM_CMD="sha256 -q" + else + command_not_found sha256sum + fi +fi + +# When :eval-in :classloader we need more memory +grep -E -q '^\s*:eval-in\s+:classloader\s*$' project.clj 2> /dev/null && \ + export LEIN_JVM_OPTS="$LEIN_JVM_OPTS -Xms64m -Xmx512m" + +if [ -r "$BIN_DIR/../src/leiningen/version.clj" ]; then + run_from_source "$1" +else + run_from_checkout "$1" + + if [ ! -r "$LEIN_JAR" -a "$1" != "self-install" ]; then + self_install + fi +fi + +if [ ! -x "$JAVA_CMD" ] && ! type -f java >/dev/null +then + msg "Leiningen couldn't find 'java' executable, which is required." + msg "Please either set JAVA_CMD or put java (>=1.6) in your \$PATH ($PATH)." + exit 1 +fi + +export LEIN_JAVA_CMD="${LEIN_JAVA_CMD:-${JAVA_CMD:-java}}" + +if [[ -z "${DRIP_INIT+x}" && "$(basename "$LEIN_JAVA_CMD")" == *drip* ]]; then + export DRIP_INIT="$(printf -- '-e\n(require (quote leiningen.repl))')" + export DRIP_INIT_CLASS="clojure.main" +fi + +# Support $JAVA_OPTS for backwards-compatibility. +export JVM_OPTS="${JVM_OPTS:-"$JAVA_OPTS"}" + +# Handle jline issue with cygwin not propagating OSTYPE through java subprocesses: https://github.com/jline/jline2/issues/62 +cygterm=false +if $cygwin; then + case "$TERM" in + rxvt* | xterm* | vt*) cygterm=true ;; + esac +fi + +if $cygterm; then + LEIN_JVM_OPTS="$LEIN_JVM_OPTS -Djline.terminal=jline.UnixTerminal" + stty -icanon min 1 -echo > /dev/null 2>&1 +fi + +# TODO: investigate http://skife.org/java/unix/2011/06/20/really_executable_jars.html +# If you're packaging this for a package manager (.deb, homebrew, etc) +# you need to remove the self-install and upgrade functionality or see lein-pkg. +if [ "$1" = "self-install" ]; then + cmd_self_install +elif [ "$1" = "upgrade" ] || [ "$1" = "downgrade" ]; then + cmd_up_downgrade "$@" +else + cmd_run "$@" +fi diff --git a/buildpacks/leiningen/package.toml b/buildpacks/leiningen/package.toml new file mode 100644 index 00000000..54b0d2e4 --- /dev/null +++ b/buildpacks/leiningen/package.toml @@ -0,0 +1,2 @@ +[buildpack] +uri = "." diff --git a/buildpacks/leiningen/src/errors.rs b/buildpacks/leiningen/src/errors.rs new file mode 100644 index 00000000..518b1d1d --- /dev/null +++ b/buildpacks/leiningen/src/errors.rs @@ -0,0 +1,13 @@ +use std::fmt::Debug; + +#[derive(Debug, Copy, Clone)] +pub(crate) enum LeiningenBuildpackError {} + +#[allow(clippy::too_many_lines)] +pub(crate) fn log_user_errors(_error: LeiningenBuildpackError) {} + +impl From for libcnb::Error { + fn from(value: LeiningenBuildpackError) -> Self { + libcnb::Error::BuildpackError(value) + } +} diff --git a/buildpacks/leiningen/src/main.rs b/buildpacks/leiningen/src/main.rs new file mode 100644 index 00000000..dae78480 --- /dev/null +++ b/buildpacks/leiningen/src/main.rs @@ -0,0 +1,63 @@ +// Enable rustc and Clippy lints that are disabled by default. +// https://rust-lang.github.io/rust-clippy/stable/index.html +#![warn(clippy::pedantic)] +// This lint is too noisy and enforces a style that reduces readability in many cases. +#![allow(clippy::module_name_repetitions)] + +mod errors; + +use crate::errors::{log_user_errors, LeiningenBuildpackError}; +use buildpacks_jvm_shared::fs::set_executable; +use libcnb::build::{BuildContext, BuildResult, BuildResultBuilder}; +use libcnb::data::build_plan::BuildPlanBuilder; +use libcnb::detect::{DetectContext, DetectResult, DetectResultBuilder}; +use libcnb::generic::{GenericMetadata, GenericPlatform}; +use libcnb::{buildpack_main, Buildpack, Env, Error}; +use libherokubuildpack::error::on_error as on_buildpack_error; +use std::process::Command; + +pub(crate) struct LeiningenBuildpack; + +impl Buildpack for LeiningenBuildpack { + type Platform = GenericPlatform; + type Metadata = GenericMetadata; + type Error = LeiningenBuildpackError; + + fn detect(&self, context: DetectContext) -> libcnb::Result { + if context.app_dir.join("project.clj").exists() { + DetectResultBuilder::pass() + .build_plan( + BuildPlanBuilder::new() + .requires("jdk") + .provides("jvm-application") + .requires("jvm-application") + .build(), + ) + .build() + } else { + DetectResultBuilder::fail().build() + } + } + + fn build(&self, context: BuildContext) -> libcnb::Result { + let lein_contents = include_str!("../lein/lein"); + let lein_path = context.app_dir.join("lein"); + + std::fs::write(&lein_path, lein_contents).unwrap(); + set_executable(&lein_path).unwrap(); + + Command::new(lein_path) + .arg("uberjar") + .envs(&Env::from_current()) + .spawn() + .unwrap(); + + BuildResultBuilder::new().build() + } + + fn on_error(&self, error: Error) { + on_buildpack_error(log_user_errors, error); + } +} + +buildpack_main!(LeiningenBuildpack); diff --git a/buildpacks/leiningen/test-apps/heroku-clojure-getting-started b/buildpacks/leiningen/test-apps/heroku-clojure-getting-started new file mode 160000 index 00000000..fba02a43 --- /dev/null +++ b/buildpacks/leiningen/test-apps/heroku-clojure-getting-started @@ -0,0 +1 @@ +Subproject commit fba02a43968668ed92cc773b33b60d8eee7ce632 diff --git a/buildpacks/leiningen/tests/integration/main.rs b/buildpacks/leiningen/tests/integration/main.rs new file mode 100644 index 00000000..dd0e8247 --- /dev/null +++ b/buildpacks/leiningen/tests/integration/main.rs @@ -0,0 +1,19 @@ +//! Bundle all integration tests into one binary to: +//! - Reduce compile times +//! - Reduce required disk space +//! - Increase parallelism +//! +//! See: https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html#Implications + +use libcnb_test::BuildpackReference; + +mod smoke; +pub(crate) fn default_buildpacks() -> Vec { + vec![ + BuildpackReference::Other(String::from("heroku/jvm")), + BuildpackReference::Crate, + // Using an explicit version from Docker Hub to prevent failures when there + // are multiple Procfile buildpack versions in the builder image. + BuildpackReference::Other(String::from("docker://docker.io/heroku/procfile-cnb:2.0.1")), + ] +} diff --git a/buildpacks/leiningen/tests/integration/smoke.rs b/buildpacks/leiningen/tests/integration/smoke.rs new file mode 100644 index 00000000..a613117b --- /dev/null +++ b/buildpacks/leiningen/tests/integration/smoke.rs @@ -0,0 +1,20 @@ +//! Smoke tests that ensure a set of basic apps build successfully and the resulting container +//! exposes the HTTP interface of that app as expected. They also re-build the app and assert the +//! resulting container again to ensure that potential caching logic in the buildpack does not +//! break subsequent builds. +//! +//! These tests are strictly happy-path tests and do not assert any output of the buildpack. + +use crate::default_buildpacks; +use buildpacks_jvm_shared_test::{smoke_test, DEFAULT_INTEGRATION_TEST_BUILDER}; + +#[test] +#[ignore = "integration test"] +fn smoke_test_getting_started() { + smoke_test( + DEFAULT_INTEGRATION_TEST_BUILDER, + "test-apps/heroku-clojure-getting-started", + default_buildpacks(), + "Getting Started with Clojure on Heroku", + ); +} diff --git a/meta-buildpacks/clojure/CHANGELOG.md b/meta-buildpacks/clojure/CHANGELOG.md new file mode 100644 index 00000000..8907d09c --- /dev/null +++ b/meta-buildpacks/clojure/CHANGELOG.md @@ -0,0 +1,10 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +* Initial release diff --git a/meta-buildpacks/clojure/README.md b/meta-buildpacks/clojure/README.md new file mode 100644 index 00000000..fb7dda6d --- /dev/null +++ b/meta-buildpacks/clojure/README.md @@ -0,0 +1 @@ +# Heroku Cloud Native Clojure Buildpack diff --git a/meta-buildpacks/clojure/buildpack.toml b/meta-buildpacks/clojure/buildpack.toml new file mode 100644 index 00000000..d5453381 --- /dev/null +++ b/meta-buildpacks/clojure/buildpack.toml @@ -0,0 +1,32 @@ +api = "0.9" + +[buildpack] +id = "heroku/clojure" +version = "3.2.0" +name = "Scala" +homepage = "https://github.com/heroku/buildpacks-jvm" +description = "Official Heroku buildpack for Clojure applications." +keywords = ["clojure"] + +[[buildpack.licenses]] +type = "BSD-3-Clause" + +[[order]] + +[[order.group]] +id = "heroku/jvm" +version = "3.2.0" + +[[order.group]] +id = "heroku/leiningen" +version = "3.2.0" + +[[order.group]] +id = "heroku/procfile" +version = "2.0.1" +optional = true + +[metadata] +[metadata.release] +[metadata.release.image] +repository = "docker.io/heroku/buildpack-clojure" diff --git a/meta-buildpacks/clojure/package.toml b/meta-buildpacks/clojure/package.toml new file mode 100644 index 00000000..eef7195a --- /dev/null +++ b/meta-buildpacks/clojure/package.toml @@ -0,0 +1,11 @@ +[buildpack] +uri = "." + +[[dependencies]] +uri = "libcnb:heroku/jvm" + +[[dependencies]] +uri = "libcnb:heroku/leiningen" + +[[dependencies]] +uri = "docker://docker.io/heroku/procfile-cnb@sha256:ea7219d4bb50196b4f292c9aae397b17255c59a243d7408535d2a03a5cd2b040"