Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.

Commit

Permalink
build musl docker images, add AppCDS to musl dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
natanbc committed Apr 22, 2021
1 parent 7efc774 commit ce10905
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 37 deletions.
94 changes: 64 additions & 30 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ plugins {
id 'java'
id 'application'
id 'com.github.johnrengelman.shadow' version '5.2.0'
id 'com.palantir.docker' version '0.25.0'
}

def versionObj = new Version(major: 0, minor: 20, revision: 2)
Expand Down Expand Up @@ -109,32 +108,6 @@ dependencies {
implementation "com.google.code.findbugs:jsr305:$jsr305Version"
}

docker {
if(System.getenv("DOCKERFILE") != null) {
def f = file(System.getenv("DOCKERFILE"))
if(f.exists()) {
dockerfile f
} else {
println("Dockerfile '" + System.getenv("DOCKERFILE") + "' doesn't exist")
}
}
name "natanbc/andesite:${getCommitHash()}"
//only set latest tag for releases, so `docker pull natanbc/andesite`
//pulls the latest stable version
if(System.getenv("TAG") != null && !System.getenv("TAG").trim().isEmpty()) {
tag 'versioned', "natanbc/andesite:${versionObj}"
tag 'latest', 'natanbc/andesite:latest'
}
files "build/libs/andesite-${versionObj}-linux-x86-64.jar",
"build/libs/andesite-${versionObj}-linux-musl-x86-64.jar",
project(':jattach-debug-plugin').getTasksByName('jar', false).outputs,
"jlink.sh"
buildArgs([
version: versionObj.toString(),
jattachVersion: jattachVersion
])
}

def natives = [
'all',
'darwin',
Expand All @@ -151,15 +124,15 @@ def natives = [

task buildAll {}

tasks.docker.dependsOn buildAll
task buildImages {}

buildAll.dependsOn ':jattach-debug-plugin:jar'
buildAll.dependsOn ':api:jar'
buildAll.dependsOn ':api:javadoc'

task ci {
dependsOn buildAll
dependsOn tasks.docker
dependsOn dockerTag
dependsOn buildImages
}

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
Expand Down Expand Up @@ -205,6 +178,27 @@ natives.each { arch ->
buildAll.dependsOn shadowTask
}

def baseTags = ["natanbc/andesite:${getCommitHash()}"]
//only set latest tag for releases, so `docker pull natanbc/andesite`
//pulls the latest stable version
if(System.getenv("TAG") != null && !System.getenv("TAG").trim().isEmpty()) {
baseTags << "natanbc/andesite:${version}"
baseTags << "natanbc/andesite:latest"
}

buildImages.dependsOn createDockerBuild(
"normal",
file("Dockerfile"),
baseTags,
(ShadowJar)rootProject.tasks.findByName("shadow-linux-x86-64")
)
buildImages.dependsOn createDockerBuild(
"alpine",
file("musl/Dockerfile"),
baseTags.collect {"$it-alpine" },
(ShadowJar)rootProject.tasks.findByName("shadow-linux-musl-x86-64")
)

def lint = [
"auxiliaryclass",
"cast",
Expand Down Expand Up @@ -286,6 +280,46 @@ static def getCommitHash() {
p.getIn().text.trim()
}

def createDockerBuild(String name, File dockerfile, List<String> tags, ShadowJar shadowTask) {
if(!dockerfile.exists()) {
throw new Exception("Dockerfile '$dockerfile' doesn't exist")
}
def dir = new File(project.buildDir, "docker/$name")
dir.mkdirs()
def jarTask = (org.gradle.jvm.tasks.Jar)tasks.getByPath(":jattach-debug-plugin:jar")
def copyResults = tasks.create("dockerCopy-$name", Copy) {
from(shadowTask.outputs) {
include "*.jar"
}
from(jarTask.outputs) {
include "*.jar"
}
from('.') {
include "jlink.sh"
}
into dir
}

def dockerBuild = tasks.create("dockerBuild-$name", Exec) {
dependsOn copyResults
workingDir dir
executable = 'docker'
def argList = [
"build",
"-f",
dockerfile.getAbsolutePath(),
"--build-arg",
"version=${rootProject.version}",
"--build-arg",
"jattachVersion=${jattachVersion}",
]
tags.each { argList << "-t" << it }
argList << "."
args = argList
}
return dockerBuild
}

def getBuildNumber() {
def properties = [
"BUILD_NUMBER",
Expand Down
6 changes: 0 additions & 6 deletions jattach-debug-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ plugins {
sourceCompatibility = 15
targetCompatibility = 15

repositories {
jcenter()
maven { url 'https://dl.bintray.com/natanbc/maven' }
maven { url 'https://jitpack.io' }
}

dependencies {
compileOnly project(':api')
}
6 changes: 5 additions & 1 deletion musl/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ RUN apk add --no-cache openjdk15-jdk openjdk15-jmods jattach --repository http:/
mkdir logs && \
chown -R andesite:andesite logs

RUN jrt/bin/java -Xshare:dump && \
jrt/bin/java -XX:ArchiveClassesAtExit=app.jsa -jar andesite.jar cds && \
rm -rf /tmp/* logs/*

USER andesite

CMD ["jrt/bin/java", "-Djdk.tls.client.protocols=TLSv1,TLSv1.1,TLSv1.2", "-jar", "andesite.jar"]
CMD ["jrt/bin/java", "-XX:SharedArchiveFile=app.jsa", "-Djdk.tls.client.protocols=TLSv1,TLSv1.1,TLSv1.2", "-jar", "andesite.jar"]

0 comments on commit ce10905

Please sign in to comment.