From 70832b289aa89908b278eb845ceda5dd9c1fdb48 Mon Sep 17 00:00:00 2001 From: MaxPeal <30347730+MaxPeal@users.noreply.github.com> Date: Thu, 16 Jun 2022 02:32:41 +0200 Subject: [PATCH] add sharing=locked --- Dockerfile | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index a88e37b..4417b43 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,13 @@ +# syntax=docker/dockerfile:1.3 + +# testing with https://github.com/moby/buildkit/issues/1673#issuecomment-698361687 +# docker rm -f buildx_buildkit_localbuild0 ; docker buildx create --use --name localbuild && docker buildx inspect localbuild --bootstrap && docker rm -f buildx_buildkit_localbuild0 && docker run --privileged -d --name=buildx_buildkit_localbuild0 -v=/dev/shm/buildkit:/var/lib/buildkit moby/buildkit:buildx-stable-1 +## docker buildx create --use --name localbuild +## docker buildx inspect localbuild --bootstrap +# recreate buildkit with host path +## docker rm -f buildx_buildkit_localbuild0 +## docker run --privileged -d --name=buildx_buildkit_localbuild0 -v=/tmp/buildkit:/var/lib/buildkit moby/buildkit:buildx-stable-1 + # build it with: docker build . -t vodafone-station-exporter # run it with: docker run --rm -d --restart unless-stopped -p 9420:9420 -e VF_STATION_PASS= -e VF_STATION_URL=http://192.168.0.1 vodafone-station-exporter @@ -6,13 +16,23 @@ FROM golang:1.18-alpine as builder ADD . /go/vodafone-station-exporter WORKDIR /go/vodafone-station-exporter + +RUN apk add file # + # -ldflags="-s -w" for Shrinking Go executables, https://itnext.io/shrinking-go-executable-9e9c17b47a41 -RUN --mount=type=cache,id=gomod,target=/go/pkg/mod \ - --mount=type=cache,id=gobuild,target=/root/.cache/go-build \ - go mod download -RUN --mount=type=cache,id=gomod,target=/go/pkg/mod \ - --mount=type=cache,id=gobuild,target=/root/.cache/go-build \ - go build -ldflags="-s -w" +RUN --mount=type=cache,id=gomod,sharing=locked,mode=0775,target=/go/pkg/mod \ + --mount=type=cache,id=gobuild,sharing=locked,mode=0775,target=/root/.cache/go-build \ + go env GOCACHE && \ + du -hd0 $(go env GOCACHE) && \ + go mod download && \ + du -hd0 $(go env GOCACHE) +RUN --mount=type=cache,id=gomod,sharing=locked,mode=0775,target=/go/pkg/mod \ + --mount=type=cache,id=gobuild,sharing=locked,mode=0775,target=/root/.cache/go-build \ + go env GOCACHE && \ + du -hd0 $(go env GOCACHE) && \ + GODEBUG=gocachehash=1 go build -v -ldflags="-s -w" && \ + du -hd0 $(go env GOCACHE) + # go build -ldflags="-s -w" FROM alpine:3.16 WORKDIR /app