From d114f7057b394180a597d1d04e7b030988f7821a Mon Sep 17 00:00:00 2001 From: David Gageot Date: Fri, 12 Oct 2018 11:59:59 +0200 Subject: [PATCH] Add a sample for Jib Signed-off-by: David Gageot --- examples/annotated-skaffold.yaml | 10 ++-- examples/bazel/README.adoc | 2 +- examples/jib/.gitignore | 5 ++ examples/jib/README.adoc | 31 ++++++++++++ examples/jib/k8s/web.yaml | 29 +++++++++++ examples/jib/pom.xml | 48 +++++++++++++++++++ examples/jib/skaffold.yaml | 6 +++ .../jib/src/main/java/hello/Application.java | 11 +++++ .../src/main/java/hello/HelloController.java | 12 +++++ integration/examples/annotated-skaffold.yaml | 10 ++-- integration/examples/bazel/README.adoc | 2 +- integration/examples/jib/.gitignore | 5 ++ integration/examples/jib/README.adoc | 31 ++++++++++++ integration/examples/jib/k8s/web.yaml | 29 +++++++++++ integration/examples/jib/pom.xml | 48 +++++++++++++++++++ integration/examples/jib/skaffold.yaml | 6 +++ .../jib/src/main/java/hello/Application.java | 11 +++++ .../src/main/java/hello/HelloController.java | 12 +++++ 18 files changed, 296 insertions(+), 12 deletions(-) create mode 100644 examples/jib/.gitignore create mode 100644 examples/jib/README.adoc create mode 100644 examples/jib/k8s/web.yaml create mode 100644 examples/jib/pom.xml create mode 100644 examples/jib/skaffold.yaml create mode 100644 examples/jib/src/main/java/hello/Application.java create mode 100644 examples/jib/src/main/java/hello/HelloController.java create mode 100644 integration/examples/jib/.gitignore create mode 100644 integration/examples/jib/README.adoc create mode 100644 integration/examples/jib/k8s/web.yaml create mode 100644 integration/examples/jib/pom.xml create mode 100644 integration/examples/jib/skaffold.yaml create mode 100644 integration/examples/jib/src/main/java/hello/Application.java create mode 100644 integration/examples/jib/src/main/java/hello/HelloController.java diff --git a/examples/annotated-skaffold.yaml b/examples/annotated-skaffold.yaml index 9353366eb32..84c1d31c566 100644 --- a/examples/annotated-skaffold.yaml +++ b/examples/annotated-skaffold.yaml @@ -61,14 +61,14 @@ build: # bazel: # target: //:skaffold_example.tar - # jibMaven is an artifacts built with Maven, typically (but not only) a Java project. + # jibMaven builds containers using the Jib plugin for Maven. # jibMaven: - # module: modulename - # profile: profilename + # module: modulename # selects which maven module to build + # profile: profilename # selects which maven profile to activate - # jibGradle is an artifacts built with Gradle, typically (but not only) a Java project. + # jibGradle builds containers using the Jib plugin for Gradle. # jibGradle: - # project: projectname + # 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`. diff --git a/examples/bazel/README.adoc b/examples/bazel/README.adoc index 07de30dca51..02d0c4838b4 100644 --- a/examples/bazel/README.adoc +++ b/examples/bazel/README.adoc @@ -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 diff --git a/examples/jib/.gitignore b/examples/jib/.gitignore new file mode 100644 index 00000000000..9d26fe4575a --- /dev/null +++ b/examples/jib/.gitignore @@ -0,0 +1,5 @@ +target +.classpath +.project +.settings +.vscode diff --git a/examples/jib/README.adoc b/examples/jib/README.adoc new file mode 100644 index 00000000000..60ff69d5b51 --- /dev/null +++ b/examples/jib/README.adoc @@ -0,0 +1,31 @@ +=== 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: {} +---- + +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::[] diff --git a/examples/jib/k8s/web.yaml b/examples/jib/k8s/web.yaml new file mode 100644 index 00000000000..34c04f9b2b8 --- /dev/null +++ b/examples/jib/k8s/web.yaml @@ -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 + diff --git a/examples/jib/pom.xml b/examples/jib/pom.xml new file mode 100644 index 00000000000..b71c73e5954 --- /dev/null +++ b/examples/jib/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + + org.skaffold + hello-spring-boot + 0.1.0 + Spring Boot with Skaffold and Jib + + + 1.8 + + + + org.springframework.boot + spring-boot-starter-parent + 2.0.5.RELEASE + + + + + org.springframework.boot + spring-boot-starter-web + + + + + hello + + + org.springframework.boot + spring-boot-maven-plugin + + + com.google.cloud.tools + jib-maven-plugin + 0.9.11 + + + + -Djava.security.egd=file:/dev/./urandom + + + + + + + diff --git a/examples/jib/skaffold.yaml b/examples/jib/skaffold.yaml new file mode 100644 index 00000000000..040662cf5c0 --- /dev/null +++ b/examples/jib/skaffold.yaml @@ -0,0 +1,6 @@ +apiVersion: skaffold/v1alpha4 +kind: Config +build: + artifacts: + - image: gcr.io/k8s-skaffold/skaffold-jib + jibMaven: {} diff --git a/examples/jib/src/main/java/hello/Application.java b/examples/jib/src/main/java/hello/Application.java new file mode 100644 index 00000000000..5d77995503e --- /dev/null +++ b/examples/jib/src/main/java/hello/Application.java @@ -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); + } +} \ No newline at end of file diff --git a/examples/jib/src/main/java/hello/HelloController.java b/examples/jib/src/main/java/hello/HelloController.java new file mode 100644 index 00000000000..b98a365c9da --- /dev/null +++ b/examples/jib/src/main/java/hello/HelloController.java @@ -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!"; + } +} \ No newline at end of file diff --git a/integration/examples/annotated-skaffold.yaml b/integration/examples/annotated-skaffold.yaml index e0703b110d5..6fee17958b6 100644 --- a/integration/examples/annotated-skaffold.yaml +++ b/integration/examples/annotated-skaffold.yaml @@ -61,14 +61,14 @@ build: # bazel: # target: //:skaffold_example.tar - # jibMaven is an artifacts built with Maven, typically (but not only) a Java project. + # jibMaven builds containers using the Jib plugin for Maven. # jibMaven: - # module: modulename - # profile: profilename + # module: modulename # selects which maven module to build + # profile: profilename # selects which maven profile to activate - # jibGradle is an artifacts built with Gradle, typically (but not only) a Java project. + # jibGradle builds containers using the Jib plugin for Gradle. # jibGradle: - # project: projectname + # 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`. diff --git a/integration/examples/bazel/README.adoc b/integration/examples/bazel/README.adoc index 07de30dca51..02d0c4838b4 100644 --- a/integration/examples/bazel/README.adoc +++ b/integration/examples/bazel/README.adoc @@ -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 diff --git a/integration/examples/jib/.gitignore b/integration/examples/jib/.gitignore new file mode 100644 index 00000000000..9d26fe4575a --- /dev/null +++ b/integration/examples/jib/.gitignore @@ -0,0 +1,5 @@ +target +.classpath +.project +.settings +.vscode diff --git a/integration/examples/jib/README.adoc b/integration/examples/jib/README.adoc new file mode 100644 index 00000000000..94b72b47313 --- /dev/null +++ b/integration/examples/jib/README.adoc @@ -0,0 +1,31 @@ +=== 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-jib + context: . + jibMaven: {} +---- + +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::[] diff --git a/integration/examples/jib/k8s/web.yaml b/integration/examples/jib/k8s/web.yaml new file mode 100644 index 00000000000..34c04f9b2b8 --- /dev/null +++ b/integration/examples/jib/k8s/web.yaml @@ -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 + diff --git a/integration/examples/jib/pom.xml b/integration/examples/jib/pom.xml new file mode 100644 index 00000000000..b71c73e5954 --- /dev/null +++ b/integration/examples/jib/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + + org.skaffold + hello-spring-boot + 0.1.0 + Spring Boot with Skaffold and Jib + + + 1.8 + + + + org.springframework.boot + spring-boot-starter-parent + 2.0.5.RELEASE + + + + + org.springframework.boot + spring-boot-starter-web + + + + + hello + + + org.springframework.boot + spring-boot-maven-plugin + + + com.google.cloud.tools + jib-maven-plugin + 0.9.11 + + + + -Djava.security.egd=file:/dev/./urandom + + + + + + + diff --git a/integration/examples/jib/skaffold.yaml b/integration/examples/jib/skaffold.yaml new file mode 100644 index 00000000000..040662cf5c0 --- /dev/null +++ b/integration/examples/jib/skaffold.yaml @@ -0,0 +1,6 @@ +apiVersion: skaffold/v1alpha4 +kind: Config +build: + artifacts: + - image: gcr.io/k8s-skaffold/skaffold-jib + jibMaven: {} diff --git a/integration/examples/jib/src/main/java/hello/Application.java b/integration/examples/jib/src/main/java/hello/Application.java new file mode 100644 index 00000000000..5d77995503e --- /dev/null +++ b/integration/examples/jib/src/main/java/hello/Application.java @@ -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); + } +} \ No newline at end of file diff --git a/integration/examples/jib/src/main/java/hello/HelloController.java b/integration/examples/jib/src/main/java/hello/HelloController.java new file mode 100644 index 00000000000..b98a365c9da --- /dev/null +++ b/integration/examples/jib/src/main/java/hello/HelloController.java @@ -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!"; + } +} \ No newline at end of file