Skip to content

Commit

Permalink
feat: remove project root from the docker image (#1460)
Browse files Browse the repository at this point in the history
* feat: remove project root from the docker image

* dependencies

* Trigger build

* dependencies
  • Loading branch information
ndr-brt authored Jul 25, 2024
1 parent c057c53 commit 44585f6
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 62 deletions.
21 changes: 6 additions & 15 deletions .github/actions/publish-docker-image/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,12 @@ inputs:
docker_tag:
required: false
description: 'additional docker tags'
do_push:
required: false
default: 'false'
description: 'whether or not to actually push the image'

runs:
using: "composite"
steps:
- uses: actions/checkout@v4

- name: Download OpenTelemetry
shell: bash
run: |-
# "jq -r" removes the quotation marks, that would trip up "wget"
URL=$(grep "val openTelemetryAgentUrl = " build.gradle.kts | awk -F'= ' '{print $2}' | jq -r)
wget -O ${{ inputs.rootDir }}/opentelemetry-javaagent.jar -q $URL
#####################
# Login to DockerHub
#####################
Expand Down Expand Up @@ -101,12 +91,13 @@ runs:
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
context: ${{ inputs.rootDir }}
file: ${{ inputs.rootDir }}/build/resources/docker/Dockerfile
build-args: |
JAR=${{ inputs.rootDir }}/build/libs/${{ inputs.imagename }}.jar
OTEL_JAR=${{ inputs.rootDir }}/opentelemetry-javaagent.jar
push: ${{ inputs.do_push == 'true' }}
JAR=build/libs/${{ inputs.imagename }}.jar
OTEL_JAR=build/resources/otel/opentelemetry-javaagent.jar
ADDITIONAL_FILES=build/legal/*
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

Expand Down
1 change: 1 addition & 0 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ maven/mavencentral/io.netty/netty-transport/4.1.110.Final, Apache-2.0 AND BSD-3-
maven/mavencentral/io.netty/netty-transport/4.1.111.Final, Apache-2.0 AND BSD-3-Clause AND MIT, approved, CQ20926
maven/mavencentral/io.netty/netty-transport/4.1.86.Final, Apache-2.0 AND BSD-3-Clause AND MIT, approved, CQ20926
maven/mavencentral/io.opentelemetry.instrumentation/opentelemetry-instrumentation-annotations/1.32.0, Apache-2.0, approved, #11684
maven/mavencentral/io.opentelemetry.javaagent/opentelemetry-javaagent/1.32.0, Apache-2.0, restricted, clearlydefined
maven/mavencentral/io.opentelemetry/opentelemetry-api/1.32.0, Apache-2.0, approved, #11682
maven/mavencentral/io.opentelemetry/opentelemetry-context/1.32.0, Apache-2.0, approved, #11683
maven/mavencentral/io.projectreactor.netty/reactor-netty-core/1.0.45, Apache-2.0, approved, #9687
Expand Down
65 changes: 25 additions & 40 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -140,77 +140,62 @@ allprojects {

}

// the "dockerize" task is added to all projects that use the `shadowJar` plugin
subprojects {
afterEvaluate {
// the "dockerize" task is added to all projects that use the `shadowJar` plugin
if (project.plugins.hasPlugin("com.github.johnrengelman.shadow")) {
val buildDir = project.layout.buildDirectory.get().asFile

val agentFile = buildDir.resolve("opentelemetry-javaagent.jar")
// create task to download the opentelemetry agent
val openTelemetryAgentUrl = "https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.32.0/opentelemetry-javaagent.jar"
val downloadOtel = tasks.create("downloadOtel") {
// only execute task if the opentelemetry agent does not exist. invoke the "clean" task to force
onlyIf {
!agentFile.exists()
}
// this task could be the first in the graph, so "build/" may not yet exist. Let's be defensive
doFirst {
buildDir.mkdirs()
}
// download the jar file
doLast {
val download = { url: String, destFile: File ->
ant.invokeMethod(
"get",
mapOf("src" to url, "dest" to destFile)
)
}
logger.lifecycle("Downloading OpenTelemetry Agent")
download(openTelemetryAgentUrl, agentFile)
val downloadOpentelemetryAgent = tasks.create("downloadOpentelemetryAgent", Copy::class) {
val openTelemetry = configurations.create("open-telemetry")

dependencies {
openTelemetry(libs.opentelemetry.javaagent)
}
}

val shadowJarTask = tasks.named(ShadowJavaPlugin.SHADOW_JAR_TASK_NAME).get()
from(openTelemetry)
into("build/resources/otel")
rename { "opentelemetry-javaagent.jar" }
}

// this task copies some legal docs into the build folder, so we can easily copy them into the docker images
val copyLegalDocs = tasks.create("copyLegalDocs", Copy::class) {
from(project.rootProject.projectDir)
into("${buildDir}/legal")
into("build/legal")
include("SECURITY.md", "NOTICE.md", "DEPENDENCIES", "LICENSE")
dependsOn(shadowJarTask)
}

val copyDockerfile = tasks.create("copyDockerfile", Copy::class) {
from(rootProject.projectDir.toPath().resolve("resources"))
into(project.layout.buildDirectory.dir("resources").get().dir("docker"))
include("Dockerfile")
}
shadowJarTask.dependsOn(copyDockerfile)

val shadowJarTask = tasks.named(ShadowJavaPlugin.SHADOW_JAR_TASK_NAME).get()

shadowJarTask
.dependsOn(copyDockerfile)
.dependsOn(copyLegalDocs)
.dependsOn(downloadOpentelemetryAgent)

//actually apply the plugin to the (sub-)project
apply(plugin = "com.bmuschko.docker-remote-api")

val dockerTask: DockerBuildImage = tasks.create("dockerize", DockerBuildImage::class) {
dockerFile.set(project.layout.buildDirectory.asFile.get().toPath().resolve("resources").resolve("docker").resolve("Dockerfile").toFile())
dockerFile.set(File("build/resources/docker/Dockerfile"))

val dockerContextDir = project.projectDir
images.add("${project.name}:${project.version}")
images.add("${project.name}:latest")
// specify platform with the -Dplatform flag:
if (System.getProperty("platform") != null)

if (System.getProperty("platform") != null) {
platform.set(System.getProperty("platform"))
}

buildArgs.put("JAR", "build/libs/${project.name}.jar")
buildArgs.put("OTEL_JAR", agentFile.relativeTo(dockerContextDir).path)
buildArgs.put("OTEL_JAR", "build/resources/otel/opentelemetry-javaagent.jar")
buildArgs.put("ADDITIONAL_FILES", "build/legal/*")
inputDir.set(file(dockerContextDir))
}

// make sure always runs after "dockerize" and after "copyOtel"
dockerTask
.dependsOn(shadowJarTask)
.dependsOn(downloadOtel)
.dependsOn(copyLegalDocs)
dockerTask.dependsOn(shadowJarTask)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ dependencies {


tasks.withType<ShadowJar> {
exclude("**/pom.properties", "**/pom.xm")
mergeServiceFiles()
archiveFileName.set("${project.name}.jar")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ dependencies {


tasks.withType<ShadowJar> {
exclude("**/pom.properties", "**/pom.xm")
mergeServiceFiles()
archiveFileName.set("${project.name}.jar")
}
Expand Down
1 change: 0 additions & 1 deletion edc-controlplane/edc-runtime-memory/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ dependencies {
}

tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
exclude("**/pom.properties", "**/pom.xm")
mergeServiceFiles()
archiveFileName.set("${project.name}.jar")
}
Expand Down
1 change: 0 additions & 1 deletion edc-dataplane/edc-dataplane-azure-vault/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ dependencies {
}

tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
exclude("**/pom.properties", "**/pom.xm")
mergeServiceFiles()
archiveFileName.set("${project.name}.jar")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ dependencies {
}

tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
exclude("**/pom.properties", "**/pom.xm")
mergeServiceFiles()
archiveFileName.set("${project.name}.jar")
}
Expand Down
1 change: 0 additions & 1 deletion edc-tests/runtime/mock-connector/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ edcBuild {
}

