Cannot build docker image using commit id 4de0149

I was using a version of grafana that I cloned on the 15th of November from the grafana repo and had setup an Azure pipeline which builds and pushes a linux docker image to an Azure container registry.

This morning I updated to the latest (4de0149) commit on the main branch and I am getting the following issue when building.

  1. Step 38/68 : ARG GRAFANA_TGZ=“grafana-latest.linux-x64-musl.tar.gz”

—> Running in e27da18e1002

Removing intermediate container e27da18e1002

—> d8d47c29475a

Step 39/68 : COPY ${GRAFANA_TGZ} /tmp/grafana.tar.gz

COPY failed: file not found in build context or excluded by .dockerignore: stat grafana-latest.linux-x64-musl.tar.gz: file does not exist

##[error]COPY failed: file not found in build context or excluded by .dockerignore: stat grafana-latest.linux-x64-musl.tar.gz: file does not exist

##[error]The process ‘/usr/bin/docker’ failed with exit code 1

Finishing: Build and push an image to container registry

I did find reference to this issue on Github - packaging/docker: build.sh can't find a file 'ARG GRAFANA_TGZ="grafana-latest.linux-x64-musl.tar.gz"' · Issue #44659 · grafana/grafana · GitHub about someone else who had the issue but it was closed without any comments and nothing is showing in the forums search.

Could someone explain what the issue with finding ‘grafana-latest.linux-x64-musl.tar.gz’ is and how to fix it?

Hi @dbritton,

Welcome to the :grafana: community support forums !!

We are excited that you joined our OSS community. Please read about some of the FAQs in the community :slight_smile:

Can you please post in that GitHub issue with all the data and then let me know here? I will then reopen the issue.

I’ve created and filled in the details on GitHub here:

Thanks and it seems that our team already picked it up as now this issue got assigned to the release engineering team :cowboy_hat_face: (while the other one you referenced, the user still did not reply back and therefore got closed).

So, in short, please track it there and subscribe to the issue notification to get the updates

I figured out the root cause - the issue arises from the missing grafana-latest.linux-x64-musl.tar.gz file. You can download this file from https://dl.grafana.com/oss/release/grafana-latest.linux-x64-musl.tar.gz. After downloading, place the file in the root directory and then run the docker build command.
My grafana version: 11.5.1。

特别得,当你在中国大陆,你运行Dockerfile可能会非常卡,因此我对Dockerfile做了改造

  1. 修改为国内源
  2. 替换了Dockfile中下载glibc-bin-2.40.tar.gz的逻辑,转换为直接使用根路径的glibc-bin-2.40.tar.gz

当你docker build之前,你需要把grafana-latest.linux-x64-musl.tar.gz、glibc-bin-2.40.tar.gz下载到项目根目录,然后docker build

文件下载地址:
grafana-latest.linux-x64-musl.tar.gz:见上面英文描述
glibc-bin-2.40.tar.gz:https://dl.grafana.com/glibc/glibc-bin-2.40.tar.gz

修改后的Dockfile见:

# syntax=docker/dockerfile:1

# to maintain formatting of multiline commands in vscode, add the following to settings.json:
# "docker.languageserver.formatter.ignoreMultilineInstructions": true

ARG BASE_IMAGE=alpine:3.20
ARG JS_IMAGE=node:22-alpine
ARG JS_PLATFORM=linux/amd64
ARG GO_IMAGE=golang:1.23.5-alpine

# Default to building locally
ARG GO_SRC=go-builder
ARG JS_SRC=js-builder

# Javascript build stage
FROM --platform=${JS_PLATFORM} ${JS_IMAGE} AS js-builder

ENV NODE_OPTIONS=--max_old_space_size=8000

WORKDIR /tmp/grafana

COPY package.json project.json nx.json yarn.lock .yarnrc.yml ./
COPY .yarn .yarn
COPY packages packages
COPY public public
COPY LICENSE ./
COPY conf/defaults.ini ./conf/defaults.ini
COPY e2e e2e

# 配置国内源
RUN sed -i 's#https\?://dl-cdn.alpinelinux.org/alpine#https://mirrors.tuna.tsinghua.edu.cn/alpine#g' /etc/apk/repositories

RUN apk add --no-cache make build-base python3

