Skip to content

Commit

Permalink
add sharing=locked
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxPeal committed Jun 16, 2022
1 parent bd31010 commit 70832b2
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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=<password> -e VF_STATION_URL=http://192.168.0.1 vodafone-station-exporter
Expand All @@ -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
Expand Down

0 comments on commit 70832b2

Please sign in to comment.