Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build ARM64 Docker images #55

Merged
merged 3 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .github/workflows/ci-goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,20 @@ jobs:
with:
fetch-depth: 0

- name: Set up QEMU
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the missing piece, thanks!

id: qemu
uses: docker/setup-qemu-action@v1
with:
platforms: arm64

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: "1.17"

- name: Generate the sources
run: make generate-sources
Expand Down
15 changes: 12 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,31 @@ on:
push:
tags: ["v*"]



jobs:
release:
name: Release
runs-on: ubuntu-20.04

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v1
with:
platforms: arm64

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: "1.17"

- name: Generate distribution sources
run: make generate-sources
Expand Down
32 changes: 32 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ docker_manifests:
- name_template: otel/opentelemetry-collector-contrib:{{ .Version }}
image_templates:
- otel/opentelemetry-collector-contrib:{{ .Version }}-amd64
- otel/opentelemetry-collector-contrib:{{ .Version }}-arm64
- name_template: otel/opentelemetry-collector:{{ .Version }}
image_templates:
- otel/opentelemetry-collector:{{ .Version }}-amd64
- otel/opentelemetry-collector:{{ .Version }}-arm64
dockers:
- image_templates:
- "otel/opentelemetry-collector-contrib:{{ .Version }}-amd64"
Expand All @@ -78,6 +80,21 @@ dockers:
extra_files:
- "configs/otelcol-contrib.yaml"
goarch: amd64
- image_templates:
- "otel/opentelemetry-collector-contrib:{{ .Version }}-arm64"
dockerfile: "distributions/otelcol-contrib/Dockerfile"
use: buildx
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.name={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source={{.GitURL}}"
- "--platform=linux/arm64"
extra_files:
- "configs/otelcol-contrib.yaml"
goarch: arm64
- image_templates:
- "otel/opentelemetry-collector:{{ .Version }}-amd64"
dockerfile: "distributions/otelcol/Dockerfile"
Expand All @@ -93,6 +110,21 @@ dockers:
extra_files:
- "configs/otelcol.yaml"
goarch: amd64
- image_templates:
- "otel/opentelemetry-collector:{{ .Version }}-arm64"
dockerfile: "distributions/otelcol/Dockerfile"
use: buildx
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.name={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source={{.GitURL}}"
- "--platform=linux/arm64"
extra_files:
- "configs/otelcol.yaml"
goarch: arm64
nfpms:
- id: "otelcol-contrib"
package_name: "otelcol-contrib"
Expand Down
19 changes: 18 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,25 @@ The main `Makefile` is mostly a wrapper around scripts under the [./scripts](./s

[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.

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

```shell
make generate-goreleaser
```

After that, you can test the goreleaser build process with:

```shell
make goreleaser-verify
```

#### Building multi-architecture Docker images

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.

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:

```shell
apt-get install qemu binfmt-support qemu-user-static
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
```
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
OpenTelemetry Collector distributions
===
# OpenTelemetry Collector distributions

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.

Each distribution contains:

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

More details about each individual distribution can be seen in its own readme files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ docker_manifests:
- name_template: ${CONTAINER_BASE_NAME}:{{ .Version }}
image_templates:
- ${CONTAINER_BASE_NAME}:{{ .Version }}-amd64
- ${CONTAINER_BASE_NAME}:{{ .Version }}-arm64
15 changes: 15 additions & 0 deletions scripts/goreleaser-templates/docker.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,18 @@ dockers:
extra_files:
- "configs/{distribution}.yaml"
goarch: amd64
- image_templates:
- "${CONTAINER_BASE_NAME}:{{ .Version }}-arm64"
dockerfile: "distributions/{distribution}/Dockerfile"
use: buildx
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.name={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source={{.GitURL}}"
- "--platform=linux/arm64"
extra_files:
- "configs/{distribution}.yaml"
goarch: arm64