RUN yarn install --immutable

COPY tsconfig.json eslint.config.js .editorconfig .browserslistrc .prettierrc.js ./
COPY scripts scripts
COPY emails emails

ENV NODE_ENV=production
RUN yarn build

# Golang build stage
FROM ${GO_IMAGE} AS go-builder

ARG COMMIT_SHA=""
ARG BUILD_BRANCH=""
ARG GO_BUILD_TAGS="oss"
ARG WIRE_TAGS="oss"
ARG BINGO="true"

# 配置国内源
RUN sed -i 's#https\?://dl-cdn.alpinelinux.org/alpine#https://mirrors.tuna.tsinghua.edu.cn/alpine#g' /etc/apk/repositories

RUN if grep -i -q alpine /etc/issue; then \
      apk add --no-cache \
          # This is required to allow building on arm64 due to https://github.com/golang/go/issues/22040
          binutils-gold \
          bash \
          # Install build dependencies
          gcc g++ make git; \
    fi

WORKDIR /tmp/grafana

COPY go.* ./
COPY .bingo .bingo

# Include vendored dependencies
COPY pkg/util/xorm pkg/util/xorm
COPY pkg/apiserver pkg/apiserver
COPY pkg/apimachinery pkg/apimachinery
COPY pkg/build pkg/build
COPY pkg/build/wire pkg/build/wire
COPY pkg/promlib pkg/promlib
COPY pkg/storage/unified/resource pkg/storage/unified/resource
COPY pkg/storage/unified/apistore pkg/storage/unified/apistore
COPY pkg/semconv pkg/semconv
COPY pkg/aggregator pkg/aggregator
COPY apps/playlist apps/playlist
COPY apps/investigation apps/investigation
COPY apps/advisor apps/advisor
COPY apps apps
COPY kindsv2 kindsv2
COPY apps/alerting/notifications apps/alerting/notifications
COPY pkg/codegen pkg/codegen
COPY pkg/plugins/codegen pkg/plugins/codegen

# 配置国内源
RUN go env -w GOPROXY=https://goproxy.cn

RUN go mod download
RUN if [[ "$BINGO" = "true" ]]; then \
      go install github.com/bwplotka/bingo@latest && \
      bingo get -v; \
    fi

COPY embed.go Makefile build.go package.json ./
COPY cue.mod cue.mod
COPY kinds kinds
COPY local local
COPY packages/grafana-schema packages/grafana-schema
COPY public/app/plugins public/app/plugins
COPY public/api-merged.json public/api-merged.json
COPY pkg pkg
COPY scripts scripts
COPY conf conf
COPY .github .github

ENV COMMIT_SHA=${COMMIT_SHA}
ENV BUILD_BRANCH=${BUILD_BRANCH}

RUN make build-go GO_BUILD_TAGS=${GO_BUILD_TAGS} WIRE_TAGS=${WIRE_TAGS}

# From-tarball build stage
FROM ${BASE_IMAGE} AS tgz-builder

WORKDIR /tmp/grafana

ARG GRAFANA_TGZ="grafana-latest.linux-x64-musl.tar.gz"

COPY ${GRAFANA_TGZ} /tmp/grafana.tar.gz

# add -v to make tar print every file it extracts
RUN tar x -z -f /tmp/grafana.tar.gz --strip-components=1

# helpers for COPY --from
FROM ${GO_SRC} AS go-src
FROM ${JS_SRC} AS js-src

# Final stage
FROM ${BASE_IMAGE}

LABEL maintainer="Grafana Labs <hello@grafana.com>"

ARG GF_UID="472"
ARG GF_GID="0"

ENV PATH="/usr/share/grafana/bin:$PATH" \
    GF_PATHS_CONFIG="/etc/grafana/grafana.ini" \
    GF_PATHS_DATA="/var/lib/grafana" \
    GF_PATHS_HOME="/usr/share/grafana" \
    GF_PATHS_LOGS="/var/log/grafana" \
    GF_PATHS_PLUGINS="/var/lib/grafana/plugins" \
    GF_PATHS_PROVISIONING="/etc/grafana/provisioning"

WORKDIR $GF_PATHS_HOME

