Skip to content

Commit 5c128ec

Browse files
Build/push arm64 image and multiarch manifest (open-telemetry#866)
1 parent 2ffda5b commit 5c128ec

File tree

5 files changed

+112
-47
lines changed

5 files changed

+112
-47
lines changed

.circleci/config.yml

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ executors:
88
docker:
99
- image: cimg/go:1.17.2
1010

11+
docker-amd64:
12+
machine:
13+
image: ubuntu-2004:202101-01
14+
docker_layer_caching: true
15+
16+
docker-arm64:
17+
machine:
18+
image: ubuntu-2004:202101-01
19+
docker_layer_caching: true
20+
resource_class: arm.medium
21+
1122
commands:
1223
attach_to_workspace:
1324
steps:
@@ -89,7 +100,16 @@ workflows:
89100
- docker-otelcol:
90101
requires:
91102
- cross-compile
92-
- windows-docker-otelcol:
103+
name: docker-otelcol-amd64
104+
os: docker-amd64
105+
arch: amd64
106+
- docker-otelcol:
107+
requires:
108+
- cross-compile
109+
name: docker-otelcol-arm64
110+
os: docker-arm64
111+
arch: arm64
112+
- docker-otelcol-windows:
93113
requires:
94114
- cross-compile
95115
- test:
@@ -209,19 +229,25 @@ jobs:
209229
# command: bash <(curl -s https://codecov.io/bash)
210230

211231
docker-otelcol:
212-
docker:
213-
- image: cimg/go:1.17
232+
parameters:
233+
os:
234+
type: executor
235+
arch:
236+
type: string
237+
executor: << parameters.os >>
238+
environment:
239+
ARCH: << parameters.arch >>
214240
steps:
215241
- attach_to_workspace
216-
- setup_remote_docker:
217-
version: 19.03.13
218242
- run:
219243
name: Build docker image
220-
command: make docker-otelcol SKIP_COMPILE=true
244+
command: make docker-otelcol SKIP_COMPILE=true ARCH=${ARCH}
221245
- run:
222246
name: Run docker image
223247
command: |
224-
docker run -d -e SPLUNK_ACCESS_TOKEN=12345 -e SPLUNK_REALM=fake-realm --name otelcol otelcol:latest
248+
# ensure that the arch in the image manifest is correct
249+
[ "$( docker inspect --format='{{.Architecture}}' otelcol:${ARCH} )" = "$ARCH" ] || exit 1
250+
docker run -d -e SPLUNK_ACCESS_TOKEN=12345 -e SPLUNK_REALM=fake-realm --name otelcol otelcol:${ARCH}
225251
sleep 10
226252
if [ -z "$( docker ps --filter=status=running --filter=name=otelcol -q )" ]; then
227253
docker logs otelcol
@@ -231,11 +257,11 @@ jobs:
231257
name: Save docker image
232258
command: |
233259
mkdir -p dist
234-
docker save -o dist/otelcol.tar otelcol:latest
260+
docker save -o dist/otelcol-${ARCH}.tar otelcol:${ARCH}
235261
- store_artifacts:
236-
path: dist/otelcol.tar
262+
path: dist/otelcol-*.tar
237263

238-
windows-docker-otelcol:
264+
docker-otelcol-windows:
239265
executor:
240266
name: win/default
241267
shell: powershell.exe

.gitlab-ci.yml

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,20 @@ build-linux-image:
210210
stage: package
211211
dependencies:
212212
- compile
213+
parallel:
214+
matrix:
215+
- ARCH: [amd64, arm64]
213216
retry: 2
214217
script:
215-
- make docker-otelcol SKIP_COMPILE=true
218+
- make docker-otelcol ARCH=${ARCH} SKIP_COMPILE=true
219+
- arch=$( docker inspect --format='{{.Architecture}}' otelcol:${ARCH} )
220+
- if [[ "$arch" != "$ARCH" ]]; then exit 1; fi
216221
after_script:
217222
- mkdir -p dist
218-
- docker save -o dist/otelcol.tar otelcol:latest
223+
- docker save -o dist/otelcol-${ARCH}.tar otelcol:${ARCH}
219224
artifacts:
220225
paths:
221-
- dist/otelcol.tar
226+
- dist/otelcol-*.tar
222227

223228
.build-deb-rpm:
224229
only:
@@ -287,31 +292,55 @@ push-linux-image:
287292
- build-linux-image
288293
retry: 2
289294
before_script:
290-
- docker load -i dist/otelcol.tar
295+
- docker load -i dist/otelcol-amd64.tar
296+
- docker load -i dist/otelcol-arm64.tar
291297
script:
292298
- docker login -u $CIRCLECI_QUAY_USERNAME -p $CIRCLECI_QUAY_PASSWORD quay.io
293299
- |
300+
# Set env vars
294301
set -e
295302
if [[ -n "${CI_COMMIT_TAG:-}" ]]; then
296303
IMAGE_NAME="quay.io/signalfx/splunk-otel-collector"
297-
IMAGE_TAG=${CI_COMMIT_TAG#v}
304+
MANIFEST_TAG=${CI_COMMIT_TAG#v}
298305
else
299306
IMAGE_NAME="quay.io/signalfx/splunk-otel-collector-dev"
300-
IMAGE_TAG=$CI_COMMIT_SHA
307+
MANIFEST_TAG=$CI_COMMIT_SHA
301308
fi
302-
echo "Tagging and pushing ${IMAGE_NAME}:${IMAGE_TAG}"
303-
docker tag otelcol:latest ${IMAGE_NAME}:${IMAGE_TAG}
304-
docker push ${IMAGE_NAME}:${IMAGE_TAG}
305-
if [[ "$IMAGE_TAG" = "$CI_COMMIT_SHA" ]] || [[ "$IMAGE_TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
306-
# only push latest tag for main and stable releases
307-
echo "Tagging and pushing ${IMAGE_NAME}:latest"
308-
docker tag otelcol:latest ${IMAGE_NAME}:latest
309-
docker push ${IMAGE_NAME}:latest
309+
- |
310+
# Tag and push images
311+
set -e
312+
for arch in "amd64" "arm64"; do
313+
ARCH_TAG="${MANIFEST_TAG}-${arch}"
314+
echo "Tagging and pushing ${IMAGE_NAME}:${ARCH_TAG}"
315+
docker tag otelcol:${arch} ${IMAGE_NAME}:${ARCH_TAG}
316+
docker push ${IMAGE_NAME}:${ARCH_TAG}
317+
if [[ "${CI_COMMIT_BRANCH:-}" = "main" ]] || [[ "${CI_COMMIT_TAG:-}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
318+
# only push latest tag for main and stable releases
319+
LATEST_TAG="latest-${arch}"
320+
echo "Tagging and pushing ${IMAGE_NAME}:${LATEST_TAG}"
321+
docker tag ${IMAGE_NAME}:${ARCH_TAG} ${IMAGE_NAME}:${LATEST_TAG}
322+
docker push ${IMAGE_NAME}:${LATEST_TAG}
323+
fi
324+
done
325+
- |
326+
# Create and push image manifests
327+
set -e
328+
echo "Creating and pushing ${IMAGE_NAME}:${MANIFEST_TAG} manifest"
329+
docker manifest create ${IMAGE_NAME}:${MANIFEST_TAG} --amend ${IMAGE_NAME}:${MANIFEST_TAG}-amd64 --amend ${IMAGE_NAME}:${MANIFEST_TAG}-arm64
330+
docker manifest push ${IMAGE_NAME}:${MANIFEST_TAG}
331+
if [[ "${CI_COMMIT_BRANCH:-}" = "main" ]] || [[ "${CI_COMMIT_TAG:-}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
332+
# only push latest manifest tag for main and stable releases
333+
echo "Creating and pushing ${IMAGE_NAME}:latest manifest"
334+
docker manifest create ${IMAGE_NAME}:latest --amend ${IMAGE_NAME}:latest-amd64 --amend ${IMAGE_NAME}:latest-arm64
335+
docker manifest push ${IMAGE_NAME}:latest
310336
fi
311-
- docker inspect --format='{{.RepoDigests}}' ${IMAGE_NAME}:${IMAGE_TAG} | tee dist/linux_digest.txt
337+
- docker pull ${IMAGE_NAME}:${MANIFEST_TAG}
338+
- docker inspect --format='{{.RepoDigests}}' ${IMAGE_NAME}:${MANIFEST_TAG} | tee dist/linux_digest.txt
339+
- docker manifest inspect ${IMAGE_NAME}:${MANIFEST_TAG} | tee dist/manifest_digest.txt
312340
artifacts:
313341
paths:
314342
- dist/linux_digest.txt
343+
- dist/manifest_digest.txt
315344

316345
build-push-windows-image:
317346
only:
@@ -345,7 +374,7 @@ build-push-windows-image:
345374
docker build -t ${IMAGE_NAME}:${IMAGE_TAG} --build-arg SMART_AGENT_RELEASE=${SMART_AGENT_RELEASE} -f .\cmd\otelcol\Dockerfile.windows .\cmd\otelcol\
346375
echo "Pushing ${IMAGE_NAME}:${IMAGE_TAG}"
347376
docker push ${IMAGE_NAME}:${IMAGE_TAG}
348-
if ($IMAGE_TAG -eq $env:CI_COMMIT_SHA -or $IMAGE_TAG -match '^\d+\.\d+\.\d+$') {
377+
if ($env:CI_COMMIT_BRANCH -eq "main" -or $env:CI_COMMIT_TAG -match '^v\d+\.\d+\.\d+$') {
349378
# only push latest tag for main and stable releases
350379
echo "Tagging and pushing ${IMAGE_NAME}:latest"
351380
docker tag ${IMAGE_NAME}:${IMAGE_TAG} ${IMAGE_NAME}:latest
@@ -506,14 +535,16 @@ cve-scan:
506535
- schedules
507536
before_script:
508537
- apt-get update
509-
- apt-get install -y docker.io
510-
- mkdir -p ~/.docker/cli-plugins
511-
- curl https://github.com/docker/scan-cli-plugin/releases/latest/download/docker-scan_linux_amd64 -L -s -S -o ~/.docker/cli-plugins/docker-scan
512-
- chmod +x ~/.docker/cli-plugins/docker-scan
538+
- apt-get install -y ca-certificates curl gnupg lsb-release
539+
- curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
540+
- echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
541+
- apt-get update
542+
- apt-get install -y docker-ce-cli docker-scan-plugin
513543
script:
514544
- |
515-
if [ -f dist/otelcol.tar ]; then
516-
docker load -i dist/otelcol.tar
545+
if [ -f dist/otelcol-amd64.tar ]; then
546+
docker load -i dist/otelcol-amd64.tar
547+
docker tag otelcol:amd64 otelcol:latest
517548
else
518549
make docker-otelcol
519550
fi

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
## Unreleased
44

55
- Add Chocolately package support. (#724)
6+
- Initial release of multi-arch manifest for amd64 and arm64 linux docker images (#866)
7+
- **Note:** The Smart Agent and Collectd bundle is only included with the amd64 image
68

79
## v0.37.1
810

Makefile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ BUILD_INFO=-ldflags "${BUILD_X1}"
4444

4545
SMART_AGENT_RELEASE=$(shell cat internal/buildscripts/packaging/smart-agent-release.txt)
4646
SKIP_COMPILE=false
47+
ARCH=amd64
4748

4849
# For integration testing against local changes you can run
4950
# SPLUNK_OTEL_COLLECTOR_IMAGE='otelcol:latest' make -e docker-otelcol integration-test
@@ -204,12 +205,13 @@ delete-tag:
204205
.PHONY: docker-otelcol
205206
docker-otelcol:
206207
ifneq ($(SKIP_COMPILE), true)
207-
$(MAKE) binaries-linux_amd64
208+
$(MAKE) binaries-linux_$(ARCH)
208209
endif
209-
cp ./bin/otelcol_linux_amd64 ./cmd/otelcol/otelcol
210-
cp ./bin/translatesfx_linux_amd64 ./cmd/otelcol/translatesfx
211-
cp ./bin/migratecheckpoint_linux_amd64 ./cmd/otelcol/migratecheckpoint
212-
docker build -t otelcol --build-arg SMART_AGENT_RELEASE=$(SMART_AGENT_RELEASE) ./cmd/otelcol/
210+
cp ./bin/otelcol_linux_$(ARCH) ./cmd/otelcol/otelcol
211+
cp ./bin/translatesfx_linux_$(ARCH) ./cmd/otelcol/translatesfx
212+
cp ./bin/migratecheckpoint_linux_$(ARCH) ./cmd/otelcol/migratecheckpoint
213+
docker buildx build --platform linux/$(ARCH) -o type=image,name=otelcol:$(ARCH),push=false --build-arg ARCH=$(ARCH) --build-arg SMART_AGENT_RELEASE=$(SMART_AGENT_RELEASE) ./cmd/otelcol/
214+
docker tag otelcol:$(ARCH) otelcol:latest
213215
rm ./cmd/otelcol/otelcol
214216
rm ./cmd/otelcol/translatesfx
215217
rm ./cmd/otelcol/migratecheckpoint
@@ -242,7 +244,6 @@ binaries-windows_amd64:
242244
GOOS=windows GOARCH=amd64 EXTENSION=.exe $(MAKE) migratecheckpoint
243245

244246
.PHONY: deb-rpm-package
245-
%-package: ARCH ?= amd64
246247
%-package:
247248
ifneq ($(SKIP_COMPILE), true)
248249
$(MAKE) binaries-linux_$(ARCH)

cmd/otelcol/Dockerfile

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,25 @@ RUN mkdir -p /otel/collector /splunk-otel-collector
1616

1717
FROM alpine:3.14.2 AS smartagent
1818
ARG SMART_AGENT_RELEASE
19+
ARG ARCH="amd64"
1920

2021
COPY --from=otelcol /etc_passwd /etc_passwd
2122
RUN cat /etc_passwd >> /etc/passwd
2223
COPY --from=otelcol --chown=999 /splunk-otel-collector /usr/lib/splunk-otel-collector
2324
USER splunk-otel-collector
24-
RUN SMART_AGENT=signalfx-agent-${SMART_AGENT_RELEASE#v}.tar.gz && \
25-
URL=https://github.com/signalfx/signalfx-agent/releases/download/${SMART_AGENT_RELEASE}/$SMART_AGENT && \
26-
cd /usr/lib/splunk-otel-collector && wget "$URL" && tar -xzf $SMART_AGENT && mv signalfx-agent agent-bundle && \
27-
# Absolute path of interpreter in smart agent dir is set in dependent binaries
28-
# requiring the interpreter location not to change.
29-
/usr/lib/splunk-otel-collector/agent-bundle/bin/patch-interpreter /usr/lib/splunk-otel-collector/agent-bundle && \
30-
rm -f /usr/lib/splunk-otel-collector/agent-bundle/bin/signalfx-agent \
31-
/usr/lib/splunk-otel-collector/agent-bundle/bin/agent-status \
32-
$SMART_AGENT
25+
RUN if [ "$ARCH" = "amd64" ]; then \
26+
SMART_AGENT=signalfx-agent-${SMART_AGENT_RELEASE#v}.tar.gz && \
27+
URL=https://github.com/signalfx/signalfx-agent/releases/download/${SMART_AGENT_RELEASE}/$SMART_AGENT && \
28+
cd /usr/lib/splunk-otel-collector && wget "$URL" && tar -xzf $SMART_AGENT && mv signalfx-agent agent-bundle && \
29+
# Absolute path of interpreter in smart agent dir is set in dependent binaries
30+
# requiring the interpreter location not to change.
31+
/usr/lib/splunk-otel-collector/agent-bundle/bin/patch-interpreter /usr/lib/splunk-otel-collector/agent-bundle && \
32+
rm -f /usr/lib/splunk-otel-collector/agent-bundle/bin/signalfx-agent \
33+
/usr/lib/splunk-otel-collector/agent-bundle/bin/agent-status \
34+
$SMART_AGENT; \
35+
else \
36+
mkdir -p /usr/lib/splunk-otel-collector/agent-bundle; \
37+
fi
3338
RUN find /usr/lib/splunk-otel-collector/agent-bundle -name "*.key" -delete -or -name "*.pem" -delete
3439

3540
FROM scratch

0 commit comments

Comments
 (0)