Skip to content

Commit bc17ab4

Browse files
authored
Build ARMv6, ARMv7, and ARM64 Docker images (#39)
* Install ocb and yq portably * Build ARMv6, ARMv7, and ARM64 Docker images
1 parent 91da983 commit bc17ab4

File tree

5 files changed

+135
-25
lines changed

5 files changed

+135
-25
lines changed

.goreleaser.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ docker_manifests:
3838
- name_template: otel/opentelemetry-collector:{{ .Version }}
3939
image_templates:
4040
- otel/opentelemetry-collector:{{ .Version }}-amd64
41+
- otel/opentelemetry-collector:{{ .Version }}-armv6
42+
- otel/opentelemetry-collector:{{ .Version }}-armv7
43+
- otel/opentelemetry-collector:{{ .Version }}-arm64
4144
dockers:
4245
- image_templates:
4346
- "otel/opentelemetry-collector:{{ .Version }}-amd64"
@@ -54,6 +57,53 @@ dockers:
5457
extra_files:
5558
- "configs/otelcol.yaml"
5659
goarch: amd64
60+
- image_templates:
61+
- "otel/opentelemetry-collector:{{ .Version }}-armv6"
62+
dockerfile: "distributions/otelcol/Dockerfile"
63+
use: buildx
64+
build_flag_templates:
65+
- "--pull"
66+
- "--label=org.opencontainers.image.created={{.Date}}"
67+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
68+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
69+
- "--label=org.opencontainers.image.version={{.Version}}"
70+
- "--label=org.opencontainers.image.source={{.GitURL}}"
71+
- "--platform=linux/arm/v6"
72+
extra_files:
73+
- "configs/otelcol.yaml"
74+
goarch: arm
75+
goarm: 6
76+
- image_templates:
77+
- "otel/opentelemetry-collector:{{ .Version }}-armv7"
78+
dockerfile: "distributions/otelcol/Dockerfile"
79+
use: buildx
80+
build_flag_templates:
81+
- "--pull"
82+
- "--label=org.opencontainers.image.created={{.Date}}"
83+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
84+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
85+
- "--label=org.opencontainers.image.version={{.Version}}"
86+
- "--label=org.opencontainers.image.source={{.GitURL}}"
87+
- "--platform=linux/arm/v7"
88+
extra_files:
89+
- "configs/otelcol.yaml"
90+
goarch: arm
91+
goarm: 7
92+
- image_templates:
93+
- "otel/opentelemetry-collector:{{ .Version }}-arm64"
94+
dockerfile: "distributions/otelcol/Dockerfile"
95+
use: buildx
96+
build_flag_templates:
97+
- "--pull"
98+
- "--label=org.opencontainers.image.created={{.Date}}"
99+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
100+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
101+
- "--label=org.opencontainers.image.version={{.Version}}"
102+
- "--label=org.opencontainers.image.source={{.GitURL}}"
103+
- "--platform=linux/arm64"
104+
extra_files:
105+
- "configs/otelcol.yaml"
106+
goarch: arm64
57107
nfpms:
58108
- id: "otelcol"
59109
package_name: "otelcol"

Makefile

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
GO=$(shell which go)
22
OTELCOL_BUILDER_VERSION ?= 0.41.0
3-
OTELCOL_BUILDER_DIR ?= ~/bin
3+
OTELCOL_BUILDER_DIR ?= ${HOME}/bin
44
OTELCOL_BUILDER ?= ${OTELCOL_BUILDER_DIR}/ocb
55

66
YQ_VERSION ?= 4.11.1
@@ -30,25 +30,33 @@ ensure-goreleaser-up-to-date: generate-goreleaser
3030
@git diff -s --exit-code .goreleaser.yaml || (echo "Build failed: The goreleaser templates have changed but the .goreleaser.yaml hasn't. Run 'make generate-goreleaser' and update your PR." && exit 1)
3131

3232
ocb:
33-
ifeq (, $(shell which ocb))
33+
ifeq (, $(shell which ocb >/dev/null 2>/dev/null))
3434
@{ \
3535
set -e ;\
36-
echo Installing ocb at $(OTELCOL_BUILDER_DIR);\
36+
os=$$(uname | tr A-Z a-z) ;\
37+
machine=$$(uname -m) ;\
38+
[ "$${machine}" != x86 ] || machine=386 ;\
39+
[ "$${machine}" != x86_64 ] || machine=amd64 ;\
40+
echo "Installing ocb ($${os}/$${machine}) at $(OTELCOL_BUILDER_DIR)";\
3741
mkdir -p $(OTELCOL_BUILDER_DIR) ;\
38-
curl -sLo $(OTELCOL_BUILDER) "https://github.com/open-telemetry/opentelemetry-collector/releases/download/v$(OTELCOL_BUILDER_VERSION)/ocb_$(OTELCOL_BUILDER_VERSION)_linux_amd64" ;\
42+
curl -sLo $(OTELCOL_BUILDER) "https://github.com/open-telemetry/opentelemetry-collector/releases/download/v$(OTELCOL_BUILDER_VERSION)/ocb_$(OTELCOL_BUILDER_VERSION)_$${os}_$${machine}" ;\
3943
chmod +x $(OTELCOL_BUILDER) ;\
4044
}
4145
else
4246
OTELCOL_BUILDER=$(shell which ocb)
4347
endif
4448

4549
yq:
46-
ifeq (, $(shell which yq))
50+
ifeq (, $(shell which yq >/dev/null 2>/dev/null))
4751
@{ \
4852
set -e ;\
49-
echo Installing yq at $(YQ_DIR);\
53+
os=$$(uname | tr A-Z a-z) ;\
54+
machine=$$(uname -m) ;\
55+
[ "$${machine}" != x86 ] || machine=386 ;\
56+
[ "$${machine}" != x86_64 ] || machine=amd64 ;\
57+
echo "Installing yq ($${os}/$${machine}) at $(YQ_DIR)";\
5058
mkdir -p $(YQ_DIR) ;\
51-
curl -sLo $(YQ) https://github.com/mikefarah/yq/releases/download/v$(YQ_VERSION)/yq_linux_amd64 ;\
59+
curl -sLo $(YQ) https://github.com/mikefarah/yq/releases/download/v$(YQ_VERSION)/yq_$${os}_$${machine} ;\
5260
chmod +x $(YQ) ;\
5361
}
5462
else

scripts/generate-goreleaser-config.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ do
1313
esac
1414
done
1515

16-
if [ -z $distributions ]; then
16+
if [[ -z $distributions ]]; then
1717
echo "List of distributions to use with goreleaser not provided. Use '-d' to specify the names of the distributions. Ex.:"
1818
echo "$0 -d opentelemetry-collector"
1919
exit 1
@@ -30,19 +30,21 @@ do
3030
export CONTAINER_BASE_NAME="otel/{distribution}"
3131
DIST_CONF="${REPO_DIR}/distributions/${distribution}/distribution.conf"
3232

33-
if [ -f "${DIST_CONF}" ]; then
33+
if [[ -f "${DIST_CONF}" ]]; then
3434
set -o allexport
3535
source "${DIST_CONF}"
3636
set +o allexport
3737
fi
3838

3939
sed "s/{distribution}/${distribution}/gi" "${TEMPLATES_DIR}/${template}.template.yaml" | envsubst > "${GEN_YAML_DIR}/${distribution}-${template}.yaml"
40-
if [ $? != 0 ]; then
40+
if [[ $? -ne 0 ]]; then
4141
echo "❌ ERROR: failed to generate '${template}' YAML snippets for '${distribution}'."
4242
exit 1
4343
fi
4444
done
4545
done
4646

47+
set -e -o pipefail
48+
4749
${YQ} eval-all '. as $item ireduce ({}; . *+ $item)' "${MAIN_TEMPLATE}" "${GEN_YAML_DIR}"/*.yaml > .goreleaser.yaml
4850
echo "✅ SUCCESS: goreleaser YAML generated"

scripts/goreleaser-templates/docker-manifests.template.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ docker_manifests:
22
- name_template: ${CONTAINER_BASE_NAME}:{{ .Version }}
33
image_templates:
44
- ${CONTAINER_BASE_NAME}:{{ .Version }}-amd64
5+
- ${CONTAINER_BASE_NAME}:{{ .Version }}-armv6
6+
- ${CONTAINER_BASE_NAME}:{{ .Version }}-armv7
7+
- ${CONTAINER_BASE_NAME}:{{ .Version }}-arm64
Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,63 @@
11
dockers:
2-
- image_templates:
3-
- "${CONTAINER_BASE_NAME}:{{ .Version }}-amd64"
4-
dockerfile: "distributions/{distribution}/Dockerfile"
5-
use: buildx
6-
build_flag_templates:
7-
- "--pull"
8-
- "--label=org.opencontainers.image.created={{.Date}}"
9-
- "--label=org.opencontainers.image.name={{.ProjectName}}"
10-
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
11-
- "--label=org.opencontainers.image.version={{.Version}}"
12-
- "--label=org.opencontainers.image.source={{.GitURL}}"
13-
- "--platform=linux/amd64"
14-
extra_files:
15-
- "configs/{distribution}.yaml"
16-
goarch: amd64
2+
- image_templates:
3+
- "${CONTAINER_BASE_NAME}:{{ .Version }}-amd64"
4+
dockerfile: "distributions/{distribution}/Dockerfile"
5+
use: buildx
6+
build_flag_templates:
7+
- "--pull"
8+
- "--label=org.opencontainers.image.created={{.Date}}"
9+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
10+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
11+
- "--label=org.opencontainers.image.version={{.Version}}"
12+
- "--label=org.opencontainers.image.source={{.GitURL}}"
13+
- "--platform=linux/amd64"
14+
extra_files:
15+
- "configs/{distribution}.yaml"
16+
goarch: amd64
17+
- image_templates:
18+
- "${CONTAINER_BASE_NAME}:{{ .Version }}-armv6"
19+
dockerfile: "distributions/{distribution}/Dockerfile"
20+
use: buildx
21+
build_flag_templates:
22+
- "--pull"
23+
- "--label=org.opencontainers.image.created={{.Date}}"
24+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
25+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
26+
- "--label=org.opencontainers.image.version={{.Version}}"
27+
- "--label=org.opencontainers.image.source={{.GitURL}}"
28+
- "--platform=linux/arm/v6"
29+
extra_files:
30+
- "configs/{distribution}.yaml"
31+
goarch: arm
32+
goarm: 6
33+
- image_templates:
34+
- "${CONTAINER_BASE_NAME}:{{ .Version }}-armv7"
35+
dockerfile: "distributions/{distribution}/Dockerfile"
36+
use: buildx
37+
build_flag_templates:
38+
- "--pull"
39+
- "--label=org.opencontainers.image.created={{.Date}}"
40+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
41+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
42+
- "--label=org.opencontainers.image.version={{.Version}}"
43+
- "--label=org.opencontainers.image.source={{.GitURL}}"
44+
- "--platform=linux/arm/v7"
45+
extra_files:
46+
- "configs/{distribution}.yaml"
47+
goarch: arm
48+
goarm: 7
49+
- image_templates:
50+
- "${CONTAINER_BASE_NAME}:{{ .Version }}-arm64"
51+
dockerfile: "distributions/{distribution}/Dockerfile"
52+
use: buildx
53+
build_flag_templates:
54+
- "--pull"
55+
- "--label=org.opencontainers.image.created={{.Date}}"
56+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
57+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
58+
- "--label=org.opencontainers.image.version={{.Version}}"
59+
- "--label=org.opencontainers.image.source={{.GitURL}}"
60+
- "--platform=linux/arm64"
61+
extra_files:
62+
- "configs/{distribution}.yaml"
63+
goarch: arm64

0 commit comments

Comments
 (0)