Refactor Dockerfile with layered jar (#1248)

* Refactor Dockerfile with layered jar

* Add projectVersion print task

* Refactor docker build process

* Remove aliyun maven mirror

* Correct multi platforms list

* Correct multi platforms list again

* Make docker platforms configurable
pull/1249/head
John Niang 2021-01-27 23:55:57 +08:00 committed by GitHub
parent 30c9baf92b
commit bcf26fdc50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 34 deletions

View File

@ -156,27 +156,39 @@ jobs:
key: ${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-dependencies-
- name: Get version of halo
id: get_halo_version
run: |
version=$(./gradlew -q projectVersion)
echo "Trying to build and publish halo:${version}"
echo "HALO_VERSION=${version}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build docker image
run: |
docker info
docker images
export DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}
export DOCKER_TOKEN=${{ secrets.DOCKER_TOKEN }}
export DOCKER_IMAGE_NAME=${{ secrets.DOCKER_IMAGE_NAME }}
export TAG_LATEST=false
echo "Building and pushing with version tag."
./gradlew bootBuildImage -x bootJar --publishImage
PRE_RELEASE=${{ github.event.release.prerelease }}
if ! $PRE_RELEASE
then
echo "Building and pushing with latest tag."
export TAG_LATEST=true
./gradlew bootBuildImage -x bootJar --publishImage
else
echo "Skipped building and pushing with latest tag due to pre-release."
fi
docker images
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
-
name: Build and push with version tag
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: ${{ secrets.DOCKER_PLATFORMS }}
push: true
tags: |
${{ secrets.DOCKER_IMAGE_NAME }}:${{ env.HALO_VERSION}}
- name: Build and push with latest tag
uses: docker/build-push-action@v2
if: "!github.event.release.prerelease"
with:
context: .
file: ./Dockerfile
platforms: ${{ secrets.DOCKER_PLATFORMS }}
push: true
tags: |
${{ secrets.DOCKER_IMAGE_NAME }}:latest

View File

@ -1,17 +1,26 @@
FROM adoptopenjdk/openjdk11-openj9
VOLUME /tmp
FROM adoptopenjdk:11-jre-hotspot as builder
WORKDIR application
ARG JAR_FILE=build/libs/*.jar
ARG TIME_ZONE=Asia/Shanghai
COPY ${JAR_FILE} application.jar
RUN java -Djarmode=layertools -jar application.jar extract
################################
FROM adoptopenjdk:11-jre-hotspot
MAINTAINER johnniang <johnniang@fastmail.com>
WORKDIR application
COPY --from=builder application/dependencies/ ./
COPY --from=builder application/spring-boot-loader/ ./
COPY --from=builder application/snapshot-dependencies/ ./
COPY --from=builder application/application/ ./
# JVM_XMS and JVM_XMX configs deprecated for removal in halov1.4.4
ENV JVM_XMS="256m" \
JVM_XMX="256m" \
JVM_OPTS="" \
TZ=${TIME_ZONE}
JVM_OPTS="-Xmx256m -Xms256m" \
TZ=Asia/Shanghai
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo $TZ > /etc/timezone
COPY ${JAR_FILE} halo.jar
EXPOSE 8090
ENTRYPOINT java -Xms${JVM_XMS} -Xmx${JVM_XMX} ${JVM_OPTS} -Djava.security.egd=file:/dev/./urandom -server -jar halo.jar
ENTRYPOINT java -Xms${JVM_XMS} -Xmx${JVM_XMX} ${JVM_OPTS} -Djava.security.egd=file:/dev/./urandom org.springframework.boot.loader.JarLauncher

View File

@ -22,9 +22,9 @@ checkstyle {
repositories {
mavenLocal()
maven {
url "https://maven.aliyun.com/nexus/content/groups/public"
}
// maven {
// url "https://maven.aliyun.com/nexus/content/groups/public"
// }
mavenCentral()
jcenter()
}
@ -174,3 +174,10 @@ test {
useJUnitPlatform()
testLogging.showStandardStreams = true
}
task projectVersion {
description = 'Prints current project version.'
doLast {
println project.version
}
}