From 148cdf2e5ebb1cd986fdb6b794a95478e0818ca1 Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Mon, 1 Jul 2024 21:46:51 -0400 Subject: [PATCH 01/11] multiplatform build --- Makefile | 28 ++---- docker-compose-tests.yml | 133 +++++++++++++++++++++++++++ docker-compose.yml | 128 -------------------------- src/accountingservice/Dockerfile | 11 ++- src/adservice/Dockerfile | 4 +- src/cartservice/src/Dockerfile | 6 +- src/frauddetectionservice/Dockerfile | 4 +- src/shippingservice/Dockerfile | 4 + 8 files changed, 160 insertions(+), 158 deletions(-) create mode 100644 docker-compose-tests.yml diff --git a/Makefile b/Makefile index 4316d60e43..1417371893 100644 --- a/Makefile +++ b/Makefile @@ -79,24 +79,16 @@ install-tools: $(MISSPELL) build: $(DOCKER_COMPOSE_CMD) build -.PHONY: build-and-push-dockerhub -build-and-push-dockerhub: - $(DOCKER_COMPOSE_CMD) --env-file .dockerhub.env -f docker-compose.yml build - $(DOCKER_COMPOSE_CMD) --env-file .dockerhub.env -f docker-compose.yml push - -.PHONY: build-and-push-ghcr -build-and-push-ghcr: - $(DOCKER_COMPOSE_CMD) --env-file .ghcr.env -f docker-compose.yml build - $(DOCKER_COMPOSE_CMD) --env-file .ghcr.env -f docker-compose.yml push - -.PHONY: build-env-file -build-env-file: - cp .env .dockerhub.env - sed -i '/IMAGE_VERSION=.*/c\IMAGE_VERSION=${RELEASE_VERSION}' .dockerhub.env - sed -i '/IMAGE_NAME=.*/c\IMAGE_NAME=${DOCKERHUB_REPO}' .dockerhub.env - cp .env .ghcr.env - sed -i '/IMAGE_VERSION=.*/c\IMAGE_VERSION=${RELEASE_VERSION}' .ghcr.env - sed -i '/IMAGE_NAME=.*/c\IMAGE_NAME=${GHCR_REPO}' .ghcr.env +.PHONY: build-and-push +build-and-push: + $(DOCKER_COMPOSE_CMD) $(DOCKER_COMPOSE_ENV) build --push + +# Build and push multiplatform images (linux/amd64, linux/arm64) using buildx. +# Requires docker with buildx enabled and a multi-platform capable builder in use. +.PHONY: build-multiplatform-and-push +build-multiplatform-and-push: + # Because buildx bake does not support --env-file yet, we need to load it into the environment first. + set -a; . .env.override; set +a && docker buildx bake -f docker-compose.yml --push --set "*.platform=linux/amd64,linux/arm64" .PHONY: run-tests run-tests: diff --git a/docker-compose-tests.yml b/docker-compose-tests.yml new file mode 100644 index 0000000000..37bf3319b7 --- /dev/null +++ b/docker-compose-tests.yml @@ -0,0 +1,133 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +include: + - docker-compose.yml # depend on the main docker-compose file + +# ***** +# Tests +# ***** +# Frontend Tests +frontendTests: + image: ${IMAGE_NAME}:${DEMO_VERSION}-frontend-tests + container_name: frontend-tests + build: + context: ./ + dockerfile: ./src/frontend/Dockerfile.cypress + profiles: + - tests + volumes: + - ./src/frontend/cypress/videos:/app/cypress/videos + - ./src/frontend/cypress/screenshots:/app/cypress/screenshots + environment: + - CYPRESS_baseUrl=http://${FRONTEND_ADDR} + - FRONTEND_ADDR + - NODE_ENV=production + depends_on: + - frontend + +# Tracebased Tests +traceBasedTests: + image: ${IMAGE_NAME}:${DEMO_VERSION}-traceBasedTests + container_name: traceBasedTests + profiles: + - tests + build: + context: ./ + dockerfile: ./test/tracetesting/Dockerfile + environment: + - AD_SERVICE_ADDR + - CART_SERVICE_ADDR + - CHECKOUT_SERVICE_ADDR + - CURRENCY_SERVICE_ADDR + - EMAIL_SERVICE_ADDR + - FRONTEND_ADDR + - PAYMENT_SERVICE_ADDR + - PRODUCT_CATALOG_SERVICE_ADDR + - RECOMMENDATION_SERVICE_ADDR + - SHIPPING_SERVICE_ADDR + - KAFKA_SERVICE_ADDR + extra_hosts: + - "host.docker.internal:host-gateway" + volumes: + - ./test/tracetesting:/app/test/tracetesting + - ./pb:/app/pb + depends_on: + tracetest-server: + condition: service_healthy + # adding demo services as dependencies + frontend: + condition: service_started + adservice: + condition: service_started + cartservice: + condition: service_started + checkoutservice: + condition: service_started + currencyservice: + condition: service_started + emailservice: + condition: service_started + paymentservice: + condition: service_started + productcatalogservice: + condition: service_started + recommendationservice: + condition: service_started + shippingservice: + condition: service_started + quoteservice: + condition: service_started + accountingservice: + condition: service_started + frauddetectionservice: + condition: service_started + flagd: + condition: service_started + +tracetest-server: + image: ${TRACETEST_IMAGE} + platform: linux/amd64 + container_name: tracetest-server + profiles: + - tests + - odd # Observabilty-Driven Development (ODD) + volumes: + - type: bind + source: ./test/tracetesting/tracetest-config.yaml + target: /app/tracetest.yaml + - type: bind + source: ./test/tracetesting/tracetest-provision.yaml + target: /app/provision.yaml + command: --provisioning-file /app/provision.yaml + ports: + - 11633:11633 + extra_hosts: + - "host.docker.internal:host-gateway" + depends_on: + tracetest-postgres: + condition: service_healthy + otelcol: + condition: service_started + healthcheck: + test: [ "CMD", "wget", "--spider", "localhost:11633" ] + interval: 1s + timeout: 3s + retries: 60 + +tracetest-postgres: + image: ${POSTGRES_IMAGE} + container_name: tracetest-postgres + profiles: + - tests + - odd # Observabilty-Driven Development (ODD) + environment: + POSTGRES_PASSWORD: postgres + POSTGRES_USER: postgres + healthcheck: + test: pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB" + interval: 1s + timeout: 5s + retries: 60 + ports: + - 5432 diff --git a/docker-compose.yml b/docker-compose.yml index 511883c21f..6adfcfff78 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -757,131 +757,3 @@ services: ports: - "9200" logging: *logging - - # ***** - # Tests - # ***** - # Frontend Tests - frontendTests: - image: ${IMAGE_NAME}:${DEMO_VERSION}-frontend-tests - container_name: frontend-tests - build: - context: ./ - dockerfile: ./src/frontend/Dockerfile.cypress - profiles: - - tests - volumes: - - ./src/frontend/cypress/videos:/app/cypress/videos - - ./src/frontend/cypress/screenshots:/app/cypress/screenshots - environment: - - CYPRESS_baseUrl=http://${FRONTEND_ADDR} - - FRONTEND_ADDR - - NODE_ENV=production - depends_on: - - frontend - - # Tracebased Tests - traceBasedTests: - image: ${IMAGE_NAME}:${DEMO_VERSION}-traceBasedTests - container_name: traceBasedTests - profiles: - - tests - build: - context: ./ - dockerfile: ./test/tracetesting/Dockerfile - environment: - - AD_SERVICE_ADDR - - CART_SERVICE_ADDR - - CHECKOUT_SERVICE_ADDR - - CURRENCY_SERVICE_ADDR - - EMAIL_SERVICE_ADDR - - FRONTEND_ADDR - - PAYMENT_SERVICE_ADDR - - PRODUCT_CATALOG_SERVICE_ADDR - - RECOMMENDATION_SERVICE_ADDR - - SHIPPING_SERVICE_ADDR - - KAFKA_SERVICE_ADDR - extra_hosts: - - "host.docker.internal:host-gateway" - volumes: - - ./test/tracetesting:/app/test/tracetesting - - ./pb:/app/pb - depends_on: - tracetest-server: - condition: service_healthy - # adding demo services as dependencies - frontend: - condition: service_started - adservice: - condition: service_started - cartservice: - condition: service_started - checkoutservice: - condition: service_started - currencyservice: - condition: service_started - emailservice: - condition: service_started - paymentservice: - condition: service_started - productcatalogservice: - condition: service_started - recommendationservice: - condition: service_started - shippingservice: - condition: service_started - quoteservice: - condition: service_started - accountingservice: - condition: service_started - frauddetectionservice: - condition: service_started - flagd: - condition: service_started - - tracetest-server: - image: ${TRACETEST_IMAGE} - platform: linux/amd64 - container_name: tracetest-server - profiles: - - tests - - odd # Observabilty-Driven Development (ODD) - volumes: - - type: bind - source: ./test/tracetesting/tracetest-config.yaml - target: /app/tracetest.yaml - - type: bind - source: ./test/tracetesting/tracetest-provision.yaml - target: /app/provision.yaml - command: --provisioning-file /app/provision.yaml - ports: - - 11633:11633 - extra_hosts: - - "host.docker.internal:host-gateway" - depends_on: - tracetest-postgres: - condition: service_healthy - otelcol: - condition: service_started - healthcheck: - test: [ "CMD", "wget", "--spider", "localhost:11633" ] - interval: 1s - timeout: 3s - retries: 60 - - tracetest-postgres: - image: ${POSTGRES_IMAGE} - container_name: tracetest-postgres - profiles: - - tests - - odd # Observabilty-Driven Development (ODD) - environment: - POSTGRES_PASSWORD: postgres - POSTGRES_USER: postgres - healthcheck: - test: pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB" - interval: 1s - timeout: 5s - retries: 60 - ports: - - 5432 diff --git a/src/accountingservice/Dockerfile b/src/accountingservice/Dockerfile index f2410184cc..617f73304f 100644 --- a/src/accountingservice/Dockerfile +++ b/src/accountingservice/Dockerfile @@ -1,23 +1,24 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +FROM --platform=${TARGETPLATFORM} mcr.microsoft.com/dotnet/aspnet:8.0 AS base USER app WORKDIR /app -FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +FROM --platform=${BUILDPLATFORM} mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG TARGETARCH ARG BUILD_CONFIGURATION=Release WORKDIR /src COPY ["/src/accountingservice/", "AccountingService/"] COPY ["/pb/demo.proto", "AccountingService/proto/"] -RUN dotnet restore "./AccountingService/AccountingService.csproj" +RUN dotnet restore "./AccountingService/AccountingService.csproj" -r linux-musl-$TARGETARCH WORKDIR "/src/AccountingService" -RUN dotnet build "./AccountingService.csproj" -c $BUILD_CONFIGURATION -o /app/build +RUN dotnet build "./AccountingService.csproj" -r linux-musl-$TARGETARCH -c $BUILD_CONFIGURATION -o /app/build FROM build AS publish ARG BUILD_CONFIGURATION=Release -RUN dotnet publish "./AccountingService.csproj" --use-current-runtime -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false +RUN dotnet publish "./AccountingService.csproj" -r linux-musl-$TARGETARCH -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false FROM base AS final WORKDIR /app diff --git a/src/adservice/Dockerfile b/src/adservice/Dockerfile index a13d2b7736..9903a973ef 100644 --- a/src/adservice/Dockerfile +++ b/src/adservice/Dockerfile @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 -FROM eclipse-temurin:21-jdk as builder +FROM --platform=${BUILDPLATFORM} eclipse-temurin:21-jdk as builder WORKDIR /usr/src/app/ @@ -18,7 +18,7 @@ RUN ./gradlew installDist -PprotoSourceDir=./proto # ----------------------------------------------------------------------------- -FROM eclipse-temurin:21-jre +FROM --platform=${TARGETPLATFORM} eclipse-temurin:21-jre ARG version=2.3.0 WORKDIR /usr/src/app/ diff --git a/src/cartservice/src/Dockerfile b/src/cartservice/src/Dockerfile index e2a12e7e78..f546f8d2e7 100644 --- a/src/cartservice/src/Dockerfile +++ b/src/cartservice/src/Dockerfile @@ -23,14 +23,14 @@ WORKDIR /usr/src/app/ COPY ./src/cartservice/ ./ COPY ./pb/ ./pb/ -RUN dotnet restore ./src/cartservice.csproj -v d -r linux-musl-$TARGETARCH +RUN dotnet restore ./src/cartservice.csproj -r linux-musl-$TARGETARCH -RUN dotnet publish ./src/cartservice.csproj -v d -r linux-musl-$TARGETARCH --no-restore -o /cartservice +RUN dotnet publish ./src/cartservice.csproj -r linux-musl-$TARGETARCH --no-restore -o /cartservice # ----------------------------------------------------------------------------- # https://mcr.microsoft.com/v2/dotnet/runtime-deps/tags/list -FROM mcr.microsoft.com/dotnet/runtime-deps:8.0.6-alpine3.20 +FROM --platform=$TARGETPLATFORM mcr.microsoft.com/dotnet/runtime-deps:8.0.6-alpine3.20 WORKDIR /usr/src/app/ COPY --from=builder /cartservice/ ./ diff --git a/src/frauddetectionservice/Dockerfile b/src/frauddetectionservice/Dockerfile index c7e17158b3..0f8cd31a6b 100644 --- a/src/frauddetectionservice/Dockerfile +++ b/src/frauddetectionservice/Dockerfile @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 -FROM gradle:8-jdk17 AS builder +FROM --platform=${BUILDPLATFORM} gradle:8-jdk17 AS builder WORKDIR /usr/src/app/ @@ -12,7 +12,7 @@ RUN gradle shadowJar # ----------------------------------------------------------------------------- -FROM gcr.io/distroless/java17-debian11 +FROM --platform=${TARGETPLATFORM} gcr.io/distroless/java17-debian11 ARG version=2.4.0 WORKDIR /usr/src/app/ diff --git a/src/shippingservice/Dockerfile b/src/shippingservice/Dockerfile index 60e338cbc8..24390fce2d 100644 --- a/src/shippingservice/Dockerfile +++ b/src/shippingservice/Dockerfile @@ -15,6 +15,8 @@ RUN if [ "${TARGETPLATFORM}" = "${BUILDPLATFORM}" ] ; then \ apt-get update && apt-get install --no-install-recommends -y g++-aarch64-linux-gnu libc6-dev-arm64-cross libprotobuf-dev protobuf-compiler ca-certificates && \ rustup target add aarch64-unknown-linux-gnu && \ rustup toolchain install stable-aarch64-unknown-linux-gnu; \ + elif [ "${TARGETPLATFORM}" = "linux/amd64" ] ; then \ + apt-get update && apt-get install --no-install-recommends -y g++ libc6-dev libprotobuf-dev protobuf-compiler ca-certificates; \ else \ echo "${TARGETPLATFORM} is not supported"; \ exit 1; \ @@ -34,6 +36,8 @@ RUN if [ "${TARGETPLATFORM}" = "${BUILDPLATFORM}" ] ; then \ CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++ \ cargo build -r --features="dockerproto" --target aarch64-unknown-linux-gnu && \ cp /app/target/aarch64-unknown-linux-gnu/release/shippingservice /app/target/release/shippingservice; \ + elif [ "${TARGETPLATFORM}" = "linux/amd64" ] ; then \ + cargo build -r --features="dockerproto"; \ else \ echo "${TARGETPLATFORM} is not supported"; \ exit 1; \ From d18f9bca9d8c977f3ab6e91e0fdb3cb8c3280bfd Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Mon, 1 Jul 2024 21:48:20 -0400 Subject: [PATCH 02/11] multiplatform build --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index 1417371893..d437d8ddc4 100644 --- a/Makefile +++ b/Makefile @@ -85,6 +85,11 @@ build-and-push: # Build and push multiplatform images (linux/amd64, linux/arm64) using buildx. # Requires docker with buildx enabled and a multi-platform capable builder in use. +.PHONY: build-multiplatform +build-multiplatform: + # Because buildx bake does not support --env-file yet, we need to load it into the environment first. + set -a; . .env.override; set +a && docker buildx bake -f docker-compose.yml --set "*.platform=linux/amd64,linux/arm64" + .PHONY: build-multiplatform-and-push build-multiplatform-and-push: # Because buildx bake does not support --env-file yet, we need to load it into the environment first. From 15632e5a63375a30e6288892af84baa57c848595 Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Mon, 1 Jul 2024 22:19:32 -0400 Subject: [PATCH 03/11] multiplatform build --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d437d8ddc4..9e82376d62 100644 --- a/Makefile +++ b/Makefile @@ -88,12 +88,12 @@ build-and-push: .PHONY: build-multiplatform build-multiplatform: # Because buildx bake does not support --env-file yet, we need to load it into the environment first. - set -a; . .env.override; set +a && docker buildx bake -f docker-compose.yml --set "*.platform=linux/amd64,linux/arm64" + set -a; . ./.env.override; set +a && docker buildx bake -f docker-compose.yml --set "*.platform=linux/amd64,linux/arm64" .PHONY: build-multiplatform-and-push build-multiplatform-and-push: # Because buildx bake does not support --env-file yet, we need to load it into the environment first. - set -a; . .env.override; set +a && docker buildx bake -f docker-compose.yml --push --set "*.platform=linux/amd64,linux/arm64" + set -a; . ./.env.override; set +a && docker buildx bake -f docker-compose.yml --push --set "*.platform=linux/amd64,linux/arm64" .PHONY: run-tests run-tests: From 81a81a620fc1615996d0d53a9a708445a353385c Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Mon, 1 Jul 2024 23:16:37 -0400 Subject: [PATCH 04/11] multiplatform build instructions --- CONTRIBUTING.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c21fe5c3d3..a6927f2c61 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -197,6 +197,52 @@ on each other), the owner should try to get people aligned by: the owner should bring it to the OpenTelemetry Community Demo SIG [meeting](README.md#contributing). +## Multi-platform Builds + +Creating multi-platform builds requires the docker buildx to be installed. This +is part of Docker Desktop for macOS, or can be installed using +`apt install docker-buildx` on Ubuntu. + +You will need a multi-platform capable builder with a limiter set of parallelism +to avoid errors while building the images. On an M2 Mac, it is recommended to +limit the parallelism to 8. This can be done by specifying a configuration file +when creating the builder. First create the configuration file: + +```shell +cat < otel-builder.toml +[worker.oci] + max-parallelism = 8 +EOF +``` + +Then create the builder for your environment: + +**MacOS** +```shell +docker buildx create --name otel-builder --bootstrap --use --driver docker-container --buildkitd-config ./otel-builder.toml +``` + +**Ubuntu Linux** +```shell +docker buildx create --name otel-builder --bootstrap --use --driver docker-container --config ./otel-builder.toml +``` + +A builder will be created and set as the active builder. You can check the +builder status with `docker buildx inspect`. To build multi-platform images for +linux/amd64 and linux/arm64, use the following command: + +```shell +make build-multiplatform +``` + +To build and push multi-platform images to a registry, ensure to set +`IMAGE_NAME` to the name of the registry and image repository to use in the +`.env.override` file and run: + +```shell +make build-multiplatform-and-push +``` + ## Making a new release Maintainers can create a new release when desired by following these steps. diff --git a/Makefile b/Makefile index 9e82376d62..66026a7314 100644 --- a/Makefile +++ b/Makefile @@ -88,7 +88,7 @@ build-and-push: .PHONY: build-multiplatform build-multiplatform: # Because buildx bake does not support --env-file yet, we need to load it into the environment first. - set -a; . ./.env.override; set +a && docker buildx bake -f docker-compose.yml --set "*.platform=linux/amd64,linux/arm64" + set -a; . ./.env.override; set +a && docker buildx bake -f docker-compose.yml --load --set "*.platform=linux/amd64,linux/arm64" .PHONY: build-multiplatform-and-push build-multiplatform-and-push: From 613073c111f23a86cd8c52d99b8efb4d064906ed Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Tue, 2 Jul 2024 08:33:31 -0400 Subject: [PATCH 05/11] fix tests --- Makefile | 6 +- docker-compose-tests.yml | 251 ++++++++++++++++++++------------------- 2 files changed, 129 insertions(+), 128 deletions(-) diff --git a/Makefile b/Makefile index 66026a7314..71b55e293c 100644 --- a/Makefile +++ b/Makefile @@ -97,12 +97,12 @@ build-multiplatform-and-push: .PHONY: run-tests run-tests: - $(DOCKER_COMPOSE_CMD) $(DOCKER_COMPOSE_ENV) run frontendTests - $(DOCKER_COMPOSE_CMD) $(DOCKER_COMPOSE_ENV) run traceBasedTests + $(DOCKER_COMPOSE_CMD) $(DOCKER_COMPOSE_ENV) -f docker-compose-tests.yml run frontendTests + $(DOCKER_COMPOSE_CMD) $(DOCKER_COMPOSE_ENV) -f docker-compose-tests.yml run traceBasedTests .PHONY: run-tracetesting run-tracetesting: - $(DOCKER_COMPOSE_CMD) $(DOCKER_COMPOSE_ENV) run traceBasedTests ${SERVICES_TO_TEST} + $(DOCKER_COMPOSE_CMD) $(DOCKER_COMPOSE_ENV) -f docker-compose-tests.yml run traceBasedTests ${SERVICES_TO_TEST} .PHONY: generate-protobuf generate-protobuf: diff --git a/docker-compose-tests.yml b/docker-compose-tests.yml index 37bf3319b7..bc5499f69d 100644 --- a/docker-compose-tests.yml +++ b/docker-compose-tests.yml @@ -2,132 +2,133 @@ # SPDX-License-Identifier: Apache-2.0 include: - - docker-compose.yml # depend on the main docker-compose file + - docker-compose.yml # depend on the main docker-compose file -# ***** -# Tests -# ***** -# Frontend Tests -frontendTests: - image: ${IMAGE_NAME}:${DEMO_VERSION}-frontend-tests - container_name: frontend-tests - build: - context: ./ - dockerfile: ./src/frontend/Dockerfile.cypress - profiles: - - tests - volumes: - - ./src/frontend/cypress/videos:/app/cypress/videos - - ./src/frontend/cypress/screenshots:/app/cypress/screenshots - environment: - - CYPRESS_baseUrl=http://${FRONTEND_ADDR} - - FRONTEND_ADDR - - NODE_ENV=production - depends_on: - - frontend +services: + # ***** + # Tests + # ***** + # Frontend Tests + frontendTests: + image: ${IMAGE_NAME}:${DEMO_VERSION}-frontend-tests + container_name: frontend-tests + build: + context: ./ + dockerfile: ./src/frontend/Dockerfile.cypress + profiles: + - tests + volumes: + - ./src/frontend/cypress/videos:/app/cypress/videos + - ./src/frontend/cypress/screenshots:/app/cypress/screenshots + environment: + - CYPRESS_baseUrl=http://${FRONTEND_ADDR} + - FRONTEND_ADDR + - NODE_ENV=production + depends_on: + - frontend -# Tracebased Tests -traceBasedTests: - image: ${IMAGE_NAME}:${DEMO_VERSION}-traceBasedTests - container_name: traceBasedTests - profiles: - - tests - build: - context: ./ - dockerfile: ./test/tracetesting/Dockerfile - environment: - - AD_SERVICE_ADDR - - CART_SERVICE_ADDR - - CHECKOUT_SERVICE_ADDR - - CURRENCY_SERVICE_ADDR - - EMAIL_SERVICE_ADDR - - FRONTEND_ADDR - - PAYMENT_SERVICE_ADDR - - PRODUCT_CATALOG_SERVICE_ADDR - - RECOMMENDATION_SERVICE_ADDR - - SHIPPING_SERVICE_ADDR - - KAFKA_SERVICE_ADDR - extra_hosts: - - "host.docker.internal:host-gateway" - volumes: - - ./test/tracetesting:/app/test/tracetesting - - ./pb:/app/pb - depends_on: - tracetest-server: - condition: service_healthy - # adding demo services as dependencies - frontend: - condition: service_started - adservice: - condition: service_started - cartservice: - condition: service_started - checkoutservice: - condition: service_started - currencyservice: - condition: service_started - emailservice: - condition: service_started - paymentservice: - condition: service_started - productcatalogservice: - condition: service_started - recommendationservice: - condition: service_started - shippingservice: - condition: service_started - quoteservice: - condition: service_started - accountingservice: - condition: service_started - frauddetectionservice: - condition: service_started - flagd: - condition: service_started + # Tracebased Tests + traceBasedTests: + image: ${IMAGE_NAME}:${DEMO_VERSION}-traceBasedTests + container_name: traceBasedTests + profiles: + - tests + build: + context: ./ + dockerfile: ./test/tracetesting/Dockerfile + environment: + - AD_SERVICE_ADDR + - CART_SERVICE_ADDR + - CHECKOUT_SERVICE_ADDR + - CURRENCY_SERVICE_ADDR + - EMAIL_SERVICE_ADDR + - FRONTEND_ADDR + - PAYMENT_SERVICE_ADDR + - PRODUCT_CATALOG_SERVICE_ADDR + - RECOMMENDATION_SERVICE_ADDR + - SHIPPING_SERVICE_ADDR + - KAFKA_SERVICE_ADDR + extra_hosts: + - "host.docker.internal:host-gateway" + volumes: + - ./test/tracetesting:/app/test/tracetesting + - ./pb:/app/pb + depends_on: + tracetest-server: + condition: service_healthy + # adding demo services as dependencies + frontend: + condition: service_started + adservice: + condition: service_started + cartservice: + condition: service_started + checkoutservice: + condition: service_started + currencyservice: + condition: service_started + emailservice: + condition: service_started + paymentservice: + condition: service_started + productcatalogservice: + condition: service_started + recommendationservice: + condition: service_started + shippingservice: + condition: service_started + quoteservice: + condition: service_started + accountingservice: + condition: service_started + frauddetectionservice: + condition: service_started + flagd: + condition: service_started -tracetest-server: - image: ${TRACETEST_IMAGE} - platform: linux/amd64 - container_name: tracetest-server - profiles: - - tests - - odd # Observabilty-Driven Development (ODD) - volumes: - - type: bind - source: ./test/tracetesting/tracetest-config.yaml - target: /app/tracetest.yaml - - type: bind - source: ./test/tracetesting/tracetest-provision.yaml - target: /app/provision.yaml - command: --provisioning-file /app/provision.yaml - ports: - - 11633:11633 - extra_hosts: - - "host.docker.internal:host-gateway" - depends_on: - tracetest-postgres: - condition: service_healthy - otelcol: - condition: service_started - healthcheck: - test: [ "CMD", "wget", "--spider", "localhost:11633" ] - interval: 1s - timeout: 3s - retries: 60 + tracetest-server: + image: ${TRACETEST_IMAGE} + platform: linux/amd64 + container_name: tracetest-server + profiles: + - tests + - odd # Observabilty-Driven Development (ODD) + volumes: + - type: bind + source: ./test/tracetesting/tracetest-config.yaml + target: /app/tracetest.yaml + - type: bind + source: ./test/tracetesting/tracetest-provision.yaml + target: /app/provision.yaml + command: --provisioning-file /app/provision.yaml + ports: + - 11633:11633 + extra_hosts: + - "host.docker.internal:host-gateway" + depends_on: + tracetest-postgres: + condition: service_healthy + otelcol: + condition: service_started + healthcheck: + test: [ "CMD", "wget", "--spider", "localhost:11633" ] + interval: 1s + timeout: 3s + retries: 60 -tracetest-postgres: - image: ${POSTGRES_IMAGE} - container_name: tracetest-postgres - profiles: - - tests - - odd # Observabilty-Driven Development (ODD) - environment: - POSTGRES_PASSWORD: postgres - POSTGRES_USER: postgres - healthcheck: - test: pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB" - interval: 1s - timeout: 5s - retries: 60 - ports: - - 5432 + tracetest-postgres: + image: ${POSTGRES_IMAGE} + container_name: tracetest-postgres + profiles: + - tests + - odd # Observabilty-Driven Development (ODD) + environment: + POSTGRES_PASSWORD: postgres + POSTGRES_USER: postgres + healthcheck: + test: pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB" + interval: 1s + timeout: 5s + retries: 60 + ports: + - 5432 From c8a0122e3471868378422bf2063f997c0d8d6a3d Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Tue, 2 Jul 2024 08:36:00 -0400 Subject: [PATCH 06/11] multi-platform build support --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ed0d1876e..4335af7f45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ the release. ## Unreleased +* [chore] multi-platform build support for all services + ([#1651](https://github.com/open-telemetry/opentelemetry-demo/pull/1651)) + ## 1.11.0 * [accountingservice] convert from Go service to .NET service, uses From 350a64c2a1518adb7f3339b107492e445d463c10 Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Tue, 2 Jul 2024 10:52:19 -0400 Subject: [PATCH 07/11] fix failed linting --- CONTRIBUTING.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a6927f2c61..2cbb8dc25b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -215,14 +215,16 @@ cat < otel-builder.toml EOF ``` -Then create the builder for your environment: +Then create the builder for your environment. + +If you are using **MacOS** use this command to create the builder: -**MacOS** ```shell docker buildx create --name otel-builder --bootstrap --use --driver docker-container --buildkitd-config ./otel-builder.toml ``` -**Ubuntu Linux** +If you are using **Ubuntu** use this command to create the builder: + ```shell docker buildx create --name otel-builder --bootstrap --use --driver docker-container --config ./otel-builder.toml ``` From 60025447547818e5da56c6f2674f62f68868e934 Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Tue, 2 Jul 2024 12:48:07 -0400 Subject: [PATCH 08/11] stop tests properly --- Makefile | 3 ++- docker-compose-tests.yml | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 71b55e293c..1c961c1c3b 100644 --- a/Makefile +++ b/Makefile @@ -159,7 +159,8 @@ start-odd: .PHONY: stop stop: - $(DOCKER_COMPOSE_CMD) --profile tests --profile odd down --remove-orphans --volumes + $(DOCKER_COMPOSE_CMD) down --remove-orphans --volumes + $(DOCKER_COMPOSE_CMD) -f docker-compose-tests.yml --profile tests down --remove-orphans --volumes @echo "" @echo "OpenTelemetry Demo is stopped." diff --git a/docker-compose-tests.yml b/docker-compose-tests.yml index bc5499f69d..89269df936 100644 --- a/docker-compose-tests.yml +++ b/docker-compose-tests.yml @@ -92,7 +92,6 @@ services: container_name: tracetest-server profiles: - tests - - odd # Observabilty-Driven Development (ODD) volumes: - type: bind source: ./test/tracetesting/tracetest-config.yaml @@ -121,7 +120,6 @@ services: container_name: tracetest-postgres profiles: - tests - - odd # Observabilty-Driven Development (ODD) environment: POSTGRES_PASSWORD: postgres POSTGRES_USER: postgres From 9ba1e300138fca5e68d2664f7846edcdca16463f Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Tue, 2 Jul 2024 14:00:02 -0400 Subject: [PATCH 09/11] fix grammar --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2cbb8dc25b..ebf983c3b0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -199,7 +199,7 @@ on each other), the owner should try to get people aligned by: ## Multi-platform Builds -Creating multi-platform builds requires the docker buildx to be installed. This +Creating multi-platform builds requires docker buildx to be installed. This is part of Docker Desktop for macOS, or can be installed using `apt install docker-buildx` on Ubuntu. From e02d828170e155390cd54bb8f1fc37fd440932d3 Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Sat, 13 Jul 2024 00:31:56 -0400 Subject: [PATCH 10/11] fix multi-platform builds --- src/shippingservice/Dockerfile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/shippingservice/Dockerfile b/src/shippingservice/Dockerfile index 24390fce2d..071cf39c0d 100644 --- a/src/shippingservice/Dockerfile +++ b/src/shippingservice/Dockerfile @@ -16,7 +16,9 @@ RUN if [ "${TARGETPLATFORM}" = "${BUILDPLATFORM}" ] ; then \ rustup target add aarch64-unknown-linux-gnu && \ rustup toolchain install stable-aarch64-unknown-linux-gnu; \ elif [ "${TARGETPLATFORM}" = "linux/amd64" ] ; then \ - apt-get update && apt-get install --no-install-recommends -y g++ libc6-dev libprotobuf-dev protobuf-compiler ca-certificates; \ + apt-get update && apt-get install --no-install-recommends -y g++-x86-64-linux-gnu libc6-amd64-cross libprotobuf-dev protobuf-compiler ca-certificates && \ + rustup target add x86_64-unknown-linux-gnu && \ + rustup toolchain install stable-x86_64-unknown-linux-gnu; \ else \ echo "${TARGETPLATFORM} is not supported"; \ exit 1; \ @@ -37,7 +39,11 @@ RUN if [ "${TARGETPLATFORM}" = "${BUILDPLATFORM}" ] ; then \ cargo build -r --features="dockerproto" --target aarch64-unknown-linux-gnu && \ cp /app/target/aarch64-unknown-linux-gnu/release/shippingservice /app/target/release/shippingservice; \ elif [ "${TARGETPLATFORM}" = "linux/amd64" ] ; then \ - cargo build -r --features="dockerproto"; \ + env CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc \ + CC_x86_64_unknown_linux_gnu=x86_64-linux-gnu-gcc \ + CXX_x86_64_unknown_linux_gnu=x86_64-linux-gnu-g++ \ + cargo build -r --features="dockerproto" --target x86_64-unknown-linux-gnu && \ + cp /app/target/x86_64-unknown-linux-gnu/release/shippingservice /app/target/release/shippingservice; \ else \ echo "${TARGETPLATFORM} is not supported"; \ exit 1; \ From 9e1ab13b2bfd5d09afee1213422682302f41cc37 Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Sat, 13 Jul 2024 00:37:29 -0400 Subject: [PATCH 11/11] align with cartservice steps --- src/accountingservice/Dockerfile | 45 ++++++++++++++------------------ 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/src/accountingservice/Dockerfile b/src/accountingservice/Dockerfile index 617f73304f..c1709feaf8 100644 --- a/src/accountingservice/Dockerfile +++ b/src/accountingservice/Dockerfile @@ -1,32 +1,25 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -FROM --platform=${TARGETPLATFORM} mcr.microsoft.com/dotnet/aspnet:8.0 AS base -USER app -WORKDIR /app - -FROM --platform=${BUILDPLATFORM} mcr.microsoft.com/dotnet/sdk:8.0 AS build +FROM --platform=${BUILDPLATFORM} mcr.microsoft.com/dotnet/sdk:8.0 AS builder ARG TARGETARCH -ARG BUILD_CONFIGURATION=Release -WORKDIR /src -COPY ["/src/accountingservice/", "AccountingService/"] -COPY ["/pb/demo.proto", "AccountingService/proto/"] -RUN dotnet restore "./AccountingService/AccountingService.csproj" -r linux-musl-$TARGETARCH -WORKDIR "/src/AccountingService" - -RUN dotnet build "./AccountingService.csproj" -r linux-musl-$TARGETARCH -c $BUILD_CONFIGURATION -o /app/build - -FROM build AS publish -ARG BUILD_CONFIGURATION=Release -RUN dotnet publish "./AccountingService.csproj" -r linux-musl-$TARGETARCH -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false - -FROM base AS final -WORKDIR /app -COPY --from=publish /app/publish . - -USER root -RUN mkdir -p "/var/log/opentelemetry/dotnet" -RUN chown app "/var/log/opentelemetry/dotnet" -USER app + +WORKDIR /usr/src/app/ + +COPY ./src/accountingservice/ ./ +COPY ./pb/ ./proto/ + +RUN dotnet restore "./AccountingService.csproj" -r linux-musl-$TARGETARCH + +RUN dotnet publish "./AccountingService.csproj" -r linux-musl-$TARGETARCH --no-restore -o /accountingservice + +# ----------------------------------------------------------------------------- + +FROM --platform=${TARGETPLATFORM} mcr.microsoft.com/dotnet/aspnet:8.0 + +WORKDIR /usr/src/app/ +COPY --from=builder /accountingservice/ ./ + +ENV DOTNET_HOSTBUILDER__RELOADCONFIGONCHANGE=false ENTRYPOINT ["./instrument.sh", "dotnet", "AccountingService.dll"]