Skip to content

Commit cf601b2

Browse files
author
Tibor Vass
committed
hack: update scripts to be go mod compatible
Signed-off-by: Tibor Vass <[email protected]>
1 parent df84e3d commit cf601b2

File tree

11 files changed

+128
-48
lines changed

11 files changed

+128
-48
lines changed

frontend/dockerfile/cmd/dockerfile-frontend/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ FROM --platform=$BUILDPLATFORM tonistiigi/xx:golang@sha256:6f7d999551dd471b58f70
44

55
FROM --platform=$BUILDPLATFORM golang:1.11 AS base
66
COPY --from=xgo / /
7-
WORKDIR /go/src/github.com/moby/buildkit
7+
WORKDIR /src
8+
ENV GOFLAGS=-mod=vendor
89

910
FROM base AS version
1011
ARG CHANNEL
12+
# TODO: PKG should be inferred from go modules
1113
RUN --mount=target=. \
1214
PKG=github.com/moby/buildkit/frontend/dockerfile/cmd/dockerfile-frontend VERSION=$(./frontend/dockerfile/cmd/dockerfile-frontend/hack/detect "$CHANNEL") REVISION=$(git rev-parse HEAD)$(if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi); \
1315
echo "-X main.Version=${VERSION} -X main.Revision=${REVISION} -X main.Package=${PKG}" | tee /tmp/.ldflags; \
@@ -19,6 +21,7 @@ ARG BUILDTAGS=""
1921
ARG TARGETPLATFORM
2022
ENV TARGETPLATFORM=$TARGETPLATFORM
2123
RUN --mount=target=. --mount=type=cache,target=/root/.cache \
24+
--mount=target=/go/pkg/mod,type=cache \
2225
--mount=source=/tmp/.ldflags,target=/tmp/.ldflags,from=version \
2326
CGO_ENABLED=0 go build -o /dockerfile-frontend -ldflags "-d $(cat /tmp/.ldflags)" -tags "$BUILDTAGS netgo static_build osusergo" ./frontend/dockerfile/cmd/dockerfile-frontend && \
2427
file /dockerfile-frontend | grep "statically linked"
@@ -42,4 +45,4 @@ RUN ./check-daily-outdated $CHANNEL $REPO $DATE /out
4245
FROM scratch AS buildid
4346
COPY --from=buildid-check /out/ /
4447

45-
FROM release
48+
FROM release

hack/dockerfiles/test.Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ RUN apk add --no-cache g++ linux-headers
1515
RUN apk add --no-cache git libseccomp-dev make
1616

1717
FROM gobuild-base AS buildkit-base
18-
WORKDIR /go/src/github.com/moby/buildkit
18+
WORKDIR /src
1919
COPY . .
20+
# TODO: PKG should be inferred from go modules
2021
RUN mkdir .tmp; \
2122
PKG=github.com/moby/buildkit VERSION=$(git describe --match 'v[0-9]*' --dirty='.m' --always) REVISION=$(git rev-parse HEAD)$(if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi); \
2223
echo "-X ${PKG}/version.Version=${VERSION} -X ${PKG}/version.Revision=${REVISION} -X ${PKG}/version.Package=${PKG}" | tee .tmp/ldflags
24+
ENV GOFLAGS=-mod=vendor
2325

2426
FROM buildkit-base AS buildctl
2527
ENV CGO_ENABLED=0
@@ -68,7 +70,7 @@ RUN git checkout -q "$CONTAINERD10_VERSION" \
6870
FROM buildkit-base AS buildkitd.oci_only
6971
ENV CGO_ENABLED=1
7072
# mitigate https://github.com/moby/moby/pull/35456
71-
WORKDIR /go/src/github.com/moby/buildkit
73+
WORKDIR /src
7274
RUN go build -installsuffix netgo -ldflags "$(cat .tmp/ldflags) -w -extldflags -static" -tags 'no_containerd_worker seccomp netgo cgo static_build' -o /usr/bin/buildkitd.oci_only ./cmd/buildkitd
7375

7476
FROM buildkit-base AS buildkitd.containerd_only

hack/dockerfiles/test.buildkit.Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ RUN --mount=from=runc-src,src=/usr/src/runc,target=. --mount=target=/root/.cache
6666
file /usr/bin/runc | grep "statically linked"
6767

6868
FROM gobuild-base AS buildkit-base
69-
WORKDIR /go/src/github.com/moby/buildkit
69+
WORKDIR /src
70+
ENV GOFLAGS=-mod=vendor
7071

