Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Nov 24, 2024
2 parents 8332707 + 8a86840 commit 4e0663a
Show file tree
Hide file tree
Showing 16 changed files with 137 additions and 78 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ the release.
to 1.9.0 ([#1780](https://github.com/open-telemetry/opentelemetry-demo/pull/1780))
* [chore] update memory limits for flagd, flagdui, and loadgenerator
([#1786](https://github.com/open-telemetry/opentelemetry-demo/pull/1786))
* [chore] Add multi-platform build support
([#1785](https://github.com/open-telemetry/opentelemetry-demo/pull/1785))

## 1.12.0

Expand Down
46 changes: 43 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ cd .\src\adservice\

### Run Docker Compose

- Start the demo (It can take ~20min the first time the command is executed as
all the images will be build):
- Start the demo:

```shell
docker compose up -d
make start
```

### Verify the Webstore & the Telemetry
Expand Down Expand Up @@ -197,6 +196,47 @@ 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 docker buildx to be installed. This
is part of Docker Desktop for macOS, or can be installed using
`apt install docker-buildx` on Ubuntu.

To build and load the multi-platform images locally you will need to configure
docker to use `containerd`. This can be done in Docker Desktop settings on MacOS
or Windows. Please follow
[these instructions](https://docs.docker.com/engine/storage/containerd/#enable-containerd-image-store-on-docker-engine)
to configure Docker Engine on Linux/Ubuntu.

You will need a multi-platform capable builder with a limiter set on parallelism
to avoid errors while building the images. It is recommended to limit the
parallelism to 4. This can be done by specifying a configuration file when
creating the builder. The `buildkitd.toml` file in this repository can be used
as the builder configuration file.

To create a multi-platform builder with a parallelism limit of 4, use the
following command:

```shell
make create-multiplatform-builder
```

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.
Expand Down
44 changes: 26 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,32 @@ 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

# Create multiplatform builder for buildx
.PHONY: create-multiplatform-builder
create-multiplatform-builder:
docker buildx create --name otel-demo-builder --bootstrap --use --driver docker-container --config ./buildkitd.toml

# Remove multiplatform builder for buildx
.PHONY: remove-multiplatform-builder
remove-multiplatform-builder:
docker buildx rm otel-demo-builder

# Build and push multiplatform images (linux/amd64, linux/arm64) using buildx.
# Requires docker with buildx enabled and a multi-platform capable builder in use.
# Docker needs to be configured to use containerd storage for images to be loaded into the local registry.
.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 --load --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"

.PHONY: run-tests
run-tests:
Expand Down
5 changes: 5 additions & 0 deletions buildkitd.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

[worker.oci]
max-parallelism = 4
47 changes: 20 additions & 27 deletions src/accountingservice/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["/src/accountingservice/", "AccountingService/"]
COPY ["/pb/demo.proto", "AccountingService/proto/"]
RUN dotnet restore "./AccountingService/AccountingService.csproj"
WORKDIR "/src/AccountingService"

RUN dotnet build "./AccountingService.csproj" -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

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"
RUN chown app "/app/instrument.sh"
USER app
FROM --platform=${BUILDPLATFORM} mcr.microsoft.com/dotnet/sdk:8.0 AS builder
ARG TARGETARCH

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 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"]
2 changes: 1 addition & 1 deletion src/adservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down
8 changes: 4 additions & 4 deletions src/cartservice/src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@
# limitations under the License.

# https://mcr.microsoft.com/v2/dotnet/sdk/tags/list
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0.403 AS builder
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS builder
ARG TARGETARCH

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.10-alpine3.20
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-alpine3.20

WORKDIR /usr/src/app/
COPY --from=builder /cartservice/ ./
Expand Down
6 changes: 3 additions & 3 deletions src/currencyservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM alpine:3.18 as builder
FROM alpine:3.18 AS builder

RUN apk update && apk add git cmake make g++ grpc-dev protobuf-dev linux-headers

Expand All @@ -39,10 +39,10 @@ RUN cd /currencyservice \
&& make -j$(nproc || sysctl -n hw.ncpu || echo 1) install


FROM alpine:3.18 as release
FROM alpine:3.18 AS release

RUN apk update && apk add grpc-dev protobuf-dev
COPY --from=builder /usr/local /usr/local

EXPOSE ${CURRENCY_SERVICE_PORT}
ENTRYPOINT ./usr/local/bin/currencyservice ${CURRENCY_SERVICE_PORT}
ENTRYPOINT ["sh", "-c", "./usr/local/bin/currencyservice ${CURRENCY_SERVICE_PORT}"]
6 changes: 3 additions & 3 deletions src/emailservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
# SPDX-License-Identifier: Apache-2.0


FROM ruby:3.2.2-slim as base
FROM ruby:3.2.2-slim AS base

FROM base as builder
FROM base AS builder

WORKDIR /tmp

COPY ./src/emailservice/Gemfile ./src/emailservice/Gemfile.lock ./

#RUN apk update && apk add make gcc musl-dev gcompat && bundle install
RUN apt-get update && apt-get install build-essential -y && bundle install
FROM base as release
FROM base AS release

WORKDIR /email_server

Expand Down
2 changes: 1 addition & 1 deletion src/frauddetectionservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down
5 changes: 3 additions & 2 deletions src/frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

ENV PORT 8080
ENV PORT=8080
EXPOSE ${PORT}

ENTRYPOINT npm start
ENTRYPOINT ["npm", "start"]

6 changes: 3 additions & 3 deletions src/loadgenerator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# SPDX-License-Identifier: Apache-2.0


FROM python:3.12-slim-bookworm as base
FROM python:3.12-slim-bookworm AS base

FROM base as builder
FROM base AS builder
RUN apt-get -qq update \
&& apt-get install -y --no-install-recommends g++ \
&& rm -rf /var/lib/apt/lists/*
Expand All @@ -20,4 +20,4 @@ COPY ./src/loadgenerator/people.json .
ENV LOCUST_PLAYWRIGHT=1
ENV PLAYWRIGHT_BROWSERS_PATH=/opt/pw-browsers
RUN playwright install --with-deps chromium
ENTRYPOINT locust --skip-log-setup
ENTRYPOINT ["locust", "--skip-log-setup"]
2 changes: 1 addition & 1 deletion src/paymentservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ FROM node:21-alpine

USER node
WORKDIR /usr/src/app/
ENV NODE_ENV production
ENV NODE_ENV=production

COPY --chown=node:node --from=build /usr/src/app/node_modules/ ./node_modules/
COPY ./src/paymentservice/ ./
Expand Down
7 changes: 3 additions & 4 deletions src/quoteservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0


FROM php:8.3-cli as base
FROM php:8.3-cli AS base

ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions \
Expand All @@ -13,7 +13,7 @@ RUN chmod +x /usr/local/bin/install-php-extensions \
opentelemetry

WORKDIR /var/www
CMD php public/index.php
CMD ["php", "public/index.php"]
USER www-data
EXPOSE ${QUOTE_SERVICE_PORT}

Expand All @@ -30,7 +30,6 @@ RUN composer install \
--no-dev \
--prefer-dist

FROM base as final
FROM base AS final
COPY --from=vendor /tmp/vendor/ ./vendor/
COPY ./src/quoteservice/ /var/www

8 changes: 4 additions & 4 deletions src/recommendationservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# SPDX-License-Identifier: Apache-2.0


FROM python:3.12-slim-bookworm as base
FROM python:3.12-slim-bookworm AS base

#
# Fetch requirements
#
FROM base as builder
FROM base AS builder
RUN apt-get -qq update \
&& apt-get install -y --no-install-recommends g++ \
&& rm -rf /var/lib/apt/lists/*
Expand All @@ -21,7 +21,7 @@ RUN pip install --prefix="/reqs" -r requirements.txt
#
# Build gRPC files
#
FROM base as grpc-builder
FROM base AS grpc-builder
WORKDIR /usr/src/app/
COPY ./pb/ ./proto/

Expand All @@ -31,7 +31,7 @@ RUN python -m grpc_tools.protoc -I=./proto/ --python_out=./ --grpc_python_out=./
#
# Runtime
#
FROM base as runtime
FROM base AS runtime
WORKDIR /usr/src/app/
COPY --from=builder /reqs /usr/local
COPY --from=grpc-builder /usr/src/app/ .
Expand Down
Loading

0 comments on commit 4e0663a

Please sign in to comment.