From 666f68ea60331c53ba60410d1a0caffb8d38b8d7 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 25 Oct 2023 12:44:08 +0100 Subject: [PATCH] Document configuration for building images with Colima Closes gh-34522 --- .../docs/asciidoc/packaging-oci-image.adoc | 20 +++++++++++++++ ...boot-build-image-docker-host-colima.gradle | 22 ++++++++++++++++ ...-build-image-docker-host-colima.gradle.kts | 25 +++++++++++++++++++ .../docs/PackagingDocumentationTests.java | 8 ++++++ .../docs/asciidoc/packaging-oci-image.adoc | 15 ++++++++++- .../packaging-oci-image/docker-colima-pom.xml | 18 +++++++++++++ 6 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-build-image-docker-host-colima.gradle create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-build-image-docker-host-colima.gradle.kts create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/maven/packaging-oci-image/docker-colima-pom.xml diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/packaging-oci-image.adoc b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/packaging-oci-image.adoc index 87101607177..69ac4568dde 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/packaging-oci-image.adoc +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/packaging-oci-image.adoc @@ -463,6 +463,26 @@ include::../gradle/packaging/boot-build-image-docker-host-podman.gradle.kts[tags TIP: With the `podman` CLI installed, the command `podman info --format='{{.Host.RemoteSocket.Path}}'` can be used to get the value for the `docker.host` configuration property shown in this example. +[[build-image.examples.docker.colima]] +==== Docker Configuration for Colima + +The plugin can communicate with the Docker daemon provided by https://github.com/abiosoft/colima[Colima]. +The `DOCKER_HOST` environment variable can be set by using the command `export DOCKER_HOST=$(docker context inspect colima -f '{{.Endpoints.docker.Host}}').` + +The plugin can also be configured to use Colima daemon by providing connection details similar to those shown in the following example: + +[source,groovy,indent=0,subs="verbatim,attributes",role="primary"] +.Groovy +---- +include::../gradle/packaging/boot-build-image-docker-host-colima.gradle[tags=docker-host] +---- + +[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"] +.Kotlin +---- +include::../gradle/packaging/boot-build-image-docker-host-colima.gradle.kts[tags=docker-host] +---- + [[build-image.examples.docker.auth]] ==== Docker Configuration for Authentication diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-build-image-docker-host-colima.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-build-image-docker-host-colima.gradle new file mode 100644 index 00000000000..40fe577946c --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-build-image-docker-host-colima.gradle @@ -0,0 +1,22 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '{gradle-project-version}' +} + +tasks.named("bootJar") { + mainClass = 'com.example.ExampleApplication' +} + +// tag::docker-host[] +tasks.named("bootBuildImage") { + docker { + host = "unix://${System.properties['user.home']}/.colima/docker.sock" + } +} +// end::docker-host[] + +tasks.register("bootBuildImageDocker") { + doFirst { + println("host=${tasks.bootBuildImage.docker.host}") + } +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-build-image-docker-host-colima.gradle.kts b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-build-image-docker-host-colima.gradle.kts new file mode 100644 index 00000000000..25dfbb4da2b --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-build-image-docker-host-colima.gradle.kts @@ -0,0 +1,25 @@ +import org.springframework.boot.gradle.tasks.bundling.BootJar +import org.springframework.boot.gradle.tasks.bundling.BootBuildImage + +plugins { + java + id("org.springframework.boot") version "{gradle-project-version}" +} + +tasks.named("bootJar") { + mainClass.set("com.example.ExampleApplication") +} + +// tag::docker-host[] +tasks.named("bootBuildImage") { + docker { + host = "unix://${System.getProperty("user.home")}/.colima/docker.sock" + } +} +// end::docker-host[] + +tasks.register("bootBuildImageDocker") { + doFirst { + println("host=${tasks.getByName("bootBuildImage").docker.host}") + } +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PackagingDocumentationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PackagingDocumentationTests.java index a6f7d97230b..fa38b0df0b3 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PackagingDocumentationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PackagingDocumentationTests.java @@ -299,6 +299,14 @@ class PackagingDocumentationTests { .contains("bindHostToBuilder=true"); } + @TestTemplate + void bootBuildImageWithDockerHostColima() { + BuildResult result = this.gradleBuild.script("src/docs/gradle/packaging/boot-build-image-docker-host-colima") + .build("bootBuildImageDocker"); + assertThat(result.getOutput()) + .contains("host=unix://" + System.getProperty("user.home") + "/.colima/docker.sock"); + } + @TestTemplate void bootBuildImageWithDockerUserAuth() { BuildResult result = this.gradleBuild.script("src/docs/gradle/packaging/boot-build-image-docker-auth-user") diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/asciidoc/packaging-oci-image.adoc b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/asciidoc/packaging-oci-image.adoc index 111e9d94f30..c1f550386d1 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/asciidoc/packaging-oci-image.adoc +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/asciidoc/packaging-oci-image.adoc @@ -415,7 +415,20 @@ The plugin can be configured to use podman local connection by providing connect include::../maven/packaging-oci-image/docker-podman-pom.xml[tags=docker-podman] ---- -TIP: With the `podman` CLI installed, the command `podman info --format='{{.Host.RemoteSocket.Path}}'` can be used to get the value for the `docker.host` configuration property shown in this example. +TIP: With the `colima` CLI installed, the command `podman info --format='{{.Host.RemoteSocket.Path}}'` can be used to get the value for the `docker.host` configuration property shown in this example. + +[[build-image.examples.docker.colima]] +==== Docker Configuration for Colima + +The plugin can communicate with the Docker daemon provided by https://github.com/abiosoft/colima[Colima]. +The `DOCKER_HOST` environment variable can be set by using the command `export DOCKER_HOST=$(docker context inspect colima -f '{{.Endpoints.docker.Host}}').` + +The plugin can also be configured to use Colima daemon by providing connection details similar to those shown in the following example: + +[source,xml,indent=0,subs="verbatim,attributes",tabsize=4] +---- +include::../maven/packaging-oci-image/docker-colima-pom.xml[tags=docker-colima] +---- [[build-image.examples.docker.auth]] ==== Docker Configuration for Authentication diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/maven/packaging-oci-image/docker-colima-pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/maven/packaging-oci-image/docker-colima-pom.xml new file mode 100644 index 00000000000..12a048f8ddd --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/maven/packaging-oci-image/docker-colima-pom.xml @@ -0,0 +1,18 @@ + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + unix:///${user.home}/.colima/docker.sock + + + + + + +