7172
# scan the version/revision info
7273
FROM buildkit-base AS buildkit-version
74+
# TODO: PKG should be inferred from go modules
7375
RUN --mount=target=. \
7476
PKG=github.com/moby/buildkit VERSION=$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags) REVISION=$(git rev-parse HEAD)$(if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi); \
7577
echo "-X ${PKG}/version.Version=${VERSION} -X ${PKG}/version.Revision=${REVISION} -X ${PKG}/version.Package=${PKG}" | tee /tmp/.ldflags; \
@@ -80,6 +82,7 @@ FROM buildkit-base AS buildctl
8082
ENV CGO_ENABLED=0
8183
ARG TARGETPLATFORM
8284
RUN --mount=target=. --mount=target=/root/.cache,type=cache \
85+
--mount=target=/go/pkg/mod,type=cache \
8386
--mount=source=/tmp/.ldflags,target=/tmp/.ldflags,from=buildkit-version \
8487
set -x; go build -ldflags "$(cat /tmp/.ldflags)" -o /usr/bin/buildctl ./cmd/buildctl && \
8588
file /usr/bin/buildctl && file /usr/bin/buildctl | egrep "statically linked|Mach-O|Windows"
@@ -89,6 +92,7 @@ FROM buildkit-base AS buildkitd
8992
ENV CGO_ENABLED=1
9093
ARG TARGETPLATFORM
9194
RUN --mount=target=. --mount=target=/root/.cache,type=cache \
95+
--mount=target=/go/pkg/mod,type=cache \
9296
--mount=source=/tmp/.ldflags,target=/tmp/.ldflags,from=buildkit-version \
9397
go build -ldflags "$(cat /tmp/.ldflags) -w -extldflags -static" -tags 'osusergo seccomp netgo cgo static_build ' -o /usr/bin/buildkitd ./cmd/buildkitd && \
9498
file /usr/bin/buildkitd | grep "statically linked"

