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

Jib sample #1147

Merged
merged 3 commits into from
Oct 25, 2018
Merged
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
11 changes: 10 additions & 1 deletion examples/annotated-skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ build:
# The path to your dockerfile context. Defaults to ".".
context: ../examples/getting-started

# Each artifact is of a given type among: `docker` and `bazel`.
# Each artifact is of a given type among: `docker`, `bazel`, `jibMaven` and `jibGradle`.
# If not specified, it defaults to `docker: {}`.
docker:
# Dockerfile's location relative to workspace. Defaults to "Dockerfile"
Expand All @@ -61,6 +61,15 @@ build:
# bazel:
# target: //:skaffold_example.tar

# jibMaven builds containers using the Jib plugin for Maven.
# jibMaven:
# module: modulename # selects which maven module to build, for a multimodule project
# profile: profilename # selects which maven profile to activate

# jibGradle builds containers using the Jib plugin for Gradle.
# jibGradle:
# project: projectname # selects which gradle project to build

# This next section is where you'll put your specific builder configuration.
# Valid builders are `local`, `googleCloudBuild` and `kaniko`.
# Defaults to `local: {}`
Expand Down
2 changes: 1 addition & 1 deletion examples/bazel/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build:
bazel: # <2>
target: //:skaffold_example.tar # <3>
----
<1> make sure the workspace contains the bazel files (`WORKSPACE`, `BUILD`)
<1> make sure the context contains the bazel files (`WORKSPACE`, `BUILD`)
<2> add bazel to each artifact
<3> specify target - our builder will use this to load to the image to the Docker daemon

Expand Down
5 changes: 5 additions & 0 deletions examples/jib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target
.classpath
.project
.settings
.vscode
36 changes: 36 additions & 0 deletions examples/jib/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
=== Example: Jib
:icons: font

