Skip to content

Commit

Permalink
Build loki-build-image for multiple architectures. (#11130)
Browse files Browse the repository at this point in the history
**What this PR does / why we need it**:
The current `loki-build-image` is for `amd64` only. However, many are
developing Loki on Apple Silicon. That's why we should publish build
images for `arm64` as well.

**Checklist**
- [ ] Reviewed the
[`CONTRIBUTING.md`](https://github.com/grafana/loki/blob/main/CONTRIBUTING.md)
guide (**required**)
- [ ] Documentation added
- [ ] Tests updated
- [ ] `CHANGELOG.md` updated
- [ ] If the change is worth mentioning in the release notes, add
`add-to-release-notes` label
- [ ] Changes that require user attention or interaction to upgrade are
documented in `docs/sources/setup/upgrade/_index.md`
- [ ] For Helm chart changes bump the Helm chart version in
`production/helm/loki/Chart.yaml` and update
`production/helm/loki/CHANGELOG.md` and
`production/helm/loki/README.md`. [Example
PR](d10549e)
- [ ] If the change is deprecating or removing a configuration option,
update the `deprecated-config.yaml` and `deleted-config.yaml` files
respectively in the `tools/deprecated-config-checker` directory.
[Example
PR](0d4416a)
  • Loading branch information
jeschkies authored Nov 6, 2023
1 parent cb4e800 commit 3086a3b
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 66 deletions.
17 changes: 17 additions & 0 deletions .drone/docker-manifest-build-image.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
image: grafana/{{config.target}}
tags:
{{#if build.tags}}
{{#each build.tags}}
- {{this}}
{{/each}}
{{/if}}
manifests:
- image: grafana/{{config.target}}-amd64
platform:
architecture: amd64
os: linux
- image: grafana/{{config.target}}-arm64
platform:
architecture: arm64
os: linux
variant: v8
45 changes: 39 additions & 6 deletions .drone/drone.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -496,41 +496,74 @@ local manifest_ecr(apps, archs) = pipeline('manifest-ecr') {
],
};

local build_image_tag = '0.32.0';
[
pipeline('loki-build-image') {
local build_image_tag = '0.31.2',
pipeline('loki-build-image-' + arch) {
workspace: {
base: '/src',
path: 'loki',
},
platform: {
os: 'linux',
arch: arch,
},
steps: [
{
name: 'test-image',
name: 'test',
image: 'plugins/docker',
when: onPRs + onPath('loki-build-image/**'),
environment: {
DOCKER_BUILDKIT: 1,
},
settings: {
repo: 'grafana/loki-build-image',
context: 'loki-build-image',
dockerfile: 'loki-build-image/Dockerfile',
tags: [build_image_tag],
tags: [build_image_tag + '-' + arch],
dry_run: true,
},
},
{
name: 'push-image',
name: 'push',
image: 'plugins/docker',
when: onTagOrMain + onPath('loki-build-image/**'),
environment: {
DOCKER_BUILDKIT: 1,
},
settings: {
repo: 'grafana/loki-build-image',
context: 'loki-build-image',
dockerfile: 'loki-build-image/Dockerfile',
username: { from_secret: docker_username_secret.name },
password: { from_secret: docker_password_secret.name },
tags: [build_image_tag],
tags: [build_image_tag + '-' + arch],
dry_run: false,
},
},
],
}
for arch in ['amd64', 'arm64']
] + [
pipeline('loki-build-image-publish') {
steps: [
{
name: 'manifest',
image: 'plugins/manifest:1.4.0',
when: onTagOrMain + onPath('loki-build-image/**'),
settings: {
// the target parameter is abused for the app's name, as it is unused in spec mode.
target: 'loki-build-image:' + build_image_tag,
spec: '.drone/docker-manifest-build-image.tmpl',
ignore_missing: false,
username: { from_secret: docker_username_secret.name },
password: { from_secret: docker_password_secret.name },
},
},
],
depends_on: [
'loki-build-image-%s' % arch
for arch in ['amd64', 'arm64']
],
},
pipeline('helm-test-image') {
workspace: {
Expand Down
105 changes: 97 additions & 8 deletions .drone/drone.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
---
kind: pipeline
name: loki-build-image
name: loki-build-image-amd64
platform:
arch: amd64
os: linux
steps:
- image: plugins/docker
name: test-image
- environment:
DOCKER_BUILDKIT: 1
image: plugins/docker
name: test
settings:
context: loki-build-image
dockerfile: loki-build-image/Dockerfile
dry_run: true
repo: grafana/loki-build-image
tags:
- 0.31.2
- 0.32.0-amd64
when:
event:
- pull_request
paths:
- loki-build-image/**
- image: plugins/docker
name: push-image
- environment:
DOCKER_BUILDKIT: 1
image: plugins/docker
name: push
settings:
context: loki-build-image
dockerfile: loki-build-image/Dockerfile
Expand All @@ -26,7 +33,7 @@ steps:
from_secret: docker_password
repo: grafana/loki-build-image
tags:
- 0.31.2
- 0.32.0-amd64
username:
from_secret: docker_username
when:
Expand All @@ -46,6 +53,88 @@ workspace:
path: loki
---
kind: pipeline
name: loki-build-image-arm64
platform:
arch: arm64
os: linux
steps:
- environment:
DOCKER_BUILDKIT: 1
image: plugins/docker
name: test
settings:
context: loki-build-image
dockerfile: loki-build-image/Dockerfile
dry_run: true
repo: grafana/loki-build-image
tags:
- 0.32.0-arm64
when:
event:
- pull_request
paths:
- loki-build-image/**
- environment:
DOCKER_BUILDKIT: 1
image: plugins/docker
name: push
settings:
context: loki-build-image
dockerfile: loki-build-image/Dockerfile
dry_run: false
password:
from_secret: docker_password
repo: grafana/loki-build-image
tags:
- 0.32.0-arm64
username:
from_secret: docker_username
when:
event:
- push
- tag
paths:
- loki-build-image/**
trigger:
ref:
- refs/heads/main
- refs/heads/k???
- refs/tags/v*
- refs/pull/*/head
workspace:
base: /src
path: loki
---
depends_on:
- loki-build-image-amd64
- loki-build-image-arm64
kind: pipeline
name: loki-build-image-publish
steps:
- image: plugins/manifest:1.4.0
name: manifest
settings:
ignore_missing: false
password:
from_secret: docker_password
spec: .drone/docker-manifest-build-image.tmpl
target: loki-build-image:0.32.0
username:
from_secret: docker_username
when:
event:
- push
- tag
paths:
- loki-build-image/**
trigger:
ref:
- refs/heads/main
- refs/heads/k???
- refs/tags/v*
- refs/pull/*/head
---
kind: pipeline
name: helm-test-image
steps:
- image: plugins/docker
Expand Down Expand Up @@ -2017,6 +2106,6 @@ kind: secret
name: gpg_private_key
---
kind: signature
hmac: a68ce0151ff769aa0731f120437450f0d9685c843cb3c5b046d4991f910aadd7
hmac: caf375427f92f78711f801f56341357b67737330e906346ee908a796c61dd314

...
30 changes: 16 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ BUILD_IMAGE_VERSION ?= 0.31.2
# Docker image info
IMAGE_PREFIX ?= grafana

IMAGE_TAG := $(shell ./tools/image-tag)
IMAGE_TAG ?= $(shell ./tools/image-tag)

# Version info for binaries
GIT_REVISION := $(shell git rev-parse --short HEAD)
Expand Down Expand Up @@ -102,16 +102,14 @@ RM := --rm
TTY := --tty

DOCKER_BUILDKIT=1
OCI_PLATFORMS=--platform=linux/amd64 --platform=linux/arm64 --platform=linux/arm/7
BUILD_IMAGE = BUILD_IMAGE=$(IMAGE_PREFIX)/loki-build-image:$(BUILD_IMAGE_VERSION)
PUSH_OCI=docker push
TAG_OCI=docker tag
ifeq ($(CI), true)
BUILD_OCI=img build --no-console $(OCI_PLATFORMS) --build-arg $(BUILD_IMAGE)
PUSH_OCI=img push
TAG_OCI=img tag
OCI_PLATFORMS=--platform=linux/amd64,linux/arm64
BUILD_OCI=docker buildx build $(OCI_PLATFORMS) --build-arg $(BUILD_IMAGE)
else
BUILD_OCI=docker build --build-arg $(BUILD_IMAGE)
PUSH_OCI=docker push
TAG_OCI=docker tag
endif

binfmt:
Expand Down Expand Up @@ -565,7 +563,6 @@ promtail-image: ## build the promtail docker image
promtail-image-cross:
$(SUDO) $(BUILD_OCI) -t $(IMAGE_PREFIX)/promtail:$(IMAGE_TAG) -f clients/cmd/promtail/Dockerfile.cross .

promtail-debug-image: OCI_PLATFORMS=
promtail-debug-image: ## build the promtail debug docker image
$(SUDO) $(BUILD_OCI) -t $(IMAGE_PREFIX)/promtail:$(IMAGE_TAG)-debug -f clients/cmd/promtail/Dockerfile.debug .

Expand All @@ -578,7 +575,6 @@ loki-image: ## build the loki docker image
loki-image-cross:
$(SUDO) $(BUILD_OCI) -t $(IMAGE_PREFIX)/loki:$(IMAGE_TAG) -f cmd/loki/Dockerfile.cross .

loki-debug-image: OCI_PLATFORMS=
loki-debug-image: ## build the debug loki docker image
$(SUDO) $(BUILD_OCI) -t $(IMAGE_PREFIX)/loki:$(IMAGE_TAG)-debug -f cmd/loki/Dockerfile.debug .

Expand Down Expand Up @@ -620,17 +616,23 @@ logql-analyzer-push: logql-analyzer-image ## push the LogQL Analyzer image
$(call push-image,logql-analyzer)


# build-image (only amd64)
build-image: OCI_PLATFORMS=
build-image: ## build the docker build image
# build-image
ensure-buildx-builder:
ifeq ($(CI),true)
./tools/ensure-buildx-builder.sh
else
@echo "skipping buildx setup"
endif

build-image: ensure-buildx-builder
$(SUDO) $(BUILD_OCI) -t $(IMAGE_PREFIX)/loki-build-image:$(IMAGE_TAG) ./loki-build-image
build-image-push: build-image ## push the docker build image
ifneq (,$(findstring WIP,$(IMAGE_TAG)))
@echo "Cannot push a WIP image, commit changes first"; \
false;
endif
$(call push,loki-build-image,$(BUILD_IMAGE_VERSION))
$(call push,loki-build-image,latest)
echo ${DOCKER_PASSWORD} | docker login --username ${DOCKER_USERNAME} --password-stdin
$(SUDO) $(BUILD_OCI) -o type=registry -t $(IMAGE_PREFIX)/loki-build-image:$(IMAGE_TAG) ./loki-build-image

# loki-operator
loki-operator-image:
Expand Down
27 changes: 3 additions & 24 deletions docs/sources/community/maintaining/release/patch-go-version.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,8 @@ Update vulnerable Go version to non-vulnerable Go version to build Grafana Loki

1. Update Go version in the Grafana Loki build image (`loki-build-image/Dockerfile`) on the `main` branch.

1. [Backport]({{< relref "./backport-commits" >}}) it to `release-VERSION_PREFIX` branch.
1. [Release a new Loki Build Image]({{< relref "../release-loki-build-image.md" >}})

1. Determine new Grafana Loki build image version.
1. [Backport]({{< relref "./backport-commits" >}}) the Dockerfile change to `release-VERSION_PREFIX` branch.

1. Check current `BUILD_IMAGE_VERSION` from `Makefile`.

1. Increment 1 to the last digit. Example `v0.29.4` becomes `v0.29.5`

1. This will be your new `NEW_BUILD_IMAGE_VERSION`.

1. Build and push new Grafana Loki build image.

```shell
BUILD_IMAGE_VERSION=$NEW_BUILD_IMAGE_VERSION make build-image-push
```

1. Update build image versions on `main` branch.

1. Update `BUILD_IMAGE_VERSION` to `$NEW_BUILD_IMAGE_VERSION` in `Makefile`

1. Update drone file.
```shell
make .drone/drone.yml
```

1. [Backport]({{< relref "./backport-commits" >}}) it to `release-VERSION_PREFIX` branch.
1. [Backport]({{< relref "./backport-commits" >}}) the Loki Build Image version change from `main` to `release-VERSION_PREFIX` branch.
Loading

0 comments on commit 3086a3b

Please sign in to comment.