hack/dockerfiles/vendor.Dockerfile

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
FROM golang:1.11-alpine AS vndr
1+
FROM golang:1.11-alpine AS update
22
RUN apk add --no-cache git
3-
# NOTE: hack scripts override VNDR_VERSION to a specific revision
4-
ARG VNDR_VERSION=master
5-
RUN go get -d github.com/LK4D4/vndr \
6-
&& cd /go/src/github.com/LK4D4/vndr \
7-
&& git checkout $VNDR_VERSION \
8-
&& go install ./
9-
WORKDIR /go/src/github.com/moby/buildkit
3+
WORKDIR /src
104
COPY . .
11-
# Remove vendor first to workaround https://github.com/LK4D4/vndr/issues/63.
12-
RUN rm -rf vendor
13-
RUN vndr --verbose --strict
5+
RUN go mod tidy && go mod vendor && rm -rf /go/pkg/mod && ln -s /src /out
6+
7+
FROM update AS validate
8+
RUN ./hack/validate-vendor check
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# syntax = docker/dockerfile:1.0-experimental
2+
FROM golang:1.11-alpine AS vendored
3+
RUN apk add --no-cache git
4+
WORKDIR /src
5+
RUN --mount=target=/src,rw \
6+
--mount=target=/go/pkg/mod,type=cache \
7+
go mod tidy && go mod vendor && \
8+
mkdir /out && cp -r go.mod go.sum vendor /out
9+
10+
FROM scratch AS update
11+
COPY --from=vendored /out /out
12+
13+
FROM vendored AS validate
14+
RUN --mount=target=.,rw \
15+
git add -A && \
16+
rm -rf vendor && \
17+
cp -rf /out/* . && \
18+
./hack/validate-vendor check

hack/test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ case $buildmode in
6262
;;
6363
esac
6464

65-
cacheVolume=$(docker create -v /root/.cache -v /root/.cache/registry alpine)
65+
cacheVolume=$(docker create -v /root/.cache -v /root/.cache/registry -v /go/pkg/mod alpine)
6666

6767
if [ "$TEST_INTEGRATION" == 1 ]; then
6868
docker run --rm -v /tmp --volumes-from=$cacheVolume -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry --privileged $iid go test ${TESTFLAGS:--v} ${TESTPKGS:-./...}
6969
fi
7070

7171

7272
if [ "$TEST_GATEWAY" == 1 ]; then
73-
docker run --rm $iid go build ./frontend/gateway/client
73+
docker run --rm --volumes-from=$cacheVolume $iid go build ./frontend/gateway/client
7474
fi
7575

7676

hack/update-generated-files

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set -eu -o pipefail -x
88
progressFlag=""
99
if [ "$CONTINUOUS_INTEGRATION" == "true" ]; then progressFlag="--progress=plain"; fi
1010

11-
gogo_version=$(awk '$1 == "github.com/gogo/protobuf" { print $2 }' vendor.conf)
11+
gogo_version=$(awk '$1 == "github.com/gogo/protobuf" { print $2 }' go.mod)
1212
case $buildmode in
1313
"buildkit")
1414
output=$(mktemp -d -t buildctl-output.XXXXXXXXXX)

hack/update-vendor

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,44 @@
11
#!/usr/bin/env bash
22

3+
. $(dirname $0)/util
34
set -eu -o pipefail -x
45

5-
iidfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
6-
docker build --build-arg VNDR_VERSION=1fc68ee0c852556a9ed53cbde16247033f104111 --iidfile $iidfile -f ./hack/dockerfiles/vendor.Dockerfile --force-rm .
7-
iid=$(cat $iidfile)
8-
cid=$(docker create $iid noop)
9-
rm -rf ./vendor
10-
docker cp $cid:/go/src/github.com/moby/buildkit/vendor .
11-
docker rm $cid
12-
rm -f $iidfile
6+
: ${CONTINUOUS_INTEGRATION=}
7+
8+
progressFlag=""
9+
if [ "$CONTINUOUS_INTEGRATION" == "true" ]; then progressFlag="--progress=plain"; fi
10+
11+
case $buildmode in
12+
"buildkit")
13+
output=$(mktemp -d -t buildctl-output.XXXXXXXXXX)
14+
buildctl build $progressFlag --frontend=dockerfile.v0 --local context=. --local dockerfile=. \
15+
--frontend-opt target=update \
16+
--frontend-opt filename=./hack/dockerfiles/vendor.buildkit.Dockerfile \
17+
--exporter=local --exporter-opt output=$output
18+
rm -rf ./vendor
19+
cp -R "$output/out/" .
20+
rm -rf $output
21+
;;
22+
*)
23+
iidfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
24+
case $buildmode in
25+
"docker-buildkit")
26+
export DOCKER_BUILDKIT=1
27+
docker build --iidfile $iidfile -f ./hack/dockerfiles/vendor.buildkit.Dockerfile --target update --force-rm .
28+
;;
29+
*)
30+
docker build --iidfile $iidfile -f ./hack/dockerfiles/vendor.Dockerfile --target update --force-rm .
31+
;;
32+
esac
33+
iid=$(cat $iidfile)
34+
cid=$(docker create $iid noop)
35+
rm -rf ./vendor
36+
37+
docker cp $cid:/out/go.mod .
38+
docker cp $cid:/out/go.sum .
39+
docker cp $cid:/out/vendor .
40+
41+
docker rm $cid
42+
rm -f $iidfile
43+
;;
44+
esac

hack/util

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
#!/usr/bin/env sh
22

33
: ${PREFER_BUILDCTL=}
44
: ${PREFER_LEGACY=}
@@ -8,7 +8,7 @@ newerEqualThan() { # $1=minimum wanted version $2=actual-version
88
}
99

1010
buildmode="legacy"
11-
if [ "$PREFER_BUILDCTL" == "1" ]; then
11+
if [ "$PREFER_BUILDCTL" = "1" ]; then
1212
buildmode="buildkit";
1313
else
1414
serverVersion=$(docker info --format '{{.ServerVersion}}')
@@ -18,4 +18,4 @@ else
1818
[ "$DOCKER_BUILDKIT" = "1" ]); then
1919
buildmode="docker-buildkit";
2020
fi
21-
fi
21+
fi

hack/validate-generated-files

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ if [ "$CONTINUOUS_INTEGRATION" == "true" ]; then progressFlag="--progress=plain"
88
case ${1:-} in
99
'')
1010
. $(dirname $0)/util
11-
gogo_version=$(awk '$1 == "github.com/gogo/protobuf" { print $2 }' vendor.conf)
11+
gogo_version=$(awk '$1 == "github.com/gogo/protobuf" { print $2 }' go.mod)
1212
case $buildmode in
1313
"buildkit")
14-
buildctl build $progressFlag --frontend=dockerfile.v0 --local context=. --local dockerfile=. --frontend-opt build-arg:GOGO_VERSION=$gogo_version --frontend-opt filename=./hack/dockerfiles/generated-files.buildkit.Dockerfile
14+
buildctl build $progressFlag --frontend=dockerfile.v0 --local context=. --local dockerfile=. --frontend-opt build-arg:GOGO_VERSION=$gogo_version --frontend-opt target=validate --frontend-opt filename=./hack/dockerfiles/generated-files.buildkit.Dockerfile
1515
;;
1616
"docker-buildkit")
1717
export DOCKER_BUILDKIT=1

0 commit comments

Comments
 (0)