Skip to content

Conversation

@tiborvass
Copy link
Collaborator

@tiborvass tiborvass commented Jan 26, 2019

What I did:

$ go get -u github.com/tiborvass/gomod
$ GO111MODULE=on gomod init
$ GO111MODULE=on go mod tidy     # no need for forked gomod anymore
$ GO111MODULE=on go mod vendor

Because of golang/go#25556 I created https://github.com/tiborvass/gomod to convert vendor.conf to go.mod. It's only needed for conversion. Regular go mod can be used once go.mod/go.sum are created.

Related docker/cli#1642 :
Right now, the docker cli dependency is that of Tonis's fork which reduces the dependencies. I submitted a hopefully mergeable version upstream so that we no longer need to depend on a fork.
Until then, the reason we need to update the docker cli dependency is because go mod tidy errors out on logrus's Sirupsen/sirupsen mismatch, due to the docker cli fork not containing the import path update for logrus.

The PR got merged, I removed the fork!

Since go mod uses $GOPATH/pkg/mod to store its cache, I'm mounting it as type=cache in a new
vendor.buildkit.Dockerfile. Legacy vendor.Dockerfile redownloads everything every time like vndr used to.

In order for go build to honor the vendor/ folder when go modules are enabled, I had to add an -mod vendor argument.

I verified that the validate-vendor script works, but please verify as well.

It would be good to try updating some dependencies as a way to test this.

TODO:

  • Change scripts to run go build with -mod vendor
  • Update vendor-related scripts
  • Verify go1.11 vs go1.12 in go.mod

go.mod Outdated
@@ -0,0 +1,83 @@
module github.com/moby/buildkit

go 1.12
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TODO: verify that this doesn't cause issues with go1.11

@AkihiroSuda
Copy link
Member

Related docker/cli#1642

Could you be more specific?

Are we also going to migrate moby/moby (and containerd? runc?) to go mod soon?

@tonistiigi
Copy link
Member

@tiborvass Also need to update the vendor validation/update scripts. And CI does not pass.

build flag -mod=vendor only valid when using modules

Signed-off-by: Tibor Vass <tibor@docker.com>
@tiborvass
Copy link
Collaborator Author

@AkihiroSuda Updated the description. Ideally I'd like to convert everything to go mod, but I wanted to start with buildkit to see how it goes.

@tiborvass tiborvass force-pushed the gomod branch 5 times, most recently from 4527e79 to b12a6f4 Compare January 28, 2019 20:58
github.com/docker/go-events v0.0.0-20170721190031-9461782956ad // indirect
github.com/docker/go-units v0.3.1 // indirect
github.com/docker/libnetwork v0.0.0-20180913200009-36d3bed0e9f4
github.com/godbus/dbus v4.1.0+incompatible // indirect
Copy link
Collaborator Author

@tiborvass tiborvass Jan 28, 2019

Choose a reason for hiding this comment

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

The +incompatible just means that even though the repo is using semver v2+, it doesn't have a go.mod, so go is precautious and treats it as v0 (aka things can break when it updates).

@tiborvass
Copy link
Collaborator Author

The go version in go.mod is simply metadata and is not yet used to inform any decisions. Here is the commit golang/go@16962fa

iidfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
docker build --build-arg VNDR_VERSION=1fc68ee0c852556a9ed53cbde16247033f104111 --iidfile $iidfile -f ./hack/dockerfiles/vendor.Dockerfile --force-rm .
dockerfile=vendor.Dockerfile
if [ "$buildmode" == "docker-buildkit" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

still support buildkit mode even if it runs docker

RUN --mount=target=. --mount=type=cache,target=/root/.cache \
--mount=source=/tmp/.ldflags,target=/tmp/.ldflags,from=version \
CGO_ENABLED=0 go build -o /dockerfile-frontend -ldflags "-d $(cat /tmp/.ldflags)" -tags "$BUILDTAGS netgo static_build osusergo" ./frontend/dockerfile/cmd/dockerfile-frontend && \
CGO_ENABLED=0 GO111MODULE=on go build -mod vendor -o /dockerfile-frontend -ldflags "-d $(cat /tmp/.ldflags)" -tags "$BUILDTAGS netgo static_build osusergo" ./frontend/dockerfile/cmd/dockerfile-frontend && \
Copy link
Member

Choose a reason for hiding this comment

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

Will this change in go1.12 ? If the dockerfiles don't use go mod anyway atm we don't need -mod vendor. We could just add comments with a reminder that we need to enable it when go mod is enabled.

@tiborvass tiborvass force-pushed the gomod branch 3 times, most recently from ed84a89 to 9c3d761 Compare January 29, 2019 17:07
@@ -1,3 +1,5 @@
# syntax = docker/dockerfile:1.0-experimental
Copy link
Member

Choose a reason for hiding this comment

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

?

FROM buildkit-base AS buildctl
ENV CGO_ENABLED=0
RUN go build -ldflags "$(cat .tmp/ldflags) -d" -o /usr/bin/buildctl ./cmd/buildctl
RUN go build -mod vendor -ldflags "$(cat .tmp/ldflags) -d" -o /usr/bin/buildctl ./cmd/buildctl
Copy link
Member

Choose a reason for hiding this comment

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

I think I prefer GOFLAGS=-mod=vendor although that is easier to break.

COPY --from=vendored /out /out

FROM vendored AS validate
RUN --mount=target=.,rw \
Copy link
Member

Choose a reason for hiding this comment

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

rm -rf vendor

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

$ touch vendor/toto
$ ./hack/validate-vendor

It should fail in that case. If I add rm -rf vendor it will not fail.

Copy link
Member

Choose a reason for hiding this comment

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

removing the file should cause the status --porcelain to fail then.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It doesn't because status --porcelain is run after we "cleaned" vendor.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fine, you win. It doesn't validate correctly if I commit vendor/toto. I need to add git add -A like in generated-files' dockerfile to cover my less useful usecase.

--frontend-opt target=update \
--frontend-opt filename=./hack/dockerfiles/vendor.buildkit.Dockerfile \
--exporter=local --exporter-opt output=$output
cp -R "$output/out/" .
Copy link
Member

Choose a reason for hiding this comment

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

rm -rf vendor

# Remove vendor first to workaround https://github.com/LK4D4/vndr/issues/63.
RUN rm -rf vendor
RUN vndr --verbose --strict
RUN go mod tidy && go mod vendor && rm -rf /go/pkg/mod
Copy link
Member

Choose a reason for hiding this comment

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

How does this work? Doesn't hack script expect files in /out ?

@tiborvass tiborvass force-pushed the gomod branch 4 times, most recently from a34695d to e3f0da2 Compare January 30, 2019 01:37
@tiborvass tiborvass changed the title [WIP] Migrate to go mod Migrate to go mod Jan 30, 2019
@tonistiigi
Copy link
Member

ping @AkihiroSuda

@tiborvass
Copy link
Collaborator Author

I'm exploring an issue when upgrading fsutil with go get -u github.com/tonistiigi/fsutil on top of this PR: go.mod removes indirect dependencies that are still in vendor/, even after go mod vendor.

@tiborvass
Copy link
Collaborator Author

From go help modules:

Indirect requirements are
automatically removed from the go.mod file once they are implied by other
direct requirements. Indirect requirements only arise when using modules
that fail to state some of their own dependencies or when explicitly
upgrading a module's dependencies ahead of its own stated requirements.

@tonistiigi
Copy link
Member

Found some issues where validate vendor passes with a dirty go.sum file.

@tiborvass
Copy link
Collaborator Author

@tonistiigi fixed!

Tibor Vass added 2 commits January 31, 2019 22:44
  go get -u github.com/tiborvass/gomod
  GO111MODULE=on gomod init
  GO111MODULE=on go mod tidy
  GO111MODULE=on go mod vendor

Signed-off-by: Tibor Vass <tibor@docker.com>
Signed-off-by: Tibor Vass <tibor@docker.com>
@tiborvass
Copy link
Collaborator Author

Updated to upstream docker/cli

@tonistiigi tonistiigi merged commit ac64f29 into moby:master Feb 1, 2019
@tonistiigi tonistiigi mentioned this pull request Feb 1, 2019
thaJeztah added a commit to thaJeztah/cli that referenced this pull request Dec 4, 2025
The AuthConfig type was forked from the docker/docker API types in commit
27b2797 to reduce the dependency on the
docker API types in BuildKit and Buildx (see [buildkit#800]). Now that
the API is a separate module with minimal dependencies, this should no longer
be a big concern, so this patch un-forks the type.

[buildkit#800]: moby/buildkit#800

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants