打包 OCI 映象
該外掛可以使用 Cloud Native Buildpacks (CNB) 從 jar 或 war 檔案建立 OCI 映象。可以使用 build-image 目標在命令列上構建映象。這確保了在建立映象之前,包的生命週期已經執行。
| 出於安全原因,映象以非 root 使用者身份構建和執行。有關詳細資訊,請參閱 CNB 規範。 |
最簡單的入門方法是在專案上呼叫 mvn spring-boot:build-image。可以自動建立映象,只要呼叫 package 階段,如下例所示
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-image-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
將目標繫結到包生命週期時使用 build-image-no-fork。此目標類似於 build-image,但不會分叉生命週期以確保 package 已執行。在本節的其餘部分,build-image 用於指代 build-image 或 build-image-no-fork 目標。 |
雖然構建包從 可執行歸檔 執行,但沒有必要首先執行 repackage 目標,因為可執行歸檔在必要時會自動建立。當 build-image 重新打包應用程式時,它會應用與 repackage 目標相同的設定,即可以使用其中一個排除選項排除依賴項。spring-boot-devtools 和 spring-boot-docker-compose 模組預設自動排除(您可以使用 excludeDevtools 和 excludeDockerCompose 屬性控制此行為)。 |
Docker Daemon
build-image 目標需要訪問 Docker daemon。該目標將檢查本地 Docker CLI 配置檔案 以確定當前的 上下文,並使用上下文連線資訊與 Docker daemon 通訊。如果無法確定當前上下文或上下文沒有連線資訊,則該目標將使用預設的本地連線。這適用於所有受支援平臺上的 Docker Engine,無需配置。
可以設定環境變數來配置 build-image 目標以使用替代的本地或遠端連線。下表顯示了環境變數及其值
| 環境變數 | 描述 |
|---|---|
DOCKER_CONFIG |
用於確定當前上下文的 Docker CLI 配置檔案 的位置(預設為 |
DOCKER_CONTEXT |
應從 Docker CLI 配置檔案中檢索主機資訊的 上下文 名稱(覆蓋 |
DOCKER_HOST |
包含 Docker daemon 主機和埠的 URL - 例如 |
DOCKER_TLS_VERIFY |
設定為 |
DOCKER_CERT_PATH |
HTTPS 證書和金鑰檔案的路徑(如果 |
Docker daemon 連線資訊也可以透過外掛配置中的 docker 引數提供。下表總結了可用引數
| 引數 | 描述 |
|---|---|
|
|
|
包含 Docker daemon 主機和埠的 URL - 例如 |
|
設定為 |
|
HTTPS 證書和金鑰檔案的路徑(如果 |
|
當 |
有關更多詳細資訊,另請參閱 示例。
Docker Registry
如果 builder 或 runImage 引數指定的 Docker 映象儲存在需要身份驗證的私有 Docker 映象倉庫中,則可以使用 docker.builderRegistry 引數提供身份驗證憑據。
如果生成的 Docker 映象要釋出到 Docker 映象倉庫,則可以使用 docker.publishRegistry 引數提供身份驗證憑據。
引數用於使用者身份驗證或身份令牌身份驗證。請查閱所用 Docker 倉庫的文件,以獲取有關支援的身份驗證方法的更多資訊。
下表總結了 docker.builderRegistry 和 docker.publishRegistry 的可用引數
| 引數 | 描述 |
|---|---|
|
Docker 映象倉庫使用者的使用者名稱。使用者身份驗證必需。 |
|
Docker 映象倉庫使用者的密碼。使用者身份驗證必需。 |
|
Docker 映象倉庫的地址。使用者身份驗證可選。 |
|
Docker 映象倉庫使用者的電子郵件地址。使用者身份驗證可選。 |
|
Docker 映象倉庫使用者的身份令牌。令牌身份驗證必需。 |
有關更多詳細資訊,另請參閱 示例。
|
如果未提供憑據,外掛將讀取使用者的現有 Docker 配置檔案(通常位於 該外掛支援以下身份驗證方法
|
映象自定義
image 引數允許配置構建器及其應如何操作專案。下表總結了可用引數及其預設值
| 引數 / (使用者屬性) | 描述 | 預設值 |
|---|---|---|
|
要使用的構建器映象的名稱。 |
|
|
是否將構建器視為 受信任的。 |
如果構建器是 |
|
拉取的任何構建器、執行和構建包映象的平臺(作業系統和架構)。必須採用 |
無預設值,表示應使用主機機器的平臺。 |
|
要使用的執行映象的名稱。 |
無預設值,表示應使用 Builder 元資料中指定的執行映象。 |
|
生成的映象的 映象名稱。 |
|
|
用於確定何時從倉庫拉取構建器和執行映象的 策略。可接受的值為 |
|
|
應傳遞給構建器的環境變數。 |
|
|
構建器在構建映象時應使用的構建包。只使用指定的構建包,覆蓋構建器中包含的預設構建包。構建包引用必須採用以下形式之一
|
無,表示構建器應使用其中包含的構建包。 |
|
構建映象時應掛載到構建器容器的 卷繫結掛載。在建立構建器容器時,繫結將未經解析和驗證地傳遞給 Docker。繫結必須採用以下形式之一
其中
|
|
|
構建器容器將配置使用的 網路驅動程式。提供的值在建立構建器容器時未經驗證地傳遞給 Docker。 |
|
|
是否在構建前清理快取。 |
|
|
啟用構建器操作的詳細日誌記錄。 |
|
|
是否將生成的映象釋出到 Docker 倉庫。 |
|
|
要應用於生成的映象的一個或多個附加標籤。提供給 |
|
|
構建器和構建包在映象構建過程中儲存檔案的臨時工作區。該值可以是命名卷或繫結掛載位置。 |
Docker daemon 中的命名卷,其名稱源自映象名稱。 |
|
包含構建包建立並由映象構建過程使用的層的快取。該值可以是命名卷或繫結掛載位置。 |
Docker daemon 中的命名卷,其名稱源自映象名稱。 |
|
包含構建包建立並由映象啟動過程使用的層的快取。該值可以是命名卷或繫結掛載位置。 |
Docker daemon 中的命名卷,其名稱源自映象名稱。 |
|
將用於設定生成映象元資料中 |
固定日期,啟用 構建可重現性。 |
|
應用程式內容將上傳到構建器映象中的目錄路徑。應用程式內容也將在生成的映象中的此位置。 |
|
|
將應用於構建器容器的 安全選項,以字串值陣列的形式提供 |
Linux 和 macOS 上為 |
外掛使用編譯器的外掛配置或 maven.compiler.target 屬性檢測專案的目標 Java 相容性。當使用預設的 Paketo 構建器和構建包時,外掛會指示構建包安裝相同的 Java 版本。您可以根據 構建器配置 示例所示覆蓋此行為。 |
有關更多詳細資訊,另請參閱 示例。
標籤格式
提供給 tags 選項的值應為完整的映象引用。接受的格式為 [domainHost:port/][path/]name[:tag][@digest]。
如果缺少域,則預設為 docker.io。如果缺少路徑,則預設為 library。如果缺少標籤,則預設為 latest。
一些示例
-
my-image導致映象引用docker.io/library/my-image:latest -
my-repository/my-image導致docker.io/my-repository/my-image:latest -
example.com/my-repository/my-image:1.0.0將按原樣使用
spring-boot:build-image
org.springframework.boot:spring-boot-maven-plugin:4.0.0
使用構建包將應用程式打包成 OCI 映象,分叉生命週期以確保 package 已執行。此目標適用於命令列呼叫。如果您需要在構建中配置目標 execution,請改用 build-image-no-fork。
可選引數
| 名稱 | 型別 | 預設值 |
|---|---|---|
|
||
|
||
|
||
|
||
|
|
|
|
|
|
|
||
|
||
|
||
|
||
|
||
|
|
|
|
|
|
|
|
|
|
||
|
||
|
||
|
||
|
||
|
|
|
|
引數詳情
applicationDirectory
Image#applicationDirectory 的別名,用於支援透過命令列屬性進行配置。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
cleanCache
Image#cleanCache 的別名,用於支援透過命令列屬性進行配置。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
createdDate
Image#createdDate 的別名,用於支援透過命令列屬性進行配置。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
excludeDevtools
從重新打包的歸檔中排除 Spring Boot devtools。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
excludeDockerCompose
從重新打包的歸檔中排除 Spring Boot 開發服務。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
excludeGroupIds
要排除的 groupId 名稱的逗號分隔列表(精確匹配)。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
excludes
要排除的 artifact 定義集合。Exclude 元素定義了強制的 groupId 和 artifactId 元件以及可選的 classifier 元件。當配置為屬性時,值應以逗號分隔,元件以冒號分隔:groupId:artifactId,groupId:artifactId:classifier
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
image
映象配置,包含 builder、runImage、name、env、cleanCache、verboseLogging、pullPolicy 和 publish 選項。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
imageBuilder
Image#builder 的別名,用於支援透過命令列屬性進行配置。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
imageName
Image#name 的別名,用於支援透過命令列屬性進行配置。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
imagePlatform
Image#imagePlatform 的別名,用於支援透過命令列屬性進行配置。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
includes
要包含的 artifact 定義集合。Include 元素定義了強制的 groupId 和 artifactId 元件以及可選的 classifier 元件。當配置為屬性時,值應以逗號分隔,元件以冒號分隔:groupId:artifactId,groupId:artifactId:classifier
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
layout
歸檔型別(對應於依賴項在其中佈局的方式)。可能的值為 JAR、WAR、ZIP、DIR、NONE。預設為根據歸檔型別猜測。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
network
Image#network 的別名,用於支援透過命令列屬性進行配置。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
publish
Image#publish 的別名,用於支援透過命令列屬性進行配置。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
pullPolicy
Image#pullPolicy 的別名,用於支援透過命令列屬性進行配置。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
runImage
Image#runImage 的別名,用於支援透過命令列屬性進行配置。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
spring-boot:build-image-no-fork
org.springframework.boot:spring-boot-maven-plugin:4.0.0
使用構建包將應用程式打包成 OCI 映象,但不分叉生命週期。在構建中配置目標 execution 時應使用此目標。要在命令列上呼叫此目標,請改用 build-image。
可選引數
| 名稱 | 型別 | 預設值 |
|---|---|---|
|
||
|
||
|
||
|
||
|
|
|
|
|
|
|
||
|
||
|
||
|
||
|
||
|
|
|
|
|
|
|
|
|
|
||
|
||
|
||
|
||
|
||
|
|
|
|
引數詳情
applicationDirectory
Image#applicationDirectory 的別名,用於支援透過命令列屬性進行配置。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
cleanCache
Image#cleanCache 的別名,用於支援透過命令列屬性進行配置。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
createdDate
Image#createdDate 的別名,用於支援透過命令列屬性進行配置。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
excludeDevtools
從重新打包的歸檔中排除 Spring Boot devtools。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
excludeDockerCompose
從重新打包的歸檔中排除 Spring Boot 開發服務。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
excludeGroupIds
要排除的 groupId 名稱的逗號分隔列表(精確匹配)。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
excludes
要排除的 artifact 定義集合。Exclude 元素定義了強制的 groupId 和 artifactId 元件以及可選的 classifier 元件。當配置為屬性時,值應以逗號分隔,元件以冒號分隔:groupId:artifactId,groupId:artifactId:classifier
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
image
映象配置,包含 builder、runImage、name、env、cleanCache、verboseLogging、pullPolicy 和 publish 選項。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
imageBuilder
Image#builder 的別名,用於支援透過命令列屬性進行配置。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
imageName
Image#name 的別名,用於支援透過命令列屬性進行配置。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
imagePlatform
Image#imagePlatform 的別名,用於支援透過命令列屬性進行配置。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
includes
要包含的 artifact 定義集合。Include 元素定義了強制的 groupId 和 artifactId 元件以及可選的 classifier 元件。當配置為屬性時,值應以逗號分隔,元件以冒號分隔:groupId:artifactId,groupId:artifactId:classifier
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
layout
歸檔型別(對應於依賴項在其中佈局的方式)。可能的值為 JAR、WAR、ZIP、DIR、NONE。預設為根據歸檔型別猜測。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
network
Image#network 的別名,用於支援透過命令列屬性進行配置。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
publish
Image#publish 的別名,用於支援透過命令列屬性進行配置。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
pullPolicy
Image#pullPolicy 的別名,用於支援透過命令列屬性進行配置。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
runImage
Image#runImage 的別名,用於支援透過命令列屬性進行配置。
名稱 |
|
|---|---|
型別 |
|
預設值 |
|
使用者屬性 |
|
自 |
|
示例
自定義映象構建器
如果您需要自定義用於建立映象的構建器或用於啟動已構建映象的執行映象,請按以下示例配置外掛
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<builder>mine/java-cnb-builder</builder>
<runImage>mine/java-cnb-run</runImage>
</image>
</configuration>
</plugin>
</plugins>
</build>
</project>
此配置將使用名為 mine/java-cnb-builder 且標籤為 latest 的構建器映象,以及名為 mine/java-cnb-run 且標籤為 latest 的執行映象。
構建器和執行映象也可以在命令列上指定,如下例所示
$ mvn spring-boot:build-image -Dspring-boot.build-image.builder=mine/java-cnb-builder -Dspring-boot.build-image.runImage=mine/java-cnb-run
構建器配置
如果構建器使用環境變數暴露配置選項,則可以使用 env 屬性設定這些選項。
以下是 配置 Paketo Java 構建包在構建時使用的 JVM 版本 的示例
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<env>
<BP_JVM_VERSION>17</BP_JVM_VERSION>
</env>
</image>
</configuration>
</plugin>
</plugins>
</build>
</project>
如果 Docker daemon 執行的構建器與構建包下載工件的網路位置之間存在網路代理,則需要配置構建器使用該代理。當使用 Paketo 構建器時,可以透過設定 HTTPS_PROXY 和/或 HTTP_PROXY 環境變數來完成,如下例所示
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<env>
<HTTP_PROXY>http://proxy.example.com</HTTP_PROXY>
<HTTPS_PROXY>https://proxy.example.com</HTTPS_PROXY>
</env>
</image>
</configuration>
</plugin>
</plugins>
</build>
</project>
執行時 JVM 配置
Paketo Java 構建包透過設定 JAVA_TOOL_OPTIONS 環境變數 配置 JVM 執行時環境。可以修改構建包提供的 JAVA_TOOL_OPTIONS 值,以在應用程式映象在容器中啟動時自定義 JVM 執行時行為。
應儲存在映象中並應用於每次部署的環境變數修改可以按照 Paketo 文件 中所述設定,如下例所示
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<env>
<BPE_DELIM_JAVA_TOOL_OPTIONS xml:space="preserve"> </BPE_DELIM_JAVA_TOOL_OPTIONS>
<BPE_APPEND_JAVA_TOOL_OPTIONS>-XX:+HeapDumpOnOutOfMemoryError</BPE_APPEND_JAVA_TOOL_OPTIONS>
</env>
</image>
</configuration>
</plugin>
</plugins>
</build>
</project>
自定義映象名稱
預設情況下,映象名稱是根據專案的 artifactId 和 version 推斷出來的,例如 docker.io/library/${project.artifactId}:${project.version}。您可以控制名稱,如下例所示
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<name>example.com/library/${project.artifactId}</name>
</image>
</configuration>
</plugin>
</plugins>
</build>
</project>
此配置未提供顯式標籤,因此使用 latest。也可以指定標籤,可以使用 ${project.version}、構建中可用的任何屬性或硬編碼版本。 |
映象名稱也可以在命令列上指定,如下例所示
$ mvn spring-boot:build-image -Dspring-boot.build-image.imageName=example.com/library/my-app:v1
構建包
預設情況下,構建器將使用構建器映象中包含的構建包並按預定義順序應用它們。可以提供一組替代的構建包,以應用未包含在構建器中的構建包,或更改包含的構建包的順序。當提供一個或多個構建包時,只應用指定的構建包。
以下示例指示構建器使用打包在 .tgz 檔案中的自定義構建包,然後是構建器中包含的構建包。
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<buildpacks>
<buildpack>file:///path/to/example-buildpack.tgz</buildpack>
<buildpack>urn:cnb:builder:paketo-buildpacks/java</buildpack>
</buildpacks>
</image>
</configuration>
</plugin>
</plugins>
</build>
</project>
構建包可以按以下任何一種形式指定。
CNB 構建器中的構建包(如果構建器中只有一個與 buildpack-id 匹配的構建包,則可以省略版本)
-
urn:cnb:builder:buildpack-id -
urn:cnb:builder:[email protected] -
buildpack-id
包含構建包內容的目錄路徑(Windows 上不支援)
-
file:///path/to/buildpack/ -
/path/to/buildpack/
包含構建包內容的 gzipped tar 檔案的路徑
-
file:///path/to/buildpack.tgz -
/path/to/buildpack.tgz
包含 打包構建包 的 OCI 映象
-
docker://example/buildpack -
docker:///example/buildpack:latest -
docker:///example/buildpack@sha256:45b23dee08… -
example/buildpack -
example/buildpack:latest -
example/buildpack@sha256:45b23dee08…
映象釋出
可以透過啟用 publish 選項將生成的映象釋出到 Docker 倉庫。
如果 Docker 倉庫需要身份驗證,可以使用 docker.publishRegistry 引數配置憑據。如果 Docker 倉庫不需要身份驗證,則可以省略 docker.publishRegistry 配置。
映象將釋出到的倉庫由映象名稱的倉庫部分決定(在這些示例中為 docker.example.com)。如果配置了 docker.publishRegistry 憑據幷包含 url 引數,則此值將傳遞給倉庫,但不用於確定釋出倉庫位置。 |
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<name>docker.example.com/library/${project.artifactId}</name>
<publish>true</publish>
</image>
<docker>
<publishRegistry>
<username>user</username>
<password>secret</password>
</publishRegistry>
</docker>
</configuration>
</plugin>
</plugins>
</build>
</project>
publish 選項也可以在命令列上指定,如下例所示
$ mvn spring-boot:build-image -Dspring-boot.build-image.imageName=docker.example.com/library/my-app:v1 -Dspring-boot.build-image.publish=true
當在命令列上使用 publish 選項並進行身份驗證時,您可以像此示例中一樣使用屬性提供憑據
$ mvn spring-boot:build-image \
-Ddocker.publishRegistry.username=user \
-Ddocker.publishRegistry.password=secret \
-Ddocker.publishRegistry.url=docker.example.com \
-Dspring-boot.build-image.publish=true \
-Dspring-boot.build-image.imageName=docker.example.com/library/my-app:v1
並在 XML 配置中引用屬性
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<docker>
<publishRegistry>
<url>${docker.publishRegistry.url}</url>
<username>${docker.publishRegistry.username}</username>
<password>${docker.publishRegistry.password}</password>
</publishRegistry>
</docker>
</configuration>
</plugin>
</plugins>
</build>
</project>
構建器快取和工作區配置
CNB 構建器快取用於構建和啟動映象的層。預設情況下,這些快取作為命名卷儲存在 Docker daemon 中,其名稱源自目標映象的完整名稱。如果映象名稱頻繁更改,例如當專案版本用作映象名稱中的標籤時,快取可能會頻繁失效。
可以配置快取卷使用替代名稱,以更好地控制快取生命週期,如下例所示
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<buildCache>
<volume>
<name>cache-${project.artifactId}.build</name>
</volume>
</buildCache>
<launchCache>
<volume>
<name>cache-${project.artifactId}.launch</name>
</volume>
</launchCache>
</image>
</configuration>
</plugin>
</plugins>
</build>
</project>
構建器和構建包在映象構建過程中需要一個位置來儲存臨時檔案。預設情況下,此臨時構建工作區儲存在命名卷中。
可以配置快取和構建工作區使用繫結掛載而不是命名卷,如下例所示
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<buildWorkspace>
<bind>
<source>/tmp/cache-${project.artifactId}.work</source>
</bind>
</buildWorkspace>
<buildCache>
<bind>
<source>/tmp/cache-${project.artifactId}.build</source>
</bind>
</buildCache>
<launchCache>
<bind>
<source>/tmp/cache-${project.artifactId}.launch</source>
</bind>
</launchCache>
</image>
</configuration>
</plugin>
</plugins>
</build>
</project>
Docker 配置
minikube 的 Docker 配置
外掛可以與 minikube 提供的 Docker daemon 通訊,而不是預設的本地連線。
在 Linux 和 macOS 上,minikube 啟動後可以使用命令 eval $(minikube docker-env) 設定環境變數。
也可以透過提供類似於以下示例中所示的連線詳細資訊來配置外掛使用 minikube daemon
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<docker>
<host>tcp://192.168.99.100:2376</host>
<tlsVerify>true</tlsVerify>
<certPath>/home/user/.minikube/certs</certPath>
</docker>
</configuration>
</plugin>
</plugins>
</build>
</project>
podman 的 Docker 配置
外掛可以與 podman 容器引擎 通訊。
可以透過提供類似於以下示例中所示的連線詳細資訊來配置外掛使用 podman 本地連線
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<docker>
<host>unix:///run/user/1000/podman/podman.sock</host>
<bindHostToBuilder>true</bindHostToBuilder>
</docker>
</configuration>
</plugin>
</plugins>
</build>
</project>
安裝 colima CLI 後,可以使用命令 podman info --format='{{.Host.RemoteSocket.Path}}' 獲取此示例中所示的 docker.host 配置屬性的值。 |
Colima 的 Docker 配置
外掛可以與 Colima 提供的 Docker daemon 通訊。可以使用以下命令設定 DOCKER_HOST 環境變數
$ export DOCKER_HOST=$(docker context inspect colima -f '{{.Endpoints.docker.Host}}')
也可以透過提供類似於以下示例中所示的連線詳細資訊來配置外掛使用 Colima daemon
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<docker>
<host>unix:///${user.home}/.colima/docker.sock</host>
</docker>
</configuration>
</plugin>
</plugins>
</build>
</project>
Docker 身份驗證配置
如果構建器或執行映象儲存在支援使用者身份驗證的私有 Docker 倉庫中,則可以使用 docker.builderRegistry 引數提供身份驗證詳細資訊,如下例所示
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<docker>
<builderRegistry>
<username>user</username>
<password>secret</password>
<url>https://docker.example.com/v1/</url>
<email>[email protected]</email>
</builderRegistry>
</docker>
</configuration>
</plugin>
</plugins>
</build>
</project>
如果構建器或執行映象儲存在支援令牌身份驗證的私有 Docker 倉庫中,則可以使用 docker.builderRegistry 引數提供令牌值,如下例所示
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<docker>
<builderRegistry>
<token>9cbaf023786cd7...</token>
</builderRegistry>
</docker>
</configuration>
</plugin>
</plugins>
</build>
</project>