Skip to content
Snippets Groups Projects
Commit 813f0d2d authored by sh0rez's avatar sh0rez Committed by Cyril Tovena
Browse files

feat(docker): multi-arch Dockerfile (#668)

Adds an entirely new Dockerfile to the repository root which is capable of:

- building promtail and loki from the same image
- based on `scratch`, so that the final image can be executed on every supported
  GOARCH

Please note that this Dockerfile should always be built using
BuildKit (`buildctl` or `DOCKER_BUILDKIT=1` in recent versions) for maximum
performance, as BuildKit's DAG allows for smart skipping of uneeded stages.

These changes were proposed in #659
parent 909adf62
No related branches found
No related tags found
No related merge requests found
# These may be overwritten by --build-arg to build promtail or debug images
ARG APP=loki
ARG TYPE=production
# ca-certificates
FROM alpine:3.9 as ssl
RUN apk add --update --no-cache ca-certificates
# use grafana/loki-build-image to compile binaries
FROM grafana/loki-build-image as golang
ARG GOARCH="amd64"
COPY . /go/src/github.com/grafana/loki
WORKDIR /go/src/github.com/grafana/loki
RUN touch loki-build-image/.uptodate &&\
mkdir /build
# production image
FROM golang as builder-production
ARG APP
RUN make BUILD_IN_CONTAINER=false cmd/${APP}/${APP} &&\
mv cmd/${APP}/${APP} /build/${APP}
FROM scratch as production
COPY --from=ssl /etc/ssl /etc/ssl
COPY --from=builder-production /build/${APP} /usr/bin/${APP}
# debug image (only arm64 supported, because of go-delve/delve#118)
FROM golang as builder-debug
ARG APP
RUN go get github.com/go-delve/delve/cmd/dlv &&\
make BUILD_IN_CONTAINER=false cmd/promtail/promtail-debug &&\
mv cmd/${APP}/${APP}-debug /build/app-debug &&\
mv cmd/${APP}/dlv /build/dlv
FROM alpine:3.9 as debug
COPY --from=ssl /etc/ssl /etc/ssl
COPY --from=builder-debug /build/app-debug /usr/bin/app-debug
COPY --from=builder-debug /build/dlv /usr/bin/dlv
RUN apk add --no-cache libc6-compat
EXPOSE 40000
ENTRYPOINT ["/usr/bin/dlv", "--listen=:40000", "--headless=true", "--api-version=2", "exec", "/usr/bin/app-debug", "--"]
# final image with configuration
FROM ${TYPE} as promtail
COPY cmd/promtail/promtail-local-config.yaml cmd/promtail/promtail-docker-config.yaml /etc/promtail/
ENTRYPOINT ["/usr/bin/promtail"]
FROM ${TYPE} as loki
COPY cmd/loki/loki-local-config.yaml /etc/loki/local-config.yaml
EXPOSE 80
ENTRYPOINT ["/usr/bin/loki"]
FROM ${APP}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment