Skip to content

chore(ci): Add dockerfmt CI check #17120

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
---
name: lint-jsonnet
name: lint
on: [pull_request]
# pull_request:
# paths: "production/**"

jobs:
check-mixin:
name: Check mixin jsonnet files
lint-jsonnet:
name: Lint jsonnet files
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: setup go
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.24.2'
- name: setup jsonnet
- name: Setup jsonnet
run: |
go install github.com/google/go-jsonnet/cmd/[email protected]
go install github.com/google/go-jsonnet/cmd/[email protected]
go install github.com/google/go-jsonnet/cmd/[email protected]
go install github.com/monitoring-mixins/mixtool/cmd/mixtool@16dc166166d91e93475b86b9355a4faed2400c18
go install github.com/jsonnet-bundler/jsonnet-bundler/cmd/[email protected]
- name: run linting
- name: Run jsonnet linter
run: make BUILD_IN_CONTAINER=false lint-jsonnet
- name: check compiled mixin has been updated
- name: Check mixin
run: |
make BUILD_IN_CONTAINER=false loki-mixin-check



lint-dockerfile:
name: Lint Docker files
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.24.2'
- name: Setup dockerfmt
run: |
go install github.com/reteps/[email protected]
- name: Run dockerfmt
run: make BUILD_IN_CONTAINER=false fmt-dockerfile
- name: Check drift
run: |
git diff
git diff-index --quiet HEAD --
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -698,17 +698,21 @@ lint-jsonnet:
exit $$RESULT

fmt-jsonnet:
@find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \
xargs -n 1 -- jsonnetfmt -i
@find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | xargs -n 1 -- jsonnetfmt -i

fmt-proto:
fmt-dockerfile:
ifeq ($(BUILD_IN_CONTAINER),true)
$(run_in_container)
else
echo '$(PROTO_DEFS)' | \
xargs -n 1 -- buf format -w
@find . -name 'vendor' -prune -o -name 'Dockerfile*' -print | xargs -n 1 -- dockerfmt -w
endif

fmt-proto:
ifeq ($(BUILD_IN_CONTAINER),true)
$(run_in_container)
else
@echo '$(PROTO_DEFS)' | xargs -n 1 -- buf format -w
endif

lint-scripts:
# Ignore https://github.com/koalaman/shellcheck/wiki/SC2312
Expand Down
2 changes: 1 addition & 1 deletion clients/cmd/docker-driver/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ COPY --from=temp /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=build /src/loki/clients/cmd/docker-driver/docker-driver /bin/docker-driver

