Skip to content

Commit 8a86840

Browse files
[chore] add multi platform build support (open-telemetry#1785)
* multiplatform build * multiplatform build instructions * fix tests * multi-platform build support * fix failed linting * stop tests properly * fix grammar * fix multi-platform builds * align with cartservice steps * remove buildx warnings * add create-multiplatform-builder target * support Linux to create multiplaform builder * update multiplatform build instructions * add multiplatform build support * add multiplatform build support * add multiplatform build support * create and remove multi-platform builder * clarify multi-platform build instructions * clarify multi-platform build instructions * use shell directly for env var subst * Update CONTRIBUTING.md --------- Co-authored-by: Juliano Costa <[email protected]>
1 parent 5c748f7 commit 8a86840

File tree

16 files changed

+137
-78
lines changed

16 files changed

+137
-78
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ the release.
1919
to 1.9.0 ([#1780](https://github.com/open-telemetry/opentelemetry-demo/pull/1780))
2020
* [chore] update memory limits for flagd, flagdui, and loadgenerator
2121
([#1786](https://github.com/open-telemetry/opentelemetry-demo/pull/1786))
22+
* [chore] Add multi-platform build support
23+
([#1785](https://github.com/open-telemetry/opentelemetry-demo/pull/1785))
2224

2325
## 1.12.0
2426

CONTRIBUTING.md

+43-3
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,10 @@ cd .\src\adservice\
8080

8181
### Run Docker Compose
8282

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

8685
```shell
87-
docker compose up -d
86+
make start
8887
```
8988

9089
### Verify the Webstore & the Telemetry
@@ -197,6 +196,47 @@ on each other), the owner should try to get people aligned by:
197196
the owner should bring it to the OpenTelemetry Community Demo SIG
198197
[meeting](README.md#contributing).
199198

199+
## Multi-platform Builds
200+
201+
Creating multi-platform builds requires docker buildx to be installed. This
202+
is part of Docker Desktop for macOS, or can be installed using
203+
`apt install docker-buildx` on Ubuntu.
204+
205+
To build and load the multi-platform images locally you will need to configure
206+
docker to use `containerd`. This can be done in Docker Desktop settings on MacOS
207+
or Windows. Please follow
208+
[these instructions](https://docs.docker.com/engine/storage/containerd/#enable-containerd-image-store-on-docker-engine)
209+
to configure Docker Engine on Linux/Ubuntu.
210+
211+
You will need a multi-platform capable builder with a limiter set on parallelism
212+
to avoid errors while building the images. It is recommended to limit the
213+
parallelism to 4. This can be done by specifying a configuration file when
214+
creating the builder. The `buildkitd.toml` file in this repository can be used
215+
as the builder configuration file.
216+
217+
To create a multi-platform builder with a parallelism limit of 4, use the
218+
following command:
219+
220+
```shell
221+
make create-multiplatform-builder
222+
```
223+
224+
A builder will be created and set as the active builder. You can check the
225+
builder status with `docker buildx inspect`. To build multi-platform images for
226+
linux/amd64 and linux/arm64, use the following command:
227+
228+
```shell
229+
make build-multiplatform
230+
```
231+
232+
To build and push multi-platform images to a registry, ensure to set
233+
`IMAGE_NAME` to the name of the registry and image repository to use in the
234+
`.env.override` file and run:
235+
236+
```shell
237+
make build-multiplatform-and-push
238+
```
239+
200240
## Making a new release
201241

202242
Maintainers can create a new release when desired by following these steps.

Makefile

+26-18
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,32 @@ install-tools: $(MISSPELL)
7979
build:
8080
$(DOCKER_COMPOSE_CMD) build
8181

82-
.PHONY: build-and-push-dockerhub
83-
build-and-push-dockerhub:
84-
$(DOCKER_COMPOSE_CMD) --env-file .dockerhub.env -f docker-compose.yml build
85-
$(DOCKER_COMPOSE_CMD) --env-file .dockerhub.env -f docker-compose.yml push
86-
87-
.PHONY: build-and-push-ghcr
88-
build-and-push-ghcr:
89-
$(DOCKER_COMPOSE_CMD) --env-file .ghcr.env -f docker-compose.yml build
90-
$(DOCKER_COMPOSE_CMD) --env-file .ghcr.env -f docker-compose.yml push
91-
92-
.PHONY: build-env-file
93-
build-env-file:
94-
cp .env .dockerhub.env
95-
sed -i '/IMAGE_VERSION=.*/c\IMAGE_VERSION=${RELEASE_VERSION}' .dockerhub.env
96-
sed -i '/IMAGE_NAME=.*/c\IMAGE_NAME=${DOCKERHUB_REPO}' .dockerhub.env
97-
cp .env .ghcr.env
98-
sed -i '/IMAGE_VERSION=.*/c\IMAGE_VERSION=${RELEASE_VERSION}' .ghcr.env
99-
sed -i '/IMAGE_NAME=.*/c\IMAGE_NAME=${GHCR_REPO}' .ghcr.env
82+
.PHONY: build-and-push
83+
build-and-push:
84+
$(DOCKER_COMPOSE_CMD) $(DOCKER_COMPOSE_ENV) build --push
85+
86+
# Create multiplatform builder for buildx
87+
.PHONY: create-multiplatform-builder
88+
create-multiplatform-builder:
89+
docker buildx create --name otel-demo-builder --bootstrap --use --driver docker-container --config ./buildkitd.toml
90+
91+
# Remove multiplatform builder for buildx
92+
.PHONY: remove-multiplatform-builder
93+
remove-multiplatform-builder:
94+
docker buildx rm otel-demo-builder
95+
96+
# Build and push multiplatform images (linux/amd64, linux/arm64) using buildx.
97+
# Requires docker with buildx enabled and a multi-platform capable builder in use.
98+
# Docker needs to be configured to use containerd storage for images to be loaded into the local registry.
99+
.PHONY: build-multiplatform
100+
build-multiplatform:
101+
# Because buildx bake does not support --env-file yet, we need to load it into the environment first.
102+
set -a; . ./.env.override; set +a && docker buildx bake -f docker-compose.yml --load --set "*.platform=linux/amd64,linux/arm64"
103+
104+
.PHONY: build-multiplatform-and-push
105+
build-multiplatform-and-push:
106+
# Because buildx bake does not support --env-file yet, we need to load it into the environment first.
107+
set -a; . ./.env.override; set +a && docker buildx bake -f docker-compose.yml --push --set "*.platform=linux/amd64,linux/arm64"
100108

101109
.PHONY: run-tests
102110
run-tests:

buildkitd.toml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
[worker.oci]
5+
max-parallelism = 4

src/accountingservice/Dockerfile

+20-27
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
11
# Copyright The OpenTelemetry Authors
22
# SPDX-License-Identifier: Apache-2.0
33

4-
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
5-
USER app
6-
WORKDIR /app
7-
8-
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
9-
ARG BUILD_CONFIGURATION=Release
10-
WORKDIR /src
11-
COPY ["/src/accountingservice/", "AccountingService/"]
12-
COPY ["/pb/demo.proto", "AccountingService/proto/"]
13-
RUN dotnet restore "./AccountingService/AccountingService.csproj"
14-
WORKDIR "/src/AccountingService"
15-
16-
RUN dotnet build "./AccountingService.csproj" -c $BUILD_CONFIGURATION -o /app/build
17-
18-
FROM build AS publish
19-
ARG BUILD_CONFIGURATION=Release
20-
RUN dotnet publish "./AccountingService.csproj" --use-current-runtime -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
21-
22-
FROM base AS final
23-
WORKDIR /app
24-
COPY --from=publish /app/publish .
25-
26-
USER root
27-
RUN mkdir -p "/var/log/opentelemetry/dotnet"
28-
RUN chown app "/var/log/opentelemetry/dotnet"
29-
RUN chown app "/app/instrument.sh"
30-
USER app
4+
FROM --platform=${BUILDPLATFORM} mcr.microsoft.com/dotnet/sdk:8.0 AS builder
5+
ARG TARGETARCH
6+
7+
WORKDIR /usr/src/app/
8+
9+
COPY ./src/accountingservice/ ./
10+
COPY ./pb/ ./proto/
11+
12+
RUN dotnet restore "./AccountingService.csproj" -r linux-musl-$TARGETARCH
13+
14+
RUN dotnet publish "./AccountingService.csproj" -r linux-musl-$TARGETARCH --no-restore -o /accountingservice
15+
16+
# -----------------------------------------------------------------------------
17+
18+
FROM mcr.microsoft.com/dotnet/aspnet:8.0
19+
20+
WORKDIR /usr/src/app/
21+
COPY --from=builder /accountingservice/ ./
22+
23+
ENV DOTNET_HOSTBUILDER__RELOADCONFIGONCHANGE=false
3124

3225
ENTRYPOINT ["./instrument.sh", "dotnet", "AccountingService.dll"]

src/adservice/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44

5-
FROM eclipse-temurin:21-jdk as builder
5+
FROM --platform=${BUILDPLATFORM} eclipse-temurin:21-jdk AS builder
66

77
WORKDIR /usr/src/app/
88

src/cartservice/src/Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@
1515
# limitations under the License.
1616

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

2121
WORKDIR /usr/src/app/
2222

2323
COPY ./src/cartservice/ ./
2424
COPY ./pb/ ./pb/
2525

26-
RUN dotnet restore ./src/cartservice.csproj -v d -r linux-musl-$TARGETARCH
26+
RUN dotnet restore ./src/cartservice.csproj -r linux-musl-$TARGETARCH
2727

28-
RUN dotnet publish ./src/cartservice.csproj -v d -r linux-musl-$TARGETARCH --no-restore -o /cartservice
28+
RUN dotnet publish ./src/cartservice.csproj -r linux-musl-$TARGETARCH --no-restore -o /cartservice
2929

3030
# -----------------------------------------------------------------------------
3131

3232
# https://mcr.microsoft.com/v2/dotnet/runtime-deps/tags/list
33-
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0.10-alpine3.20
33+
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-alpine3.20
3434

3535
WORKDIR /usr/src/app/
3636
COPY --from=builder /cartservice/ ./

src/currencyservice/Dockerfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
FROM alpine:3.18 as builder
17+
FROM alpine:3.18 AS builder
1818

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

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

4141

42-
FROM alpine:3.18 as release
42+
FROM alpine:3.18 AS release
4343

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

4747
EXPOSE ${CURRENCY_SERVICE_PORT}
48-
ENTRYPOINT ./usr/local/bin/currencyservice ${CURRENCY_SERVICE_PORT}
48+
ENTRYPOINT ["sh", "-c", "./usr/local/bin/currencyservice ${CURRENCY_SERVICE_PORT}"]

src/emailservice/Dockerfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44

5-
FROM ruby:3.2.2-slim as base
5+
FROM ruby:3.2.2-slim AS base
66

7-
FROM base as builder
7+
FROM base AS builder
88

99
WORKDIR /tmp
1010

1111
COPY ./src/emailservice/Gemfile ./src/emailservice/Gemfile.lock ./
1212

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

1717
WORKDIR /email_server
1818

src/frauddetectionservice/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44

5-
FROM gradle:8-jdk17 AS builder
5+
FROM --platform=${BUILDPLATFORM} gradle:8-jdk17 AS builder
66

77
WORKDIR /usr/src/app/
88

src/frontend/Dockerfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
4040

4141
USER nextjs
4242

43-
ENV PORT 8080
43+
ENV PORT=8080
4444
EXPOSE ${PORT}
4545

46-
ENTRYPOINT npm start
46+
ENTRYPOINT ["npm", "start"]
47+

src/loadgenerator/Dockerfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44

5-
FROM python:3.12-slim-bookworm as base
5+
FROM python:3.12-slim-bookworm AS base
66

7-
FROM base as builder
7+
FROM base AS builder
88
RUN apt-get -qq update \
99
&& apt-get install -y --no-install-recommends g++ \
1010
&& rm -rf /var/lib/apt/lists/*
@@ -20,4 +20,4 @@ COPY ./src/loadgenerator/people.json .
2020
ENV LOCUST_PLAYWRIGHT=1
2121
ENV PLAYWRIGHT_BROWSERS_PATH=/opt/pw-browsers
2222
RUN playwright install --with-deps chromium
23-
ENTRYPOINT locust --skip-log-setup
23+
ENTRYPOINT ["locust", "--skip-log-setup"]

src/paymentservice/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ FROM node:21-alpine
1616

1717
USER node
1818
WORKDIR /usr/src/app/
19-
ENV NODE_ENV production
19+
ENV NODE_ENV=production
2020

2121
COPY --chown=node:node --from=build /usr/src/app/node_modules/ ./node_modules/
2222
COPY ./src/paymentservice/ ./

src/quoteservice/Dockerfile

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44

5-
FROM php:8.3-cli as base
5+
FROM php:8.3-cli AS base
66

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

1515
WORKDIR /var/www
16-
CMD php public/index.php
16+
CMD ["php", "public/index.php"]
1717
USER www-data
1818
EXPOSE ${QUOTE_SERVICE_PORT}
1919

@@ -30,7 +30,6 @@ RUN composer install \
3030
--no-dev \
3131
--prefer-dist
3232

33-
FROM base as final
33+
FROM base AS final
3434
COPY --from=vendor /tmp/vendor/ ./vendor/
3535
COPY ./src/quoteservice/ /var/www
36-

src/recommendationservice/Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44

5-
FROM python:3.12-slim-bookworm as base
5+
FROM python:3.12-slim-bookworm AS base
66

77
#
88
# Fetch requirements
99
#
10-
FROM base as builder
10+
FROM base AS builder
1111
RUN apt-get -qq update \
1212
&& apt-get install -y --no-install-recommends g++ \
1313
&& rm -rf /var/lib/apt/lists/*
@@ -21,7 +21,7 @@ RUN pip install --prefix="/reqs" -r requirements.txt
2121
#
2222
# Build gRPC files
2323
#
24-
FROM base as grpc-builder
24+
FROM base AS grpc-builder
2525
WORKDIR /usr/src/app/
2626
COPY ./pb/ ./proto/
2727

@@ -31,7 +31,7 @@ RUN python -m grpc_tools.protoc -I=./proto/ --python_out=./ --grpc_python_out=./
3131
#
3232
# Runtime
3333
#
34-
FROM base as runtime
34+
FROM base AS runtime
3535
WORKDIR /usr/src/app/
3636
COPY --from=builder /reqs /usr/local
3737
COPY --from=grpc-builder /usr/src/app/ .

0 commit comments

Comments
 (0)