From 5a3180065b0c63c5c1116efbbe67f5c07ca194e3 Mon Sep 17 00:00:00 2001 From: Tugdual Saunier Date: Sun, 16 Apr 2023 16:52:02 -0400 Subject: [PATCH] Build the Docker driver for arm64 **What this PR does / why we need it**: Add ARM64 build and release of the Docker driver in Drone pipeline **Which issue(s) this PR fixes**: Fixes #5682 **Special notes for your reviewer**: I would have loved to have a unified x64 and arm64 build but apparently Docker drivers does not support multi arch images. So instead I went with tweaking the build steps to allow cross building the image for ARM64 and added the instructions to do so in `drone.yml`. **Checklist** - [x] Reviewed the [`CONTRIBUTING.md`](https://github.com/grafana/loki/blob/main/CONTRIBUTING.md) guide (**required**) - [x] Documentation added - [ ] Tests updated - [ ] Changes that require user attention or interaction to upgrade are documented in `docs/sources/upgrading/_index.md` --- .drone/drone.jsonnet | 1 + Makefile | 7 ++++++- clients/cmd/docker-driver/Dockerfile | 18 ++++++++++++++---- docs/sources/send-data/docker-driver/_index.md | 3 +++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/.drone/drone.jsonnet b/.drone/drone.jsonnet index 718f0a84aa886..5c8e154960f93 100644 --- a/.drone/drone.jsonnet +++ b/.drone/drone.jsonnet @@ -628,6 +628,7 @@ local build_image_tag = '0.33.2'; commands: [ 'git fetch origin --tags', 'make docker-driver-push', + 'make docker-driver-push PLUGIN_ARCH=-arm64', ], volumes: [ { diff --git a/Makefile b/Makefile index cadce23fe2624..463caf5f6be09 100644 --- a/Makefile +++ b/Makefile @@ -458,13 +458,18 @@ endif LOKI_DOCKER_DRIVER ?= "grafana/loki-docker-driver" PLUGIN_TAG ?= $(IMAGE_TAG) PLUGIN_ARCH ?= +PLUGIN_BUILD_ARGS ?= +ifeq ("$(PLUGIN_ARCH)", "-arm64") + PLUGIN_BUILD_ARGS = --build-arg GOARCH=arm64 +endif # build-rootfs # builds the plugin rootfs define build-rootfs rm -rf clients/cmd/docker-driver/rootfs || true mkdir clients/cmd/docker-driver/rootfs - docker build --build-arg $(BUILD_IMAGE) -t rootfsimage -f clients/cmd/docker-driver/Dockerfile . + + docker build $(PLUGIN_BUILD_ARGS) --build-arg $(BUILD_IMAGE) -t rootfsimage -f clients/cmd/docker-driver/Dockerfile . ID=$$(docker create rootfsimage true) && \ (docker export $$ID | tar -x -C clients/cmd/docker-driver/rootfs) && \ diff --git a/clients/cmd/docker-driver/Dockerfile b/clients/cmd/docker-driver/Dockerfile index 88f6b47fe2623..fc429182e4855 100644 --- a/clients/cmd/docker-driver/Dockerfile +++ b/clients/cmd/docker-driver/Dockerfile @@ -1,16 +1,26 @@ + ARG BUILD_IMAGE=grafana/loki-build-image:0.33.4 +ARG GOARCH=amd64 # Directories in this file are referenced from the root of the project not this folder # This file is intended to be called from the root like so: -# docker build -t grafana/loki -f cmd/loki/Dockerfile . +# docker build -t grafana/loki-docker-driver -f clients/cmd/docker-driver/Dockerfile . -# TODO: add cross-platform support FROM $BUILD_IMAGE as build COPY . /src/loki WORKDIR /src/loki RUN make clean && make BUILD_IN_CONTAINER=false clients/cmd/docker-driver/docker-driver -FROM alpine:3.18.5 -RUN apk add --update --no-cache ca-certificates tzdata +FROM alpine:3.18.5 as temp + +RUN apk add --update --no-cache --arch=${GOARCH} ca-certificates tzdata + +FROM --platform=linux/${GOARCH} alpine:3.18.5 + +COPY --from=temp /etc/ca-certificates.conf /etc/ca-certificates.conf +COPY --from=temp /usr/share/ca-certificates /usr/share/ca-certificates +COPY --from=temp /usr/share/zoneinfo /usr/share/zoneinfo + COPY --from=build /src/loki/clients/cmd/docker-driver/docker-driver /bin/docker-driver + WORKDIR /bin/ ENTRYPOINT [ "/bin/docker-driver" ] diff --git a/docs/sources/send-data/docker-driver/_index.md b/docs/sources/send-data/docker-driver/_index.md index f262829d58fd7..bc290fd9a3ff3 100644 --- a/docs/sources/send-data/docker-driver/_index.md +++ b/docs/sources/send-data/docker-driver/_index.md @@ -31,6 +31,9 @@ Run the following command to install the plugin, updating the release version if ```bash docker plugin install grafana/loki-docker-driver:2.9.2 --alias loki --grant-all-permissions ``` +{{% admonition type="note" %}} +Add `-arm64` to the image tag for AMR64 hosts. +{{% /admonition %}} To check installed plugins, use the `docker plugin ls` command. Plugins that have started successfully are listed as enabled: