From 09ab6cc6f669592507d8d4590fc46dcf7dddeb1c Mon Sep 17 00:00:00 2001 From: Juliano Costa Date: Thu, 7 Nov 2024 13:58:28 +0100 Subject: [PATCH] [chore] Move build args to .env file (#1767) * Move build args to .env file * Try different approach * Try individual value * explicitly export to $GITHUB_ENV * test each step * Remove if * explicitly export to $GITHUB_ENV no if * single build arg * Persist env vars across steps * check if .env is accessible * Load whole .env file * Move current build args to .env file * changelog * fix indentation --- .env | 10 +++++++--- .github/workflows/component-build-images.yml | 15 +++++++++++++++ CHANGELOG.md | 2 ++ docker-compose-tests.yml | 2 ++ docker-compose.minimal.yml | 4 ++++ docker-compose.yml | 8 ++++++++ src/adservice/Dockerfile | 4 ++-- src/currencyservice/Dockerfile | 2 +- src/frauddetectionservice/Dockerfile | 4 ++-- src/kafka/Dockerfile | 4 ++-- test/tracetesting/Dockerfile | 2 +- 11 files changed, 46 insertions(+), 11 deletions(-) diff --git a/.env b/.env index 9fd97857b7..1e4c83dffd 100644 --- a/.env +++ b/.env @@ -5,18 +5,22 @@ IMAGE_VERSION=1.12.0 IMAGE_NAME=ghcr.io/open-telemetry/demo DEMO_VERSION=latest +# Build Args +TRACETEST_IMAGE_VERSION=v1.5.2 +OTEL_JAVA_AGENT_VERSION=2.9.0 +OPENTELEMETRY_CPP_VERSION=1.17.0 + # Dependent images COLLECTOR_CONTRIB_IMAGE=otel/opentelemetry-collector-contrib:0.108.0 FLAGD_IMAGE=ghcr.io/open-feature/flagd:v0.11.2 GRAFANA_IMAGE=grafana/grafana:11.3.0 JAEGERTRACING_IMAGE=jaegertracing/all-in-one:1.60 -# must also update version field in +# must also update version field in src/grafana/provisioning/datasources/opensearch.yaml OPENSEARCH_IMAGE=opensearchproject/opensearch:2.17.1 POSTGRES_IMAGE=postgres:16.4 PROMETHEUS_IMAGE=quay.io/prometheus/prometheus:v2.54.1 VALKEY_IMAGE=valkey/valkey:8.0-alpine -# must also update the version arg in ./test/tracetesting/Dockerfile -TRACETEST_IMAGE=kubeshop/tracetest:v1.5.2 +TRACETEST_IMAGE=kubeshop/tracetest:${TRACETEST_IMAGE_VERSION} # Demo Platform ENV_PLATFORM=local diff --git a/.github/workflows/component-build-images.yml b/.github/workflows/component-build-images.yml index d209aeb29b..715f3feafb 100644 --- a/.github/workflows/component-build-images.yml +++ b/.github/workflows/component-build-images.yml @@ -124,6 +124,17 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 + - name: Load environment variables from .env file + run: | + if [ -f .env ]; then + # Filter out comments and empty lines, then add each variable to $GITHUB_ENV + grep -vE '^\s*#|^\s*$' .env | while read -r line; do + echo "$line" >> $GITHUB_ENV + done + else + echo ".env file not found!" + exit 1 + fi - name: Check for changes and set push options id: check_changes run: | @@ -172,6 +183,10 @@ jobs: file: ${{ matrix.file_tag.file }} platforms: linux/amd64,linux/arm64 push: ${{ inputs.push }} + build-args: | + OTEL_JAVA_AGENT_VERSION=${{ env.OTEL_JAVA_AGENT_VERSION }} + OPENTELEMETRY_CPP_VERSION=${{ env.OPENTELEMETRY_CPP_VERSION }} + TRACETEST_IMAGE_VERSION=${{ env.TRACETEST_IMAGE_VERSION }} tags: | ${{ inputs.dockerhub_repo }}:${{ inputs.version }}-${{matrix.file_tag.tag_suffix }} ${{ inputs.dockerhub_repo }}:latest-${{matrix.file_tag.tag_suffix }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 53016fb759..63d2a85038 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ the release. * [grafana] Update grafana to 11.3.0 ([#1764](https://github.com/open-telemetry/opentelemetry-demo/pull/1764)) +* [chore] Move build args to .env file + ([#1767](https://github.com/open-telemetry/opentelemetry-demo/pull/1767)) ## 1.12.0 diff --git a/docker-compose-tests.yml b/docker-compose-tests.yml index 1c97ceb6ac..8bab0cb0cd 100644 --- a/docker-compose-tests.yml +++ b/docker-compose-tests.yml @@ -34,6 +34,8 @@ services: build: context: ./ dockerfile: ./test/tracetesting/Dockerfile + args: + TRACETEST_IMAGE_VERSION: ${TRACETEST_IMAGE_VERSION} environment: - AD_SERVICE_ADDR - CART_SERVICE_ADDR diff --git a/docker-compose.minimal.yml b/docker-compose.minimal.yml index f5b65faa91..38e93575a1 100644 --- a/docker-compose.minimal.yml +++ b/docker-compose.minimal.yml @@ -27,6 +27,8 @@ services: dockerfile: ${AD_SERVICE_DOCKERFILE} cache_from: - ${IMAGE_NAME}:${IMAGE_VERSION}-adservice + args: + OTEL_JAVA_AGENT_VERSION: ${OTEL_JAVA_AGENT_VERSION} deploy: resources: limits: @@ -133,6 +135,8 @@ services: dockerfile: ${CURRENCY_SERVICE_DOCKERFILE} cache_from: - ${IMAGE_NAME}:${IMAGE_VERSION}-currencyservice + args: + OPENTELEMETRY_CPP_VERSION: ${OPENTELEMETRY_CPP_VERSION} deploy: resources: limits: diff --git a/docker-compose.yml b/docker-compose.yml index 39ec207aa9..d0f52dccf7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -53,6 +53,8 @@ services: dockerfile: ${AD_SERVICE_DOCKERFILE} cache_from: - ${IMAGE_NAME}:${IMAGE_VERSION}-adservice + args: + OTEL_JAVA_AGENT_VERSION: ${OTEL_JAVA_AGENT_VERSION} deploy: resources: limits: @@ -171,6 +173,8 @@ services: dockerfile: ${CURRENCY_SERVICE_DOCKERFILE} cache_from: - ${IMAGE_NAME}:${IMAGE_VERSION}-currencyservice + args: + OPENTELEMETRY_CPP_VERSION: ${OPENTELEMETRY_CPP_VERSION} deploy: resources: limits: @@ -224,6 +228,8 @@ services: dockerfile: ${FRAUD_SERVICE_DOCKERFILE} cache_from: - ${IMAGE_NAME}:${IMAGE_VERSION}-frauddetectionservice + args: + OTEL_JAVA_AGENT_VERSION: ${OTEL_JAVA_AGENT_VERSION} deploy: resources: limits: @@ -637,6 +643,8 @@ services: dockerfile: ${KAFKA_SERVICE_DOCKERFILE} cache_from: - ${IMAGE_NAME}:${IMAGE_VERSION}-kafka + args: + OTEL_JAVA_AGENT_VERSION: ${OTEL_JAVA_AGENT_VERSION} deploy: resources: limits: diff --git a/src/adservice/Dockerfile b/src/adservice/Dockerfile index 97c2ebd1ed..369af01a05 100644 --- a/src/adservice/Dockerfile +++ b/src/adservice/Dockerfile @@ -20,11 +20,11 @@ RUN ./gradlew installDist -PprotoSourceDir=./proto FROM eclipse-temurin:21-jre -ARG version=2.6.0 +ARG OTEL_JAVA_AGENT_VERSION WORKDIR /usr/src/app/ COPY --from=builder /usr/src/app/ ./ -ADD --chmod=644 https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v$version/opentelemetry-javaagent.jar /usr/src/app/opentelemetry-javaagent.jar +ADD --chmod=644 https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v$OTEL_JAVA_AGENT_VERSION/opentelemetry-javaagent.jar /usr/src/app/opentelemetry-javaagent.jar ENV JAVA_TOOL_OPTIONS=-javaagent:/usr/src/app/opentelemetry-javaagent.jar EXPOSE ${AD_SERVICE_PORT} diff --git a/src/currencyservice/Dockerfile b/src/currencyservice/Dockerfile index a5cd79bb7c..3c26de728a 100644 --- a/src/currencyservice/Dockerfile +++ b/src/currencyservice/Dockerfile @@ -18,7 +18,7 @@ FROM alpine:3.18 as builder RUN apk update && apk add git cmake make g++ grpc-dev protobuf-dev linux-headers -ARG OPENTELEMETRY_CPP_VERSION=1.15.0 +ARG OPENTELEMETRY_CPP_VERSION RUN git clone https://github.com/open-telemetry/opentelemetry-cpp \ && cd opentelemetry-cpp/ \ diff --git a/src/frauddetectionservice/Dockerfile b/src/frauddetectionservice/Dockerfile index c7e17158b3..f3f62401da 100644 --- a/src/frauddetectionservice/Dockerfile +++ b/src/frauddetectionservice/Dockerfile @@ -14,11 +14,11 @@ RUN gradle shadowJar FROM gcr.io/distroless/java17-debian11 -ARG version=2.4.0 +ARG OTEL_JAVA_AGENT_VERSION WORKDIR /usr/src/app/ COPY --from=builder /usr/src/app/build/libs/frauddetectionservice-1.0-all.jar ./ -ADD --chmod=644 https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v$version/opentelemetry-javaagent.jar /app/opentelemetry-javaagent.jar +ADD --chmod=644 https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v$OTEL_JAVA_AGENT_VERSION/opentelemetry-javaagent.jar /app/opentelemetry-javaagent.jar ENV JAVA_TOOL_OPTIONS=-javaagent:/app/opentelemetry-javaagent.jar ENTRYPOINT [ "java", "-jar", "frauddetectionservice-1.0-all.jar" ] diff --git a/src/kafka/Dockerfile b/src/kafka/Dockerfile index b3e6a236b5..42e4ffd139 100644 --- a/src/kafka/Dockerfile +++ b/src/kafka/Dockerfile @@ -5,11 +5,11 @@ FROM apache/kafka:3.7.0 USER root -ARG version=2.4.0 +ARG OTEL_JAVA_AGENT_VERSION USER appuser -ADD --chown=appuser:appuser https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v$version/opentelemetry-javaagent.jar /tmp/opentelemetry-javaagent.jar +ADD --chown=appuser:appuser https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v$OTEL_JAVA_AGENT_VERSION/opentelemetry-javaagent.jar /tmp/opentelemetry-javaagent.jar ENV KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092,CONTROLLER://0.0.0.0:9093 ENV KAFKA_CONTROLLER_QUORUM_VOTERS='1@0.0.0.0:9093' diff --git a/test/tracetesting/Dockerfile b/test/tracetesting/Dockerfile index 388269cd48..a76dea5d52 100644 --- a/test/tracetesting/Dockerfile +++ b/test/tracetesting/Dockerfile @@ -7,7 +7,7 @@ FROM alpine WORKDIR /app # The build-images workflow action does not set a build-arg so we need to specify a default value here -ARG TRACETEST_IMAGE_VERSION=v1.5.2 +ARG TRACETEST_IMAGE_VERSION RUN apk --update add bash jq curl RUN curl -L https://raw.githubusercontent.com/kubeshop/tracetest/main/install-cli.sh | bash -s -- $TRACETEST_IMAGE_VERSION