Skip to content

Commit

Permalink
feat(docker): multi-arch Dockerfile (#668)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sh0rez authored and cyriltovena committed Jul 8, 2019
1 parent 909adf6 commit 813f0d2
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 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 comments on commit 813f0d2

Please sign in to comment.