Skip to content

Commit

Permalink
feat: support jib-jvm-flags-extension-maven
Browse files Browse the repository at this point in the history
  • Loading branch information
shihyuho committed Jan 12, 2024
1 parent 81e312f commit 8e8bb75
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ Non-Heap = Direct Memory + Metaspace + Reserved Code Cache + (Thread Stack * Thr

1.`entrypoint.sh` 放入 Jib 所使用的 Base Image 中,例如放在 `/tmp` 資料夾下。
2. 在 Jib 的配置中,將 entrypoint 設定為 `/tmp/entrypoint.sh`
3. 在 Jib 的配置中,建議避免使用 `jvmFlags`,而是使用 `JAVA_OPTS` 環境變數。

在 Jib 中若[自定義了 entrypoint](https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin#custom-container-entrypoint)`<jvmFlags>` 參數將無法被直接引用。因此,`entrypoint.sh` 還整合了公司開發的 [jib-jvm-flags-extension-maven](https://github.com/softleader/jib-jvm-flags-extension-maven)。藉由這個 Jib Extension,我們就可以繼續使用 `<jvmFlags>`

## 開發前準備

Expand Down
11 changes: 9 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ TMP_ENV="/tmp/.env"

$BIN/memory-calculator -o $TMP_ENV

# 檢查 /app/jib-jvm-flags-file 是否存在
if [ -f /app/jib-jvm-flags-file ]; then
JVM_FLAGS=$(cat /app/jib-jvm-flags-file)
else
JVM_FLAGS=""
fi

if [ -f "$TMP_ENV" ]; then
source $TMP_ENV
exec java -cp $( cat /app/jib-classpath-file ) $( cat /app/jib-main-class-file )
exec java $JVM_FLAGS -cp $( cat /app/jib-classpath-file ) $( cat /app/jib-main-class-file )
else
exec java $JAVA_OPTS -cp $( cat /app/jib-classpath-file ) $( cat /app/jib-main-class-file )
exec java $JVM_FLAGS $JAVA_OPTS -cp $( cat /app/jib-classpath-file ) $( cat /app/jib-main-class-file )
fi

0 comments on commit 8e8bb75

Please sign in to comment.