WORKDIR /bin/
ENTRYPOINT [ "/bin/docker-driver" ]
ENTRYPOINT ["/bin/docker-driver"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missing newline at the end of file

2 changes: 1 addition & 1 deletion clients/cmd/fluent-bit/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ COPY clients/cmd/fluent-bit/fluent-bit.conf /fluent-bit/etc/fluent-bit.conf

EXPOSE 2020

CMD ["/fluent-bit/bin/fluent-bit", "-e","/fluent-bit/bin/out_grafana_loki.so", "-c", "/fluent-bit/etc/fluent-bit.conf"]
CMD ["/fluent-bit/bin/fluent-bit", "-e", "/fluent-bit/bin/out_grafana_loki.so", "-c", "/fluent-bit/etc/fluent-bit.conf"]
2 changes: 1 addition & 1 deletion clients/cmd/fluentd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ COPY clients/cmd/fluentd/docker/conf/loki.conf /fluentd/etc/loki.conf

USER root
RUN sed -i '$i'' @include loki.conf' /fluentd/etc/fluent.conf
USER fluent
USER fluent
20 changes: 10 additions & 10 deletions clients/cmd/logstash/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
FROM logstash:8.17.4

USER logstash
ENV PATH /usr/share/logstash/vendor/jruby/bin:/usr/share/logstash/vendor/bundle/jruby/2.5.0/bin:/usr/share/logstash/jdk/bin:$PATH
ENV LOGSTASH_PATH /usr/share/logstash
ENV GEM_PATH /usr/share/logstash/vendor/bundle/jruby/2.5.0
ENV GEM_HOME /usr/share/logstash/vendor/bundle/jruby/2.5.0
ENV PATH=/usr/share/logstash/vendor/jruby/bin:/usr/share/logstash/vendor/bundle/jruby/2.5.0/bin:/usr/share/logstash/jdk/bin:$PATH
ENV LOGSTASH_PATH=/usr/share/logstash
ENV GEM_PATH=/usr/share/logstash/vendor/bundle/jruby/2.5.0
ENV GEM_HOME=/usr/share/logstash/vendor/bundle/jruby/2.5.0

RUN gem install bundler:2.3.6

COPY --chown=logstash:logstash ./clients/cmd/logstash/ /home/logstash/
WORKDIR /home/logstash/

# don't run 'bundle update'. It causes a transitive dependency error
RUN bundle config set --local path /usr/share/logstash/vendor/bundle && \
bundle install && \
bundle exec rake vendor && \
bundle exec rspec
RUN bundle config set --local path /usr/share/logstash/vendor/bundle \
&& bundle install \
&& bundle exec rake vendor \
&& bundle exec rspec

RUN cat logstash-output-loki.gemspec | grep s.version | awk '{print $3}' | cut -d "'" -f 2 > VERSION
RUN cat logstash-output-loki.gemspec | grep s.version | awk '{print $3}' | cut -d "'" -f 2 >VERSION

RUN gem build logstash-output-loki.gemspec && \
PLUGIN_VERSION=$(cat VERSION); /usr/share/logstash/bin/logstash-plugin install logstash-output-loki-${PLUGIN_VERSION}.gem

EXPOSE 5044
EXPOSE 5044
8 changes: 4 additions & 4 deletions clients/cmd/promtail/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ RUN make clean && make BUILD_IN_CONTAINER=false PROMTAIL_JOURNAL_ENABLED=true IM
FROM public.ecr.aws/ubuntu/ubuntu:noble
# tzdata required for the timestamp stage to work
# Install dependencies needed at runtime.
RUN apt-get update \
&& apt-get install -qy libsystemd-dev tzdata ca-certificates \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN apt-get update \
&& apt-get install -qy libsystemd-dev tzdata ca-certificates \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY --from=build /src/loki/clients/cmd/promtail/promtail /usr/bin/promtail
COPY clients/cmd/promtail/promtail-docker-config.yaml /etc/promtail/config.yml
ENTRYPOINT ["/usr/bin/promtail"]
CMD ["-config.file=/etc/promtail/config.yml"]
CMD ["-config.file=/etc/promtail/config.yml"]
8 changes: 4 additions & 4 deletions clients/cmd/promtail/Dockerfile.arm32
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ RUN make clean && make BUILD_IN_CONTAINER=false PROMTAIL_JOURNAL_ENABLED=true pr
# Promtail requires debian or ubuntu as the base image to support systemd journal reading
FROM public.ecr.aws/ubuntu/ubuntu:noble
# tzdata required for the timestamp stage to work
RUN apt-get update && \
apt-get install -qy tzdata ca-certificates wget libsystemd-dev && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN apt-get update \
&& apt-get install -qy tzdata ca-certificates wget libsystemd-dev \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY --from=build /src/loki/clients/cmd/promtail/promtail /usr/bin/promtail
COPY clients/cmd/promtail/promtail-local-config.yaml /etc/promtail/local-config.yaml
COPY clients/cmd/promtail/promtail-docker-config.yaml /etc/promtail/config.yml
Expand All @@ -25,4 +25,4 @@ COPY clients/cmd/promtail/promtail-docker-config.yaml /etc/promtail/config.yml
RUN sh -c '[ ! -f /lib/ld-linux-armhf.so.3 ] && echo RE-LINKING LD-LINUX-ARMHF.SO.3 && ln -s /lib/ld-linux.so.3 /lib/ld-linux-armhf.so.3'

ENTRYPOINT ["/usr/bin/promtail"]
CMD ["-config.file=/etc/promtail/config.yml"]
CMD ["-config.file=/etc/promtail/config.yml"]
12 changes: 6 additions & 6 deletions clients/cmd/promtail/Dockerfile.cross
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ ARG GO_VERSION=1.24
# This file is intended to be called from the root like so:
# docker build -t grafana/promtail -f clients/cmd/promtail/Dockerfile .
FROM golang:${GO_VERSION}-alpine as goenv
RUN go env GOARCH > /goarch && \
go env GOARM > /goarm
RUN go env GOARCH >/goarch \
&& go env GOARM >/goarm

FROM --platform=linux/amd64 $BUILD_IMAGE as build
COPY --from=goenv /goarch /goarm /
Expand All @@ -16,11 +16,11 @@ RUN make clean && GOARCH=$(cat /goarch) GOARM=$(cat /goarm) make BUILD_IN_CONTAI
# Promtail requires debian or ubuntu as the base image to support systemd journal reading
FROM public.ecr.aws/ubuntu/ubuntu:noble
# tzdata required for the timestamp stage to work
RUN apt-get update && \
apt-get install -qy tzdata ca-certificates wget libsystemd-dev && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN apt-get update \
&& apt-get install -qy tzdata ca-certificates wget libsystemd-dev \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY --from=build /src/loki/clients/cmd/promtail/promtail /usr/bin/promtail
COPY clients/cmd/promtail/promtail-local-config.yaml /etc/promtail/local-config.yaml
COPY clients/cmd/promtail/promtail-docker-config.yaml /etc/promtail/config.yml
ENTRYPOINT ["/usr/bin/promtail"]
CMD ["-config.file=/etc/promtail/config.yml"]
CMD ["-config.file=/etc/promtail/config.yml"]
14 changes: 7 additions & 7 deletions clients/cmd/promtail/Dockerfile.debug
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ WORKDIR /src/loki
RUN make clean && make BUILD_IN_CONTAINER=false PROMTAIL_JOURNAL_ENABLED=true promtail-debug


FROM alpine:3.21.3
RUN apk add --update --no-cache ca-certificates tzdata
COPY --from=build /src/loki/clients/cmd/promtail/promtail-debug /usr/bin/promtail-debug
COPY --from=build /usr/bin/dlv /usr/bin/dlv
COPY clients/cmd/promtail/promtail-local-config.yaml /etc/promtail/local-config.yaml
COPY clients/cmd/promtail/promtail-docker-config.yaml /etc/promtail/config.yml
FROM alpine:3.21.3
RUN apk add --update --no-cache ca-certificates tzdata
COPY --from=build /src/loki/clients/cmd/promtail/promtail-debug /usr/bin/promtail-debug
COPY --from=build /usr/bin/dlv /usr/bin/dlv
COPY clients/cmd/promtail/promtail-local-config.yaml /etc/promtail/local-config.yaml
COPY clients/cmd/promtail/promtail-docker-config.yaml /etc/promtail/config.yml

# Expose 40000 for delve
EXPOSE 40000
Expand All @@ -26,4 +26,4 @@ RUN apk add --no-cache libc6-compat
# Pass flags to the program you are debugging using --, for example:`
# dlv exec ./hello -- server --config conf/config.toml`
ENTRYPOINT ["/usr/bin/dlv", "--listen=:40000", "--headless=true", "--continue", "--accept-multiclient", "--api-version=2", "exec", "/usr/bin/promtail-debug", "--"]
CMD ["-config.file=/etc/promtail/config.yml"]
CMD ["-config.file=/etc/promtail/config.yml"]
4 changes: 2 additions & 2 deletions cmd/logcli/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN make clean && make BUILD_IN_CONTAINER=false IMAGE_TAG=${IMAGE_TAG} logcli
FROM gcr.io/distroless/static:debug

COPY --from=build /src/loki/cmd/logcli/logcli /usr/bin/logcli
SHELL [ "/busybox/sh", "-c" ]
SHELL ["/busybox/sh", "-c"]
RUN ln -s /busybox/sh /bin/sh

ENTRYPOINT [ "/usr/bin/logcli" ]
ENTRYPOINT ["/usr/bin/logcli"]
4 changes: 2 additions & 2 deletions cmd/logql-analyzer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN make clean && CGO_ENABLED=0 go build ./cmd/logql-analyzer/
FROM gcr.io/distroless/static:debug

COPY --from=build /src/loki/logql-analyzer /usr/bin/logql-analyzer
SHELL [ "/busybox/sh", "-c" ]
SHELL ["/busybox/sh", "-c"]
RUN ln -s /busybox/sh /bin/sh

ENTRYPOINT [ "/usr/bin/logql-analyzer" ]
ENTRYPOINT ["/usr/bin/logql-analyzer"]
6 changes: 3 additions & 3 deletions cmd/loki-canary-boringcrypto/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ ARG IMAGE_TAG

COPY . /src/loki
WORKDIR /src/loki
RUN go env GOARCH > /goarch
RUN go env GOARCH >/goarch
RUN make clean && make GOARCH=$(cat /goarch) BUILD_IN_CONTAINER=true GOEXPERIMENT=boringcrypto IMAGE_TAG=${IMAGE_TAG} loki-canary-boringcrypto

FROM gcr.io/distroless/base-nossl:debug
COPY --from=build /src/loki/cmd/loki-canary-boringcrypto/loki-canary-boringcrypto /usr/bin/loki-canary
SHELL [ "/busybox/sh", "-c" ]
SHELL ["/busybox/sh", "-c"]
RUN ln -s /busybox/sh /bin/sh
ENTRYPOINT [ "/usr/bin/loki-canary" ]
ENTRYPOINT ["/usr/bin/loki-canary"]
4 changes: 2 additions & 2 deletions cmd/loki-canary/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ RUN make clean && make BUILD_IN_CONTAINER=false IMAGE_TAG=${IMAGE_TAG} loki-cana
FROM gcr.io/distroless/static:debug

COPY --from=build /src/loki/cmd/loki-canary/loki-canary /usr/bin/loki-canary
SHELL [ "/busybox/sh", "-c" ]
SHELL ["/busybox/sh", "-c"]
RUN ln -s /busybox/sh /bin/sh
ENTRYPOINT [ "/usr/bin/loki-canary" ]
ENTRYPOINT ["/usr/bin/loki-canary"]
8 changes: 4 additions & 4 deletions cmd/loki-canary/Dockerfile.cross
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ ARG GO_VERSION=1.24
# This file is intended to be called from the root like so:
# docker build -t grafana/promtail -f cmd/promtail/Dockerfile .
FROM golang:${GO_VERSION} AS goenv
RUN go env GOARCH > /goarch && \
go env GOARM > /goarm
RUN go env GOARCH >/goarch \
&& go env GOARM >/goarm

FROM $BUILD_IMAGE as build
COPY --from=goenv /goarch /goarm /
Expand All @@ -15,6 +15,6 @@ RUN make clean && GOARCH=$(cat /goarch) GOARM=$(cat /goarm) make BUILD_IN_CONTAI

FROM gcr.io/distroless/static:debug
COPY --from=build /src/loki/cmd/loki-canary/loki-canary /usr/bin/loki-canary
SHELL [ "/busybox/sh", "-c" ]
SHELL ["/busybox/sh", "-c"]
RUN ln -s /busybox/sh /bin/sh
ENTRYPOINT [ "/usr/bin/loki-canary" ]
ENTRYPOINT ["/usr/bin/loki-canary"]
18 changes: 9 additions & 9 deletions cmd/loki/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ FROM gcr.io/distroless/static:debug
COPY --from=build /src/loki/cmd/loki/loki /usr/bin/loki
COPY cmd/loki/loki-docker-config.yaml /etc/loki/local-config.yaml

SHELL [ "/busybox/sh", "-c" ]
SHELL ["/busybox/sh", "-c"]

RUN addgroup -g 10001 -S loki && \
adduser -u 10001 -S loki -G loki
RUN mkdir -p /loki/rules && \
mkdir -p /loki/rules-temp && \
chown -R loki:loki /etc/loki /loki && \
ln -s /busybox/sh /bin/sh
RUN addgroup -g 10001 -S loki \
&& adduser -u 10001 -S loki -G loki
RUN mkdir -p /loki/rules \
&& mkdir -p /loki/rules-temp \
&& chown -R loki:loki /etc/loki /loki \
&& ln -s /busybox/sh /bin/sh
USER 10001
EXPOSE 3100
ENTRYPOINT [ "/usr/bin/loki" ]
CMD ["-config.file=/etc/loki/local-config.yaml"]
ENTRYPOINT ["/usr/bin/loki"]
CMD [ "-config.file=/etc/loki/local-config.yaml" ]
20 changes: 10 additions & 10 deletions cmd/loki/Dockerfile.cross
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ ARG GO_VERSION=1.24
# This file is intended to be called from the root like so:
# docker build -t grafana/loki -f cmd/loki/Dockerfile .
FROM golang:${GO_VERSION} AS goenv
RUN go env GOARCH > /goarch && \
go env GOARM > /goarm
RUN go env GOARCH >/goarch \
&& go env GOARM >/goarm

COPY . /src/loki
WORKDIR /src/loki
Expand All @@ -15,15 +15,15 @@ FROM gcr.io/distroless/static:debug
COPY --from=goenv /src/loki/cmd/loki/loki /usr/bin/loki
COPY cmd/loki/loki-local-config.yaml /etc/loki/local-config.yaml

SHELL [ "/busybox/sh", "-c" ]
SHELL ["/busybox/sh", "-c"]

RUN addgroup -g 10001 -S loki && \
adduser -u 10001 -S loki -G loki
RUN mkdir -p /loki && \
chown -R loki:loki /etc/loki /loki && \
ln -s /busybox/sh /bin/sh
RUN addgroup -g 10001 -S loki \
&& adduser -u 10001 -S loki -G loki
RUN mkdir -p /loki \
&& chown -R loki:loki /etc/loki /loki \
&& ln -s /busybox/sh /bin/sh

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