Skip to content
Open
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
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ endif

DOCKER_TOOLS = docker run \
--rm \
-v $(shell bash -c "$(GOCC) env GOCACHE || (mkdir -p /tmp/go-cache; echo /tmp/go-cache)"):/tmp/build/.cache \
-v $(shell bash -c "$(GOCC) env GOMODCACHE || (mkdir -p /tmp/go-modcache; echo /tmp/go-modcache)"):/tmp/build/.modcache \
-v $(shell bash -c "mkdir -p /tmp/go-build-cache; echo /tmp/go-build-cache"):/root/.cache/go-build \
-v $(shell bash -c "mkdir -p /tmp/go-lint-cache; echo /tmp/go-lint-cache"):/root/.cache/golangci-lint \
-v $$(pwd):/build lnd-tools

Expand Down
25 changes: 13 additions & 12 deletions tools/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
FROM golang:1.24.6
FROM golang:1.24.6-alpine

RUN apt-get update && apt-get install -y git
ENV GOCACHE=/tmp/build/.cache
ENV GOMODCACHE=/tmp/build/.modcache
ENV GOFLAGS="-buildvcs=false"

COPY . /tmp/tools
RUN apk update && apk add --no-cache git

Choose a reason for hiding this comment

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

medium

While this change correctly switches to apk for the Alpine base image, there's a small improvement to further reduce the image size. The apk update command creates a cache in /var/cache/apk/. In your later RUN command on line 17, you remove this cache with rm -rf /var/cache/apk/*.

However, because the removal happens in a different RUN instruction (and thus a different Docker layer), the cache files from this layer will still be part of the image, even though they are marked as deleted in a later layer.

To avoid this and make the image even smaller, you should perform the cleanup in the same RUN instruction. After applying the suggestion below, you can remove the rm -rf /var/cache/apk/* from the RUN command on lines 11-18.

RUN apk update && apk add --no-cache git && rm -rf /var/cache/apk/*

RUN cd /tmp \
&& mkdir -p /tmp/build/.cache \
&& mkdir -p /tmp/build/.modcache \
&& cd /tmp/tools \
&& CGO_ENABLED=0 go install -trimpath github.com/golangci/golangci-lint/cmd/golangci-lint \
WORKDIR /tmp/tools

COPY . ./

RUN CGO_ENABLED=0 go install -trimpath github.com/golangci/golangci-lint/cmd/golangci-lint \
&& CGO_ENABLED=0 golangci-lint custom \
&& mv ./custom-gcl /usr/local/bin/custom-gcl \
&& chmod -R 777 /tmp/build/ \
&& git config --global --add safe.directory /build
&& git config --global --add safe.directory /build \
&& rm -rf /go/pkg/mod \
&& rm -rf /root/.cache/go-build \
&& rm -rf /var/cache/apk/* \
&& rm -rf /tmp/*

WORKDIR /build
Loading