Skip to content

Commit e630858

Browse files
authored
Build ARM64 Docker images (#55)
* Build ARM64 Docker images * Add ARM64 support to CI workflows * Update docs about multi-arch Docker builds
1 parent 80c95d2 commit e630858

File tree

7 files changed

+91
-8
lines changed

7 files changed

+91
-8
lines changed

.github/workflows/ci-goreleaser.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,20 @@ jobs:
1818
with:
1919
fetch-depth: 0
2020

21+
- name: Set up QEMU
22+
id: qemu
23+
uses: docker/setup-qemu-action@v1
24+
with:
25+
platforms: arm64
26+
27+
- name: Set up Docker Buildx
28+
id: buildx
29+
uses: docker/setup-buildx-action@v1
30+
2131
- name: Set up Go
2232
uses: actions/setup-go@v2
2333
with:
24-
go-version: 1.17
34+
go-version: "1.17"
2535

2636
- name: Generate the sources
2737
run: make generate-sources

.github/workflows/release.yaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,31 @@ on:
44
push:
55
tags: ["v*"]
66

7-
8-
97
jobs:
108
release:
119
name: Release
1210
runs-on: ubuntu-20.04
11+
1312
steps:
1413
- name: Checkout
1514
uses: actions/checkout@v2
1615
with:
1716
fetch-depth: 0
1817

18+
- name: Set up QEMU
19+
id: qemu
20+
uses: docker/setup-qemu-action@v1
21+
with:
22+
platforms: arm64
23+
24+
- name: Set up Docker Buildx
25+
id: buildx
26+
uses: docker/setup-buildx-action@v1
27+
1928
- name: Set up Go
2029
uses: actions/setup-go@v2
2130
with:
22-
go-version: 1.17
31+
go-version: "1.17"
2332

2433
- name: Generate distribution sources
2534
run: make generate-sources

.goreleaser.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ docker_manifests:
5959
- name_template: otel/opentelemetry-collector-contrib:{{ .Version }}
6060
image_templates:
6161
- otel/opentelemetry-collector-contrib:{{ .Version }}-amd64
62+
- otel/opentelemetry-collector-contrib:{{ .Version }}-arm64
6263
- name_template: otel/opentelemetry-collector:{{ .Version }}
6364
image_templates:
6465
- otel/opentelemetry-collector:{{ .Version }}-amd64
66+
- otel/opentelemetry-collector:{{ .Version }}-arm64
6567
dockers:
6668
- image_templates:
6769
- "otel/opentelemetry-collector-contrib:{{ .Version }}-amd64"
@@ -78,6 +80,21 @@ dockers:
7880
extra_files:
7981
- "configs/otelcol-contrib.yaml"
8082
goarch: amd64
83+
- image_templates:
84+
- "otel/opentelemetry-collector-contrib:{{ .Version }}-arm64"
85+
dockerfile: "distributions/otelcol-contrib/Dockerfile"
86+
use: buildx
87+
build_flag_templates:
88+
- "--pull"
89+
- "--label=org.opencontainers.image.created={{.Date}}"
90+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
91+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
92+
- "--label=org.opencontainers.image.version={{.Version}}"
93+
- "--label=org.opencontainers.image.source={{.GitURL}}"
94+
- "--platform=linux/arm64"
95+
extra_files:
96+
- "configs/otelcol-contrib.yaml"
97+
goarch: arm64
8198
- image_templates:
8299
- "otel/opentelemetry-collector:{{ .Version }}-amd64"
83100
dockerfile: "distributions/otelcol/Dockerfile"
@@ -93,6 +110,21 @@ dockers:
93110
extra_files:
94111
- "configs/otelcol.yaml"
95112
goarch: amd64
113+
- image_templates:
114+
- "otel/opentelemetry-collector:{{ .Version }}-arm64"
115+
dockerfile: "distributions/otelcol/Dockerfile"
116+
use: buildx
117+
build_flag_templates:
118+
- "--pull"
119+
- "--label=org.opencontainers.image.created={{.Date}}"
120+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
121+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
122+
- "--label=org.opencontainers.image.version={{.Version}}"
123+
- "--label=org.opencontainers.image.source={{.GitURL}}"
124+
- "--platform=linux/arm64"
125+
extra_files:
126+
- "configs/otelcol.yaml"
127+
goarch: arm64
96128
nfpms:
97129
- id: "otelcol-contrib"
98130
package_name: "otelcol-contrib"

CONTRIBUTING.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,25 @@ The main `Makefile` is mostly a wrapper around scripts under the [./scripts](./s
4141

4242
[goreleaser](https://goreleaser.com) plays a big role in producing the final artifacts. Given that the final configuration file for this tool would be huge and would cause relatively big changes for each new distribution, a `Makefile` target exists to generate the `.goreleaser.yaml` for the repository. The `Makefile` contains a list of distributions (`DISTRIBUTIONS`) that is passed down to the script, which will generate snippets based on the templates from `./scripts/goreleaser-templates/`. Adding a new distribution is then only a matter of adding the distribution's directory, plus adding it to the Makefile. Adding a new snippet is only a matter of adding a new template.
4343

44-
Once there's a change either to the templates or to the list of distributions, a new `.goreleaser` file can be generated with:
44+
Once there's a change either to the templates or to the list of distributions, a new `.goreleaser.yaml` file can be generated with:
4545

4646
```shell
4747
make generate-goreleaser
4848
```
49+
50+
After that, you can test the goreleaser build process with:
51+
52+
```shell
53+
make goreleaser-verify
54+
```
55+
56+
#### Building multi-architecture Docker images
57+
58+
goreleaser will build Docker images for x86_64 and arm64 processors. The build process involves executing `RUN` steps on the target architecture, which means the system you run it on needs support for emulating foreign architectures.
59+
60+
This is accomplished by installing [qemu](https://www.qemu.org/), and then [enabling support](https://github.com/multiarch/qemu-user-static#readme) for qemu within Docker:
61+
62+
```shell
63+
apt-get install qemu binfmt-support qemu-user-static
64+
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
65+
```

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
OpenTelemetry Collector distributions
2-
===
1+
# OpenTelemetry Collector distributions
32

43
This repository assembles OpenTelemetry Collector distributions, such as the "core" distribution, or "contrib". It may contain non-official distributions, focused on specific use-cases, such as the load-balancer.
54

65
Each distribution contains:
76

87
- Binaries for a multitude of platforms and architectures
9-
- Multi-arch container images
8+
- Multi-arch container images (x86_64 and arm64)
109
- Packages to be used with Linux distributions (apk, RPM, deb), Mac OS (brew)
1110

1211
More details about each individual distribution can be seen in its own readme files.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ docker_manifests:
22
- name_template: ${CONTAINER_BASE_NAME}:{{ .Version }}
33
image_templates:
44
- ${CONTAINER_BASE_NAME}:{{ .Version }}-amd64
5+
- ${CONTAINER_BASE_NAME}:{{ .Version }}-arm64

scripts/goreleaser-templates/docker.template.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,18 @@ dockers:
1414
extra_files:
1515
- "configs/{distribution}.yaml"
1616
goarch: amd64
17+
- image_templates:
18+
- "${CONTAINER_BASE_NAME}:{{ .Version }}-arm64"
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/arm64"
29+
extra_files:
30+
- "configs/{distribution}.yaml"
31+
goarch: arm64

0 commit comments

Comments
 (0)