Skip to content

Commit

Permalink
[chore] Move build args to .env file (#1767)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
julianocosta89 authored Nov 7, 2024
1 parent 1002cf0 commit 09ab6cc
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 11 deletions.
10 changes: 7 additions & 3 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/component-build-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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 }}
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions docker-compose-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.minimal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/adservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion src/currencyservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/ \
Expand Down
4 changes: 2 additions & 2 deletions src/frauddetectionservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
4 changes: 2 additions & 2 deletions src/kafka/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion test/tracetesting/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 09ab6cc

Please sign in to comment.