Skip to content

Commit

Permalink
Build ARMv6, ARMv7, and ARM64 Docker images (#39)
Browse files Browse the repository at this point in the history
* Install ocb and yq portably

* Build ARMv6, ARMv7, and ARM64 Docker images
  • Loading branch information
silverlyra committed Dec 14, 2021
1 parent 91da983 commit bc17ab4
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 25 deletions.
50 changes: 50 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ docker_manifests:
- name_template: otel/opentelemetry-collector:{{ .Version }}
image_templates:
- otel/opentelemetry-collector:{{ .Version }}-amd64
- otel/opentelemetry-collector:{{ .Version }}-armv6
- otel/opentelemetry-collector:{{ .Version }}-armv7
- otel/opentelemetry-collector:{{ .Version }}-arm64
dockers:
- image_templates:
- "otel/opentelemetry-collector:{{ .Version }}-amd64"
Expand All @@ -54,6 +57,53 @@ dockers:
extra_files:
- "configs/otelcol.yaml"
goarch: amd64
- image_templates:
- "otel/opentelemetry-collector:{{ .Version }}-armv6"
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/arm/v6"
extra_files:
- "configs/otelcol.yaml"
goarch: arm
goarm: 6
- image_templates:
- "otel/opentelemetry-collector:{{ .Version }}-armv7"
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/arm/v7"
extra_files:
- "configs/otelcol.yaml"
goarch: arm
goarm: 7
- 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"
package_name: "otelcol"
Expand Down
22 changes: 15 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GO=$(shell which go)
OTELCOL_BUILDER_VERSION ?= 0.41.0
OTELCOL_BUILDER_DIR ?= ~/bin
OTELCOL_BUILDER_DIR ?= ${HOME}/bin
OTELCOL_BUILDER ?= ${OTELCOL_BUILDER_DIR}/ocb

YQ_VERSION ?= 4.11.1
Expand Down Expand Up @@ -30,25 +30,33 @@ ensure-goreleaser-up-to-date: generate-goreleaser
@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)

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

yq:
ifeq (, $(shell which yq))
ifeq (, $(shell which yq >/dev/null 2>/dev/null))
@{ \
set -e ;\
echo Installing yq at $(YQ_DIR);\
os=$$(uname | tr A-Z a-z) ;\
machine=$$(uname -m) ;\
[ "$${machine}" != x86 ] || machine=386 ;\
[ "$${machine}" != x86_64 ] || machine=amd64 ;\
echo "Installing yq ($${os}/$${machine}) at $(YQ_DIR)";\
mkdir -p $(YQ_DIR) ;\
curl -sLo $(YQ) https://github.com/mikefarah/yq/releases/download/v$(YQ_VERSION)/yq_linux_amd64 ;\
curl -sLo $(YQ) https://github.com/mikefarah/yq/releases/download/v$(YQ_VERSION)/yq_$${os}_$${machine} ;\
chmod +x $(YQ) ;\
}
else
Expand Down
8 changes: 5 additions & 3 deletions scripts/generate-goreleaser-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ do
esac
done

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

if [ -f "${DIST_CONF}" ]; then
if [[ -f "${DIST_CONF}" ]]; then
set -o allexport
source "${DIST_CONF}"
set +o allexport
fi

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

set -e -o pipefail

${YQ} eval-all '. as $item ireduce ({}; . *+ $item)' "${MAIN_TEMPLATE}" "${GEN_YAML_DIR}"/*.yaml > .goreleaser.yaml
echo "✅ SUCCESS: goreleaser YAML generated"
3 changes: 3 additions & 0 deletions scripts/goreleaser-templates/docker-manifests.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ docker_manifests:
- name_template: ${CONTAINER_BASE_NAME}:{{ .Version }}
image_templates:
- ${CONTAINER_BASE_NAME}:{{ .Version }}-amd64
- ${CONTAINER_BASE_NAME}:{{ .Version }}-armv6
- ${CONTAINER_BASE_NAME}:{{ .Version }}-armv7
- ${CONTAINER_BASE_NAME}:{{ .Version }}-arm64
77 changes: 62 additions & 15 deletions scripts/goreleaser-templates/docker.template.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,63 @@
dockers:
- image_templates:
- "${CONTAINER_BASE_NAME}:{{ .Version }}-amd64"
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/amd64"
extra_files:
- "configs/{distribution}.yaml"
goarch: amd64
- image_templates:
- "${CONTAINER_BASE_NAME}:{{ .Version }}-amd64"
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/amd64"
extra_files:
- "configs/{distribution}.yaml"
goarch: amd64
- image_templates:
- "${CONTAINER_BASE_NAME}:{{ .Version }}-armv6"
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/arm/v6"
extra_files:
- "configs/{distribution}.yaml"
goarch: arm
goarm: 6
- image_templates:
- "${CONTAINER_BASE_NAME}:{{ .Version }}-armv7"
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/arm/v7"
extra_files:
- "configs/{distribution}.yaml"
goarch: arm
goarm: 7
- 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

0 comments on commit bc17ab4

Please sign in to comment.