# 配置国内源
RUN sed -i 's#https\?://dl-cdn.alpinelinux.org/alpine#https://mirrors.tuna.tsinghua.edu.cn/alpine#g' /etc/apk/repositories

# Install dependencies
RUN if grep -i -q alpine /etc/issue; then \
      apk add --no-cache ca-certificates bash curl tzdata musl-utils && \
      apk info -vv | sort; \
    elif grep -i -q ubuntu /etc/issue; then \
      DEBIAN_FRONTEND=noninteractive && \
      apt-get update && \
      apt-get install -y ca-certificates curl tzdata musl && \
      apt-get autoremove -y && \
      rm -rf /var/lib/apt/lists/*; \
    else \
      echo 'ERROR: Unsupported base image' && /bin/false; \
    fi

# glibc support for alpine x86_64 only
# docker run --rm --env STDOUT=1 sgerrand/glibc-builder 2.40 /usr/glibc-compat > glibc-bin-2.40.tar.gz
ARG GLIBC_TGZ="glibc-bin-2.40.tar.gz"
# 先將本地文件複製到容器內
COPY ${GLIBC_TGZ} /tmp/${GLIBC_TGZ}

RUN if grep -i -q alpine /etc/issue && [ `arch` = "x86_64" ]; then \
      tar zxf /tmp/${GLIBC_TGZ} -C / \
        usr/glibc-compat/lib/ld-linux-x86-64.so.2 \
        usr/glibc-compat/lib/libc.so.6 \
        usr/glibc-compat/lib/libdl.so.2 \
        usr/glibc-compat/lib/libm.so.6 \
        usr/glibc-compat/lib/libpthread.so.0 \
        usr/glibc-compat/lib/librt.so.1 && \
      mkdir /lib64 && \
      ln -s /usr/glibc-compat/lib/ld-linux-x86-64.so.2 /lib64; \
    fi

COPY --from=go-src /tmp/grafana/conf ./conf

RUN if [ ! $(getent group "$GF_GID") ]; then \
      if grep -i -q alpine /etc/issue; then \
        addgroup -S -g $GF_GID grafana; \
      else \
        addgroup --system --gid $GF_GID grafana; \
      fi; \
    fi && \
    GF_GID_NAME=$(getent group $GF_GID | cut -d':' -f1) && \
    mkdir -p "$GF_PATHS_HOME/.aws" && \
    if grep -i -q alpine /etc/issue; then \
      adduser -S -u $GF_UID -G "$GF_GID_NAME" grafana; \
    else \
      adduser --system --uid $GF_UID --ingroup "$GF_GID_NAME" grafana; \
    fi && \
    mkdir -p "$GF_PATHS_PROVISIONING/datasources" \
             "$GF_PATHS_PROVISIONING/dashboards" \
             "$GF_PATHS_PROVISIONING/notifiers" \
             "$GF_PATHS_PROVISIONING/plugins" \
             "$GF_PATHS_PROVISIONING/access-control" \
             "$GF_PATHS_PROVISIONING/alerting" \
             "$GF_PATHS_LOGS" \
             "$GF_PATHS_PLUGINS" \
             "$GF_PATHS_DATA" && \
    cp conf/sample.ini "$GF_PATHS_CONFIG" && \
    cp conf/ldap.toml /etc/grafana/ldap.toml && \
    chown -R "grafana:$GF_GID_NAME" "$GF_PATHS_DATA" "$GF_PATHS_HOME/.aws" "$GF_PATHS_LOGS" "$GF_PATHS_PLUGINS" "$GF_PATHS_PROVISIONING" && \
    chmod -R 777 "$GF_PATHS_DATA" "$GF_PATHS_HOME/.aws" "$GF_PATHS_LOGS" "$GF_PATHS_PLUGINS" "$GF_PATHS_PROVISIONING"

COPY --from=go-src /tmp/grafana/bin/grafana* /tmp/grafana/bin/*/grafana* ./bin/
COPY --from=js-src /tmp/grafana/public ./public
COPY --from=js-src /tmp/grafana/LICENSE ./

EXPOSE 3000

ARG RUN_SH=./packaging/docker/run.sh

COPY ${RUN_SH} /run.sh

USER "$GF_UID"
ENTRYPOINT [ "/run.sh" ]