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
15 changes: 8 additions & 7 deletions cmd/loki/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ 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 10001 -S loki && \
adduser -u 10001 -S loki -G loki
RUN mkdir -p /data && \
chown -R loki:loki /etc/loki /data

RUN addgroup -g 1000 -S loki && \
adduser -u 1000 -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
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 /data && \
chown -R loki:loki /etc/loki /data

# 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"]
4 changes: 2 additions & 2 deletions cmd/loki/loki-local-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ schema_config:

storage_config:
boltdb:
directory: /loki/index
directory: /data/loki/index
Copy link
Member

Choose a reason for hiding this comment

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

nice, thanks for the consistency!

Copy link
Contributor

Choose a reason for hiding this comment

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

@slim-bean you mentioned something about this ? I think you're good with that change right ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

this used to be /tmp a long time ago and got changed to /loki

/loki is annoying because many operating systems don't easily let you create this directory

I don't know if /data makes this any easier? my mac is dead at the moment, can you create /data (or does it exist) on mac?

Copy link
Contributor

Choose a reason for hiding this comment

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

No so it's the same :)

 sudo mkdir /data
Password:
mkdir: /data: Read-only file system

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would be favor of moving this back to /tmp if we were going to change it all

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cyriltovena Did you run that inside the OSX docker hypervisor? By default that directory isn't shared with the host (see https://docs.docker.com/docker-for-mac/#file-sharing)

So do you want the consistency with the helm image or /tmp in this file?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We are talking about running locally on mac, not in docker at all. This is useful for us for testing/debugging etc, just run the processes and use the loki-local-config.yaml.

This broke however when it was changed to /loki some time ago because you can't make this directory on a mac (nor /data)

#1833 changed this apparently, however /loki is also kind of a poor choice, it's both unusable on mac and not linux FHS compliant.

Given the sort of dual use of this file as both the config file for a container and also running outside of containers I'm not sure the best path forward here to be honest

I'm inclined to say just leave it as is for now and we should tackle this in a separate issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I've removed the config file change


filesystem:
directory: /loki/chunks
directory: /data/loki/chunks

limits_config:
enforce_metric_name: false
Expand Down