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 loki-build-image for multiple architectures. #11130

Merged
merged 53 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
8afc9f3
Build loki-build-image for multiple architectures.
jeschkies Oct 9, 2023
ac6632f
Merge remote-tracking branch 'grafana/main' into karsten/multi-arch-b…
jeschkies Oct 9, 2023
435b489
Mount Docker socket.
jeschkies Oct 9, 2023
b0507b7
Provide docker sock volume.
jeschkies Oct 9, 2023
81b4c41
Use buildx
jeschkies Oct 9, 2023
ffd82a2
Ensure buildx is setup.
jeschkies Oct 9, 2023
9f8340c
Checking buildx builder script.
jeschkies Oct 9, 2023
381a128
Only build image when there are changes.
jeschkies Oct 9, 2023
963089b
Install arm packages where required.
jeschkies Oct 9, 2023
07decbf
Install the correct Helm and Helm Docs arch.
jeschkies Oct 9, 2023
ab5ccf3
Use make target to push build image.
jeschkies Oct 9, 2023
6923a52
Merge remote-tracking branch 'grafana/main' into karsten/multi-arch-b…
jeschkies Oct 9, 2023
c0dd62a
Login Docker CLI.
jeschkies Oct 9, 2023
a011576
update drone.yml
jeschkies Oct 9, 2023
a881707
Merge remote-tracking branch 'grafana/main' into karsten/multi-arch-b…
jeschkies Oct 10, 2023
ab49503
Use new build image.
jeschkies Oct 10, 2023
7669335
Merge remote-tracking branch 'grafana/main' into karsten/multi-arch-b…
jeschkies Oct 10, 2023
a456e7a
Test image push.
jeschkies Oct 10, 2023
006e831
Migrate to two step.
jeschkies Oct 11, 2023
1f3843c
Correct Docker builds.
jeschkies Oct 11, 2023
1746ed0
Pass platform parameter
jeschkies Oct 11, 2023
2492df8
Use buildkit to get target architecture.
jeschkies Oct 11, 2023
3dbf3d2
Format jsonnet
jeschkies Oct 11, 2023
50200ae
Add todo
jeschkies Oct 11, 2023
31e4129
Add manifest for build image.
jeschkies Oct 11, 2023
2ec99de
Merge remote-tracking branch 'grafana/main' into karsten/multi-arch-b…
jeschkies Nov 2, 2023
1de5317
Try with env var.
jeschkies Nov 2, 2023
c9fff01
Merge remote-tracking branch 'grafana/main' into karsten/multi-arch-b…
jeschkies Nov 2, 2023
ae9d5c0
Only run on amd64
jeschkies Nov 2, 2023
1923d10
Reduce further.
jeschkies Nov 2, 2023
879159f
Use Docker config instead of user and password.
jeschkies Nov 3, 2023
6dc1dea
Remove buildkit
jeschkies Nov 3, 2023
509f2cd
Use 'args'
jeschkies Nov 3, 2023
cafdd65
try other format
jeschkies Nov 3, 2023
82cbe25
Use secrets
jeschkies Nov 3, 2023
fb81a16
Back to square one
jeschkies Nov 3, 2023
3e5b926
Use buildkit
jeschkies Nov 3, 2023
546e099
Build for arm as well
jeschkies Nov 3, 2023
e9a31cb
publish manifest
jeschkies Nov 3, 2023
58e2711
set tag
jeschkies Nov 3, 2023
37e8053
Format jsonnet
jeschkies Nov 3, 2023
b0324b6
Try different tagging
jeschkies Nov 3, 2023
d52b186
Set version manually for now
jeschkies Nov 3, 2023
6d66011
make manifest version dynamic
jeschkies Nov 3, 2023
b2b1e33
Remove unused script
jeschkies Nov 3, 2023
a0e6a92
add test stage
jeschkies Nov 3, 2023
b5796d5
Merge remote-tracking branch 'grafana/main' into karsten/multi-arch-b…
jeschkies Nov 3, 2023
ee26621
fix jsonnet format
jeschkies Nov 3, 2023
e6c4ee4
Make complete pipeline conditional
jeschkies Nov 3, 2023
6196073
Revert previous change
jeschkies Nov 3, 2023
b552ad1
Generate drone yaml
jeschkies Nov 3, 2023
4ff6892
Fun back and forth with condition
jeschkies Nov 3, 2023
4a96bf4
Update patch Go version documentation.
jeschkies Nov 6, 2023
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
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we are just building and not pushing now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Look at line 106. PUSH_OCI is still defined. This is just for defining variables. There's no make target here.

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
Loading