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

[Loki]: Cleanup dockerfile #1949

Merged
merged 8 commits into from
Apr 23, 2020
13 changes: 7 additions & 6 deletions cmd/loki/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ WORKDIR /src/loki
RUN make clean && (if [ "${TOUCH_PROTOS}" ]; then make touch-protos; fi) && make BUILD_IN_CONTAINER=false loki

FROM alpine:3.9
RUN apk add --update --no-cache ca-certificates libcap \
Copy link
Member

Choose a reason for hiding this comment

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

I think there's a tradeoff here of caching vs layer reduction and I'm inclined to think that caching is a bit more preferrable although I'm biased by building this regularly. That being said, I don't think it's a huge deal either way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

sry deleted my last message, didn't read closely enough

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I'd like to leave this as is, same as the changes below for 2 reasons:

  1. We spent a stupid amount of time trying to test this worked after adding this change and I don't have time to redo this.
  2. I prefer the separate run steps below I think it's easier to read and understand what the steps are doing/for

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you elaborate on what you spent a lot of time testing? Adding a new package should be as simple as adding an apk add --no-cache <pkgname>.

Copy link
Collaborator

Choose a reason for hiding this comment

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

All the cap stuff was new and we tried several combinations of where to install libcap as well as removing it and where to remove it to keep the resulting image size as small as possible as well as make sure it still works.

&& rm -rf /var/cache/apk/*

RUN apk add --no-cache ca-certificates libcap

COPY --from=build /src/loki/cmd/loki/loki /usr/bin/loki
COPY cmd/loki/loki-local-config.yaml /etc/loki/local-config.yaml

RUN setcap cap_net_bind_service=+ep /usr/bin/loki

RUN apk del --no-cache libcap && rm -rf /var/cache/apk/*

RUN addgroup -g 1000 -S loki && \
adduser -u 1000 -S loki -G loki
RUN addgroup -g 10001 -S loki && \
adduser -u 10001 -S loki -G loki
RUN mkdir -p /loki && \
chown -R loki:loki /etc/loki /loki

# See https://github.com/grafana/loki/issues/1928
RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf

USER loki
EXPOSE 3100
ENTRYPOINT [ "/usr/bin/loki" ]
Expand Down
16 changes: 14 additions & 2 deletions cmd/loki/Dockerfile.cross
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,21 @@ WORKDIR /src/loki
RUN make clean && GOARCH=$(cat /goarch) GOARM=$(cat /goarm) make BUILD_IN_CONTAINER=false loki

FROM alpine:3.9
RUN apk add --update --no-cache ca-certificates
Copy link
Member

Choose a reason for hiding this comment

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

I think this should remain earlier in the file for caching benefits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved back to the top


RUN apk add --no-cache ca-certificates

COPY --from=build /src/loki/cmd/loki/loki /usr/bin/loki
COPY cmd/loki/loki-local-config.yaml /etc/loki/local-config.yaml
EXPOSE 80

RUN addgroup -g 10001 -S loki && \
adduser -u 10001 -S loki -G loki
RUN mkdir -p /loki && \
chown -R loki:loki /etc/loki /loki

# See https://github.com/grafana/loki/issues/1928
RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf

USER loki
EXPOSE 3100
ENTRYPOINT [ "/usr/bin/loki" ]
CMD ["-config.file=/etc/loki/local-config.yaml"]