-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple java build client project
Signed-off-by: cmoulliard <[email protected]>
- Loading branch information
1 parent
0f6b5b8
commit 0305b17
Showing
5 changed files
with
177 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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=<JAVA_PROJECT> | ||
``` | ||
and execute this command in a terminal: | ||
```bash | ||
mvn compile exec:java | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>dev.snowdrop</groupId> | ||
<artifactId>build-me</artifactId> | ||
<name>Snowdrop :: Java Buildpack Client :: Samples :: Build me</name> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<maven.compiler.source>21</maven.compiler.source> | ||
<maven.compiler.target>21</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>dev.snowdrop</groupId> | ||
<artifactId>buildpack-client</artifactId> | ||
<version>0.0.12</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.30</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- docker --> | ||
<dependency> | ||
<groupId>com.github.docker-java</groupId> | ||
<artifactId>docker-java-core</artifactId> | ||
<version>3.4.0</version> | ||
</dependency> | ||
|
||
<!-- logging --> | ||
<!-- | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-slf4j2-impl</artifactId> | ||
<version>2.23.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-core</artifactId> | ||
<version>2.23.1</version> | ||
</dependency> | ||
--> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.11.0</version> | ||
<configuration> | ||
<!-- `-proc:only`: Explicitly enable annotation processing. --> | ||
<compilerArgument>-proc:full</compilerArgument> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>3.5.0</version> | ||
<configuration> | ||
<mainClass>dev.snowdrop.BuildMe</mainClass> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, String> 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); | ||
} | ||
} |