Jib is one of the supported builders in Skaffold.
[Jib](https://github.com/GoogleContainerTools/jib) builds Docker and OCI images
for your Java applications and is available as plugins for Maven and Gradle.

The way you configure it in `skaffold.yaml` is the following build stanza:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth mentioning that this example is for a standalone Maven project, where all dependencies are resolved from outside. The Jib builder requires that the projects are configured to use the Jib plugins for Maven or Gradle. Multi-module builds require a bit additional configuration.


[source,yaml]
----
build:
artifacts:
- image: gcr.io/k8s-skaffold/skaffold-example
context: .
jibMaven: {}
----

Please note that this example is for a standalone Maven project, where
all dependencies are resolved from outside. The Jib builder requires
that the projects are configured to use the Jib plugins for Maven or Gradle.
Multi-module builds require a bit additional configuration.

ifndef::env-github[]
==== link:{github-repo-tree}/examples/jib[Example files icon:github[]]

[source,yaml, indent=3, title=skaffold.yaml]
----
include::skaffold.yaml[]
----

[source,xml, indent=3, title=pom.xml, syntax=xml]
----
include::pom.xml[]
----
endif::[]
29 changes: 29 additions & 0 deletions examples/jib/k8s/web.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: v1
kind: Service
metadata:
name: web
spec:
ports:
- port: 8080
name: http
type: LoadBalancer
selector:
app: web
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: gcr.io/k8s-skaffold/skaffold-jib

50 changes: 50 additions & 0 deletions examples/jib/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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>org.skaffold</groupId>
<artifactId>hello-spring-boot</artifactId>
<version>0.1.0</version>
<description>Spring Boot with Skaffold and Jib</description>

<properties>
<java.version>1.8</java.version>
</properties>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

<build>
<finalName>hello</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>0.9.11</version>
<configuration>
<container>
<jvmFlags>
<jvmFlag>-Djava.security.egd=file:/dev/./urandom</jvmFlag>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the /./?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should also just include the other container-enabling JVM flags here too:

				  <jvmFlag>-XX:+UnlockExperimentalVMOptions</jvmFlag>
				  <jvmFlag>-XX:+UseCGroupMemoryLimitForHeap</jvmFlag>

<jvmFlag>-XX:+UnlockExperimentalVMOptions</jvmFlag>
<jvmFlag>-XX:+UseCGroupMemoryLimitForHeap</jvmFlag>
</jvmFlags>
</container>
</configuration>
</plugin>
</plugins>
</build>
</project>
6 changes: 6 additions & 0 deletions examples/jib/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: skaffold/v1alpha4
kind: Config
build:
artifacts:
- image: gcr.io/k8s-skaffold/skaffold-jib
jibMaven: {}
11 changes: 11 additions & 0 deletions examples/jib/src/main/java/hello/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
12 changes: 12 additions & 0 deletions examples/jib/src/main/java/hello/HelloController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package hello;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

@RestController
public class HelloController {
@RequestMapping("/")
public String index() {
return "Hello, World!";
}
}
11 changes: 10 additions & 1 deletion integration/examples/annotated-skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ build:
# The path to your dockerfile context. Defaults to ".".
context: ../examples/getting-started

# Each artifact is of a given type among: `docker` and `bazel`.
# Each artifact is of a given type among: `docker`, `bazel`, `jibMaven` and `jibGradle`.
# If not specified, it defaults to `docker: {}`.
docker:
# Dockerfile's location relative to workspace. Defaults to "Dockerfile"
Expand All @@ -61,6 +61,15 @@ build:
# bazel:
# target: //:skaffold_example.tar

# jibMaven builds containers using the Jib plugin for Maven.
# jibMaven:
# module: modulename # selects which maven module to build, for a multimodule project
# profile: profilename # selects which maven profile to activate

# jibGradle builds containers using the Jib plugin for Gradle.
# jibGradle:
# project: projectname # selects which gradle project to build

# This next section is where you'll put your specific builder configuration.
# Valid builders are `local`, `googleCloudBuild`, `kaniko`, and `acr`.
# Defaults to `local: {}`
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/bazel/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build:
bazel: # <2>
target: //:skaffold_example.tar # <3>
----
<1> make sure the workspace contains the bazel files (`WORKSPACE`, `BUILD`)
<1> make sure the context contains the bazel files (`WORKSPACE`, `BUILD`)
<2> add bazel to each artifact
<3> specify target - our builder will use this to load to the image to the Docker daemon

Expand Down
5 changes: 5 additions & 0 deletions integration/examples/jib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target
.classpath
.project
.settings
.vscode
36 changes: 36 additions & 0 deletions integration/examples/jib/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
=== Example: Jib
:icons: font

Jib is one of the supported builders in Skaffold.
[Jib](https://github.com/GoogleContainerTools/jib) builds Docker and OCI images
for your Java applications and is available as plugins for Maven and Gradle.

The way you configure it in `skaffold.yaml` is the following build stanza:

[source,yaml]
----
build:
artifacts:
- image: gcr.io/k8s-skaffold/skaffold-example
context: .
jibMaven: {}
----

Please note that this example is for a standalone Maven project, where
all dependencies are resolved from outside. The Jib builder requires
that the projects are configured to use the Jib plugins for Maven or Gradle.
Multi-module builds require a bit additional configuration.

ifndef::env-github[]
==== link:{github-repo-tree}/examples/jib[Example files icon:github[]]

[source,yaml, indent=3, title=skaffold.yaml]
----
include::skaffold.yaml[]
----

[source,xml, indent=3, title=pom.xml, syntax=xml]
----
include::pom.xml[]
----
endif::[]
29 changes: 29 additions & 0 deletions integration/examples/jib/k8s/web.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: v1
kind: Service
metadata:
name: web
spec:
ports:
- port: 8080
name: http
type: LoadBalancer
selector:
app: web
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: gcr.io/k8s-skaffold/skaffold-jib

50 changes: 50 additions & 0 deletions integration/examples/jib/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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>org.skaffold</groupId>
<artifactId>hello-spring-boot</artifactId>
<version>0.1.0</version>
<description>Spring Boot with Skaffold and Jib</description>

<properties>
<java.version>1.8</java.version>
</properties>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

<build>
<finalName>hello</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>0.9.11</version>
<configuration>
<container>
<jvmFlags>
<jvmFlag>-Djava.security.egd=file:/dev/./urandom</jvmFlag>
<jvmFlag>-XX:+UnlockExperimentalVMOptions</jvmFlag>
<jvmFlag>-XX:+UseCGroupMemoryLimitForHeap</jvmFlag>
</jvmFlags>
</container>
</configuration>
</plugin>
</plugins>
</build>
</project>
6 changes: 6 additions & 0 deletions integration/examples/jib/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: skaffold/v1alpha4
kind: Config
build:
artifacts:
- image: gcr.io/k8s-skaffold/skaffold-jib
jibMaven: {}
11 changes: 11 additions & 0 deletions integration/examples/jib/src/main/java/hello/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
12 changes: 12 additions & 0 deletions integration/examples/jib/src/main/java/hello/HelloController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package hello;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

@RestController
public class HelloController {
@RequestMapping("/")
public String index() {
return "Hello, World!";
}
}