tasks.withType<ShadowJar> {
exclude("**/pom.properties", "**/pom.xm")
mergeServiceFiles()
archiveFileName.set("${project.name}.jar")
}
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jupiter = "5.10.3"
nimbus = "9.40"
netty-mockserver = "5.15.0"
okhttp = "4.12.0"
opentelemetry = "1.32.0"
postgres = "42.7.3"
restAssured = "5.5.0"
rsApi = "4.0.0"
Expand Down Expand Up @@ -220,6 +221,7 @@ jakartaJson = { module = "org.glassfish:jakarta.json", version.ref = "jakarta-js
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "jupiter" }
nimbus-jwt = { module = "com.nimbusds:nimbus-jose-jwt", version.ref = "nimbus" }
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
opentelemetry-javaagent = { module = "io.opentelemetry.javaagent:opentelemetry-javaagent", version.ref = "opentelemetry" }
netty-mockserver = { module = "org.mock-server:mockserver-netty", version.ref = "netty-mockserver" }
postgres = { module = "org.postgresql:postgresql", version.ref = "postgres" }
restAssured = { module = "io.rest-assured:rest-assured", version.ref = "restAssured" }
Expand Down
1 change: 0 additions & 1 deletion samples/edc-dast/edc-dast-runtime/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ application {
}

tasks.withType<ShadowJar> {
exclude("**/pom.properties", "**/pom.xm")
mergeServiceFiles()
archiveFileName.set("${project.name}.jar")
}
Expand Down

0 comments on commit 44585f6

Please sign in to comment.