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

feat: download opentelemetry jar outside of Dockerfile #697

Merged
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
9 changes: 9 additions & 0 deletions .github/actions/publish-docker-image/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ runs:
steps:
- uses: actions/checkout@v3.3.0

- 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 @@ -97,6 +105,7 @@ runs:
file: ${{ inputs.rootDir }}/src/main/docker/Dockerfile
build-args: |
JAR=${{ inputs.rootDir }}/build/libs/${{ inputs.imagename }}.jar
OTEL_JAR=${{ inputs.rootDir }}/opentelemetry-javaagent.jar
push: ${{ inputs.do_push == 'true' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down
36 changes: 28 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -153,24 +153,44 @@ subprojects {
file("${project.projectDir}/src/main/docker/Dockerfile").exists()
) {

//actually apply the plugin to the (sub-)project
val agentFile = project.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.27.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 {
project.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)
}
}

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

// configure the "dockerize" task
val dockerTask = tasks.create("dockerize", DockerBuildImage::class) {
dockerFile.set(file("${project.projectDir}/src/main/docker/Dockerfile"))
val dockerTask: DockerBuildImage = tasks.create("dockerize", DockerBuildImage::class) {
val dockerContextDir = project.projectDir
dockerFile.set(file("$dockerContextDir/src/main/docker/Dockerfile"))
images.add("${project.name}:${project.version}")
images.add("${project.name}:latest")
// specify platform with the -Dplatform flag:
if (System.getProperty("platform") != null)
platform.set(System.getProperty("platform"))
buildArgs.put("JAR", "build/libs/${project.name}.jar")
inputDir.set(file(project.projectDir))
buildArgs.put("OTEL_JAR", agentFile.relativeTo(dockerContextDir).path)
inputDir.set(file(dockerContextDir))
}

// make sure "shadowJar" always runs before "dockerize"
dockerTask.dependsOn(tasks.findByName(ShadowJavaPlugin.SHADOW_JAR_TASK_NAME))
// make sure always runs after "dockerize" and after "copyOtel"
dockerTask.dependsOn(tasks.named(ShadowJavaPlugin.SHADOW_JAR_TASK_NAME))
.dependsOn(downloadOtel)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,9 @@
# SPDX-License-Identifier: Apache-2.0
#

FROM alpine:3.18.0 AS otel

ENV OTEL_AGENT_LOCATION "https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.12.1/opentelemetry-javaagent.jar"

HEALTHCHECK NONE

RUN apk update && apk add curl=8.2.1-r0 --no-cache
RUN curl -L --proto "=https" -sSf ${OTEL_AGENT_LOCATION} --output /tmp/opentelemetry-javaagent.jar

FROM eclipse-temurin:17.0.6_10-jre-alpine
ARG JAR
ARG OTEL_JAR

ARG APP_USER=docker
ARG APP_UID=10100
Expand All @@ -48,8 +40,8 @@ RUN adduser \
USER "$APP_USER"
WORKDIR /app

COPY --from=otel /tmp/opentelemetry-javaagent.jar .
COPY ${JAR} edc-controlplane.jar
COPY ${OTEL_JAR} opentelemetry-javaagent.jar

HEALTHCHECK NONE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,9 @@
#
# SPDX-License-Identifier: Apache-2.0
#
FROM alpine:3.18.2 AS otel

ENV OTEL_AGENT_LOCATION "https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.12.1/opentelemetry-javaagent.jar"

HEALTHCHECK NONE

RUN apk update && apk add curl=8.2.1-r0 --no-cache
RUN curl -L --proto "=https" -sSf ${OTEL_AGENT_LOCATION} --output /tmp/opentelemetry-javaagent.jar

FROM eclipse-temurin:17.0.6_10-jre-alpine
ARG JAR
ARG OTEL_JAR

ARG APP_USER=docker
ARG APP_UID=10100
Expand All @@ -47,8 +39,8 @@ RUN adduser \
USER "$APP_USER"
WORKDIR /app

COPY --from=otel /tmp/opentelemetry-javaagent.jar .
COPY ${JAR} edc-controlplane.jar
COPY ${OTEL_JAR} opentelemetry-javaagent.jar

HEALTHCHECK NONE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,10 @@
#
# SPDX-License-Identifier: Apache-2.0
#
FROM alpine:3.18.2 AS otel

ENV OTEL_AGENT_LOCATION "https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.12.1/opentelemetry-javaagent.jar"

HEALTHCHECK NONE

RUN apk update && apk add curl=8.2.1-r0 --no-cache
RUN curl -L --proto "=https" -sSf ${OTEL_AGENT_LOCATION} --output /tmp/opentelemetry-javaagent.jar

FROM eclipse-temurin:17.0.6_10-jre-alpine
ARG JAR
ARG OTEL_JAR

ARG APP_USER=docker
ARG APP_UID=10100
Expand All @@ -47,8 +40,8 @@ RUN adduser \
USER "$APP_USER"
WORKDIR /app

COPY --from=otel /tmp/opentelemetry-javaagent.jar .
COPY ${JAR} edc-controlplane.jar
COPY ${OTEL_JAR} opentelemetry-javaagent.jar

HEALTHCHECK NONE

Expand Down
12 changes: 2 additions & 10 deletions edc-dataplane/edc-dataplane-azure-vault/src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,9 @@
#
# SPDX-License-Identifier: Apache-2.0
#
FROM alpine:3.18.2 AS otel

ENV OTEL_AGENT_LOCATION "https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.12.1/opentelemetry-javaagent.jar"

HEALTHCHECK NONE

RUN apk update && apk add curl=8.2.1-r0 --no-cache
RUN curl -L --proto "=https" -sSf ${OTEL_AGENT_LOCATION} --output /tmp/opentelemetry-javaagent.jar

FROM eclipse-temurin:17.0.6_10-jre-alpine
ARG JAR
ARG OTEL_JAR

ARG APP_USER=docker
ARG APP_UID=10100
Expand All @@ -47,8 +39,8 @@ RUN adduser \
USER "$APP_USER"
WORKDIR /app

COPY --from=otel /tmp/opentelemetry-javaagent.jar .
COPY ${JAR} edc-dataplane.jar
COPY ${OTEL_JAR} opentelemetry-javaagent.jar

HEALTHCHECK NONE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,10 @@
#
# SPDX-License-Identifier: Apache-2.0
#
FROM alpine:3.18.2 AS otel

ENV OTEL_AGENT_LOCATION "https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.12.1/opentelemetry-javaagent.jar"

HEALTHCHECK NONE

RUN apk update && apk add curl=8.2.1-r0 --no-cache
RUN curl -L --proto "=https" -sSf ${OTEL_AGENT_LOCATION} --output /tmp/opentelemetry-javaagent.jar

FROM eclipse-temurin:17.0.6_10-jre-alpine
ARG JAR
ARG OTEL_JAR

ARG APP_USER=docker
ARG APP_UID=10100
Expand All @@ -47,8 +40,9 @@ RUN adduser \
USER "$APP_USER"
WORKDIR /app

COPY --from=otel /tmp/opentelemetry-javaagent.jar .
COPY ${JAR} edc-dataplane.jar
COPY ${OTEL_JAR} opentelemetry-javaagent.jar


HEALTHCHECK NONE

Expand Down