diff --git a/README.md b/README.md index 8423412..d46e6bd 100644 --- a/README.md +++ b/README.md @@ -210,9 +210,19 @@ int exitCode = BuildConfig.builder() ## Error Handling -If the build fails for any reason, a `BuildpackException` will be thrown, this is a RuntimeException, so does not need an explicit catch block. There are many many ways in which a build can fail, from something environmental, like docker being unavailable, to build related issues, like the chosen builder image requiring a platformlevel not implemented by this library. +If the build fails for any reason, a `BuildpackException` will be thrown, this is a RuntimeException, so does not need an explicit catch block. There are many ways in which a build can fail, from something environmental, like docker being unavailable, to build related issues, like the chosen builder image requiring a platformlevel not implemented by this library. -## Using the buildpack client with jbang +## Using the buildpack client + +### Maven exec:java + +To play with the Java Buildpack client & DSL, use the following simple java project: [samples/build-me](samples/build-me) +```bash +export PROJECT_PATH="$HOME/path_to/java-buildpack-client/samples/hello-quarkus" +mvn compile exec:java +``` + +### Jbang The easiest way to invoke arbitrary java code, without much hassle is by using [jbang](https://www.jbang.dev/). diff --git a/samples/build-me/.gitignore b/samples/build-me/.gitignore new file mode 100644 index 0000000..7944f07 --- /dev/null +++ b/samples/build-me/.gitignore @@ -0,0 +1,16 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/samples/build-me/README.md b/samples/build-me/README.md new file mode 100644 index 0000000..a040ca2 --- /dev/null +++ b/samples/build-me/README.md @@ -0,0 +1,14 @@ +# Buildpack Builder config example + +Example of a java project able to build a Quarkus, spring Boot, ... project +using the DSL `BuildConfig.builder()` + +To use it, just configure the following env var pointing to a project to be built as a container image + +```bash +exort PROJECT_PATH= +``` +and execute this command in a terminal: +```bash +mvn compile exec:java +``` \ No newline at end of file diff --git a/samples/build-me/pom.xml b/samples/build-me/pom.xml new file mode 100644 index 0000000..61a7c1e --- /dev/null +++ b/samples/build-me/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + dev.snowdrop + build-me + Snowdrop :: Java Buildpack Client :: Samples :: Build me + 1.0-SNAPSHOT + + + 21 + 21 + UTF-8 + + + + + dev.snowdrop + buildpack-client + 0.0.12 + + + org.projectlombok + lombok + 1.18.30 + provided + + + + + com.github.docker-java + docker-java-core + 3.4.0 + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + + -proc:full + + + + org.codehaus.mojo + exec-maven-plugin + 3.5.0 + + dev.snowdrop.BuildMe + + + + + + \ No newline at end of file diff --git a/samples/build-me/src/main/java/dev/snowdrop/BuildMe.java b/samples/build-me/src/main/java/dev/snowdrop/BuildMe.java new file mode 100644 index 0000000..994713c --- /dev/null +++ b/samples/build-me/src/main/java/dev/snowdrop/BuildMe.java @@ -0,0 +1,61 @@ +package dev.snowdrop; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import com.github.dockerjava.api.DockerClient; +import dev.snowdrop.buildpack.*; +import dev.snowdrop.buildpack.config.*; + +import static dev.snowdrop.buildpack.docker.DockerClientUtils.getDockerClient; + +public class BuildMe { + + public static void main(String... args) { + + System.setProperty("org.slf4j.simpleLogger.log.dev.snowdrop.buildpack","debug"); + System.setProperty("org.slf4j.simpleLogger.log.dev.snowdrop.buildpack.docker","debug"); + System.setProperty("org.slf4j.simpleLogger.log.dev.snowdrop.buildpack.lifecycle","debug"); + System.setProperty("org.slf4j.simpleLogger.log.dev.snowdrop.buildpack.lifecycle.phases","debug"); + + String REGISTRY_USERNAME = System.getenv("REGISTRY_USERNAME"); + String REGISTRY_PASSWORD = System.getenv("REGISTRY_PASSWORD"); + String REGISTRY_SERVER = System.getenv("REGISTRY_SERVER"); + + String PROJECT_PATH = System.getenv("PROJECT_PATH"); + File filePath = new File(PROJECT_PATH); + + Map envMap = new HashMap<>(); + envMap.put("BP_JVM_VERSION", "21"); + + DockerClient client = getDockerClient(); + client.authConfig() + .withUsername(REGISTRY_USERNAME) + .withPassword(REGISTRY_PASSWORD) + .withRegistryAddress(REGISTRY_SERVER); + + int exitCode = BuildConfig.builder() + .withBuilderImage(new ImageReference("paketocommunity/builder-ubi-base:latest")) + .withOutputImage(new ImageReference("quay.io/snowdrop/my-quarkus-app")) + .withNewPlatformConfig() + .withEnvironment(Map.ofEntries( + Map.entry("BP_JVM_VERSION", "21") + // Map.entry("BP_MAVEN_BUILT_ARTIFACT","target/quarkus-app/lib/ target/quarkus-app/*.jar target/quarkus-app/app/ target/quarkus-app/quarkus"), + // Map.entry("CNB_LOG_LEVEL","trace") + )) + .endPlatformConfig() + .withNewDockerConfig() + .withDockerClient(client) + .endDockerConfig() + .withNewLogConfig() + .withLogger(new SystemLogger()) + .withLogLevel("debug") + .and() + .addNewFileContentApplication(filePath) + .build() + .getExitCode(); + + System.exit(exitCode); + } +} \ No newline at end of file