Skip to content

Commit

Permalink
Merge pull request quarkusio#5496 from iocanel/docker-build
Browse files Browse the repository at this point in the history
Add support for building and deploying container to Kubernetes
  • Loading branch information
maxandersen authored Feb 21, 2020
2 parents a6c2b91 + 1363ca0 commit c0be966
Show file tree
Hide file tree
Showing 107 changed files with 4,199 additions and 87 deletions.
35 changes: 35 additions & 0 deletions bom/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,31 @@
<artifactId>quarkus-kotlin-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-spi</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-docker-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-jib-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-s2i-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes-deployment</artifactId>
Expand All @@ -481,11 +506,21 @@
<artifactId>quarkus-kubernetes-spi</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes-client-spi</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes-client-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes-client-deployment-internal</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-flyway-deployment</artifactId>
Expand Down
44 changes: 42 additions & 2 deletions bom/runtime/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?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">
Expand Down Expand Up @@ -142,7 +142,7 @@
<awssdk.version>2.10.3</awssdk.version>
<azure-functions-java-library.version>1.3.0</azure-functions-java-library.version>
<kotlin.version>1.3.61</kotlin.version>
<dekorate.version>0.10.9</dekorate.version>
<dekorate.version>0.10.11</dekorate.version>
<maven-artifact-transfer.version>0.10.0</maven-artifact-transfer.version>
<jline.version>2.14.6</jline.version>
<maven-invoker.version>3.0.1</maven-invoker.version>
Expand Down Expand Up @@ -185,6 +185,8 @@
<jzlib.version>1.1.1</jzlib.version>
<checker-qual.version>2.5.2</checker-qual.version>
<error-prone-annotations.version>2.2.0</error-prone-annotations.version>
<jib-core.version>0.13.0</jib-core.version>
<google-http-client.version>1.34.0</google-http-client.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -711,6 +713,21 @@
<artifactId>quarkus-azure-functions-http</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-docker</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-jib</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-s2i</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes</artifactId>
Expand All @@ -721,6 +738,11 @@
<artifactId>quarkus-kubernetes-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes-client-internal</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kogito</artifactId>
Expand Down Expand Up @@ -2852,6 +2874,24 @@
<artifactId>quarkus-banner</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Jib -->
<dependency>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-core</artifactId>
<version>${jib-core.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
<version>${google-http-client.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
import io.quarkus.deployment.pkg.builditem.BuildSystemTargetBuildItem;
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
import io.quarkus.deployment.pkg.builditem.DeploymentResultBuildItem;
import io.quarkus.runtime.LaunchMode;

public class QuarkusAugmentor {
Expand Down Expand Up @@ -107,7 +108,8 @@ public BuildResult run() throws Exception {
chainBuilder.addFinal(i);
}
chainBuilder.addFinal(GeneratedClassBuildItem.class)
.addFinal(GeneratedResourceBuildItem.class);
.addFinal(GeneratedResourceBuildItem.class)
.addFinal(DeploymentResultBuildItem.class);

for (Consumer<BuildChainBuilder> i : buildChainCustomizers) {
i.accept(chainBuilder);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

package io.quarkus.deployment.pkg.builditem;

import java.util.Map;

import io.quarkus.builder.item.SimpleBuildItem;

public final class DeploymentResultBuildItem extends SimpleBuildItem {

private final String name;
private final Map<String, String> labels;

public DeploymentResultBuildItem(String name, Map<String, String> labels) {
this.name = name;
this.labels = labels;
}

public String getName() {
return this.name;
}

public Map<String, String> getLabels() {
return this.labels;
}

}
130 changes: 130 additions & 0 deletions core/deployment/src/main/java/io/quarkus/deployment/util/ExecUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@

package io.quarkus.deployment.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.function.Function;

import org.jboss.logging.Logger;

public class ExecUtil {

private static final Logger LOG = Logger.getLogger(ExecUtil.class);

private static final Function<InputStream, Runnable> PRINT_OUTPUT = i -> new HandleOutput(i);
private static final Function<InputStream, Runnable> SILENT = i -> new HandleOutput(i, false);

private static class HandleOutput implements Runnable {

private final InputStream is;
private final Boolean logEnabled;

HandleOutput(InputStream is) {
this(is, true);
}

HandleOutput(InputStream is, Boolean logEnabled) {
this.is = is;
this.logEnabled = logEnabled;
}

@Override
public void run() {
try (InputStreamReader isr = new InputStreamReader(is);
BufferedReader reader = new BufferedReader(isr)) {

for (String line = reader.readLine(); line != null; line = reader.readLine()) {
if (logEnabled) {
LOG.info(line);
}
}
} catch (IOException e) {
}
}
}

/**
* Execute the specified command from within the current directory.
*
* @param command The command
* @param args The command arguments
* @return true if commands where executed successfully
*/
public static boolean exec(String command, String... args) {
return exec(new File("."), command, args);
}

/**
* Execute the specified command from within the current directory and hide the output.
*
* @param command The command
* @param args The command arguments
* @return true if commands where executed successfully
*/
public static boolean execSilent(String command, String... args) {
return execSilent(new File("."), command, args);
}

/**
* Execute the specified command from within the specified directory.
*
* @param directory The directory
* @param command The command
* @param args The command arguments
* @return true if commands where executed successfully
*/
public static boolean exec(File directory, String command, String... args) {
return exec(directory, PRINT_OUTPUT, command, args);
}

/**
* Execute the specified command from within the specified directory and hide the output.
*
* @param directory The directory
* @param command The command
* @param args The command arguments
* @return true if commands where executed successfully
*/
public static boolean execSilent(File directory, String command, String... args) {
return exec(directory, SILENT, command, args);
}

/**
* Execute the specified command from within the specified directory.
* The method allows specifying an output filter that processes the command output.
*
* @param directory The directory
* @param outputFilterFunction A {@link Function} that gets an {@link InputStream} and returns an outputFilter.
* @param command The command
* @param args The command arguments
* @return true if commands where executed successfully
*/
public static boolean exec(File directory, Function<InputStream, Runnable> outputFilterFunction, String command,
String... args) {
Process process = null;
try {
String[] cmd = new String[args.length + 1];
cmd[0] = command;
if (args.length > 0) {
System.arraycopy(args, 0, cmd, 1, args.length);
}
process = new ProcessBuilder()
.directory(directory)
.command(cmd)
.redirectErrorStream(true)
.start();

outputFilterFunction.apply(process.getInputStream()).run();
process.waitFor();
} catch (IOException e) {
throw new RuntimeException("Input/Output error while executing command.", e);
} catch (InterruptedException e) {
return false;
}
return process != null && process.exitValue() == 0;
}

}
Loading

0 comments on commit c0be966

Please sign in to comment.