Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zip+tar to publishable artifacts and add a run.sh script #1082

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gradle/projects.main.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ polaris-quarkus-defaults=quarkus/defaults
polaris-quarkus-service=quarkus/service
polaris-quarkus-server=quarkus/server
polaris-quarkus-admin=quarkus/admin
polaris-quarkus-run-script=quarkus/run-script
polaris-eclipselink=extension/persistence/eclipselink
polaris-jpa-model=extension/persistence/jpa-model
polaris-tests=integration-tests
Expand Down
64 changes: 47 additions & 17 deletions quarkus/admin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ plugins {
id("distribution")
}

val runScript by configurations.creating { description = "Used to reference the run.sh script" }

val distributionZip by
configurations.creating { description = "Used to reference the distribution zip" }

val distributionTar by
configurations.creating { description = "Used to reference the distribution tarball" }

dependencies {
implementation(project(":polaris-core"))
implementation(project(":polaris-version"))
Expand All @@ -53,10 +61,12 @@ dependencies {

testRuntimeOnly(project(":polaris-eclipselink"))
testRuntimeOnly("org.postgresql:postgresql")

runScript(project(":polaris-quarkus-run-script", "runScript"))
}

quarkus {
quarkusBuildProperties.put("quarkus.package.type", "uber-jar")
quarkusBuildProperties.put("quarkus.package.type", "fast-jar")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this going to complicate the tool usage? It's easier to download and run a single jar than to download a zip, unpack, then run.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that uber-jar is more convenient for the admin tool.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIU the current approach it is already a tgz/zip file that needs to be extracted, because of the necessary LICENSE/NOTICE files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we include the NOTICE test into the user jar and have a CLI option to print it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uber jar is also an option: we can ship LICENSE/NOTICE in the meta-inf. By the way, I'm working on the license and notice content for binary distributions.

// Pull manifest attributes from the "main" `jar` task to get the
// release-information into the jars generated by Quarkus.
quarkusBuildProperties.putAll(
Expand All @@ -72,28 +82,48 @@ quarkus {
)
}

publishing {
publications {
named<MavenPublication>("maven") {
val quarkusBuild = tasks.getByName<QuarkusBuild>("quarkusBuild")
artifact(quarkusBuild.runnerJar) {
classifier = "runner"
builtBy(quarkusBuild)
}
distributions {
main {
contents {
from(runScript)
from(project.layout.buildDirectory.dir("quarkus-app"))
from("../../NOTICE")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO it's better to square the license/notice on the target artifacts. I can change that in second step along with license/notice.

from("../../LICENSE-BINARY-DIST").rename("LICENSE-BINARY-DIST", "LICENSE")
}
}
}

tasks.named("distZip") { dependsOn("quarkusBuild") }
val quarkusBuild = tasks.named<QuarkusBuild>("quarkusBuild")

tasks.named("distTar") { dependsOn("quarkusBuild") }
val distTar =
tasks.named<Tar>("distTar") {
dependsOn(quarkusBuild)
// Trigger resolution (and build) of the run-script artifact
inputs.files(runScript)
compression = Compression.GZIP
}

distributions {
main {
contents {
from("../../NOTICE")
from("../../LICENSE-BINARY-DIST").rename("LICENSE-BINARY-DIST", "LICENSE")
from(project.layout.buildDirectory) { include("polaris-quarkus-admin-*-runner.jar") }
val distZip =
tasks.named<Zip>("distZip") {
dependsOn(quarkusBuild)
// Trigger resolution (and build) of the run-script artifact
inputs.files(runScript)
}

// Expose runnable jar via quarkusRunner configuration for integration-tests that require the
// server.
artifacts {
add(distributionTar.name, provider { distTar.get().archiveFile }) { builtBy(distTar) }
add(distributionZip.name, provider { distZip.get().archiveFile }) { builtBy(distZip) }
}

afterEvaluate {
publishing {
publications {
named<MavenPublication>("maven") {
artifact(distTar.get().archiveFile) { builtBy(distTar) }
artifact(distZip.get().archiveFile) { builtBy(distZip) }
}
}
}
}
36 changes: 36 additions & 0 deletions quarkus/run-script/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

val runScript by
configurations.creating { description = "Used to provide the run.sh script" }

description = "Provides run.sh script for Quarkus fast-jar for distribution tar/zip"

// This is a separate project that only provides run scripts (run.sh).
// It is a separate project, because it is not good practice to directly
// reference files outside any project.
//
// Artifacts are NOT published as a Maven artifacts.

artifacts {
add(runScript.name, project.layout.projectDirectory.file("scripts/run.sh"))
}

// Need this task to be present, there are no checks/tests in this project though
tasks.register("check")
39 changes: 39 additions & 0 deletions quarkus/run-script/scripts/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

# Linux Quarkus fast-jar run script for Apache Polaris

set -e

script_dir="$(dirname "$0")"

if [ -z "$JAVA_HOME" ] ; then
JAVACMD="`\\unset -f command; \\command -v java`"
else
JAVACMD="$JAVA_HOME/bin/java"
fi

if [ ! -x "$JAVACMD" ] ; then
echo "The JAVA_HOME environment variable is not defined correctly," >&2
echo "this environment variable is needed to run this program." >&2
exit 1
fi

exec "${JAVACMD}" -jar "${script_dir}/quarkus-run.jar"
55 changes: 51 additions & 4 deletions quarkus/server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

import io.quarkus.gradle.tasks.QuarkusBuild
import io.quarkus.gradle.tasks.QuarkusRun

plugins {
Expand All @@ -28,6 +29,17 @@ plugins {
id("distribution")
}

val quarkusRunner by
configurations.creating { description = "Used to reference the generated runner-jar" }

val runScript by configurations.creating { description = "Used to reference the run.sh script" }

val distributionZip by
configurations.creating { description = "Used to reference the distribution zip" }

val distributionTar by
configurations.creating { description = "Used to reference the distribution tarball" }

dependencies {
implementation(project(":polaris-core"))
implementation(project(":polaris-api-management-service"))
Expand All @@ -42,6 +54,8 @@ dependencies {
// enforce the Quarkus _platform_ here, to get a consistent and validated set of dependencies
implementation(enforcedPlatform(libs.quarkus.bom))
implementation("io.quarkus:quarkus-container-image-docker")

runScript(project(":polaris-quarkus-run-script", "runScript"))
}

quarkus {
Expand All @@ -61,10 +75,6 @@ quarkus {
)
}

tasks.named("distZip") { dependsOn("quarkusBuild") }

tasks.named("distTar") { dependsOn("quarkusBuild") }

tasks.register("run") { dependsOn("quarkusRun") }

tasks.named<QuarkusRun>("quarkusRun") {
Expand All @@ -75,10 +85,47 @@ tasks.named<QuarkusRun>("quarkusRun") {
distributions {
main {
contents {
from(runScript)
from(project.layout.buildDirectory.dir("quarkus-app"))
from("../../NOTICE")
from("../../LICENSE-BINARY-DIST").rename("LICENSE-BINARY-DIST", "LICENSE")
exclude("lib/main/io.quarkus.quarkus-container-image*")
}
}
}

val quarkusBuild = tasks.named<QuarkusBuild>("quarkusBuild")

val distTar =
tasks.named<Tar>("distTar") {
dependsOn(quarkusBuild)
inputs.files(runScript)
compression = Compression.GZIP
}

val distZip =
tasks.named<Zip>("distZip") {
dependsOn(quarkusBuild)
inputs.files(runScript)
}

// Expose runnable jar via quarkusRunner configuration for integration-tests that require the
// server.
artifacts {
add(quarkusRunner.name, provider { quarkusBuild.get().fastJar.resolve("quarkus-run.jar") }) {
builtBy(quarkusBuild)
}
add(distributionTar.name, provider { distTar.get().archiveFile }) { builtBy(distTar) }
add(distributionZip.name, provider { distZip.get().archiveFile }) { builtBy(distZip) }
}

afterEvaluate {
publishing {
publications {
named<MavenPublication>("maven") {
artifact(distTar.get().archiveFile) { builtBy(distTar) }
artifact(distZip.get().archiveFile) { builtBy(distZip) }
}
}
}
}