在docker使用Gradle來build graalvm 的project
在docker使用Gradle來build graalvm 的project
Gradle 目前網上很多資料可以build Java project,所以一開始我寫成這樣
- Dockerfile
FROM gradle:6.8-jdk11 AS build
COPY . /app
WORKDIR /app
RUN java -version
RUN gradle :bzkflow:bootJar --refresh-dependencies
FROM springci/graalvm-ce:master-java11
RUN java -version
ENTRYPOINT ["java","-Dspring.profiles.active=prod","-cp","app:app/lib/*","net.bzk.flow.BzkflowApplication",">","/console.log"]
直接build graalvm project 會有class not fund error
我的專案有用到 graalvm 的polyglot,所以一般的jdk11是無法 compile,
會出現class not fund 的error,且gradle並沒有出base on graalvm 的image,
自己寫一個base on graalvm的 gradle image
基本邏輯是用 graalvm
的 image 然後再去安裝 gradle
source code在這裡 : https://github.com/kirinchen/docker-gradle-graalvm
example
- Dockerfile
FROM kirinddt/gradle-graalvm:latest
COPY . /app
WORKDIR /app
RUN java -version
RUN gradle :bzkflow:bootJar --refresh-dependencies
RUN java -version
ENTRYPOINT ["java","-Dspring.profiles.active=prod","-cp","app:app/lib/*","net.bzk.flow.BzkflowApplication",">","/console.log"]
這樣就可以成功執行了,而且也不用compile完後,再切換runtime的jdk執行了
FROM kirinddt/gradle-graalvm:latest
COPY . /app
WORKDIR /app
RUN java -version
RUN gradle :bzkflow:bootJar --refresh-dependencies
RUN java -version
ENTRYPOINT ["java","-Dspring.profiles.active=prod","-cp","app:app/lib/*","net.bzk.flow.BzkflowApplication",">","/console.log"]
這樣就可以成功執行了,而且也不用compile完後,再切換runtime的jdk執行了
留言
張貼留言