-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove vendor dir #1085
Remove vendor dir #1085
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1085 +/- ##
==========================================
+ Coverage 52.60% 52.62% +0.02%
==========================================
Files 107 107
Lines 9389 9389
==========================================
+ Hits 4939 4941 +2
+ Misses 3523 3521 -2
Partials 927 927 see 2 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Curiously, the |
Is the hash calc OS/ARCH-dependent? |
Completed a review pass. While the comments I left are more of the question/nit variety, I'm left feeling like I'd like to see some proof of concept of this before I'm comfortable merging it. |
Looks as though it is, based on the docs. So for our case, we would have a version of the cache for each OS.
That's understandable, and I'm happy to prove this out through another project. It should be expected however that the first run of each build action would fail to find a cache, since all of them ran simultaneously with no previous existing cache (setup-go did not use a cache by default until v4). On subsequent re-runs however, all three build-${OS} actions succeeded in using the previous cache here. |
0ab0da8
to
0c03c57
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes make sense and look good to me. Holding on any labels to give others a shot to review
That's what I was looking for. Thanks! |
/approve |
Re: os-specific cache. Here's the suggested setup for go modules, which seems to account for that difference: https://github.com/actions/cache/blob/main/examples.md#go---modules (I'm afraid to click the diff link, so not sure if this is what you already have) |
I understand your fears 😄 I'll just paste the addition here. It's essentially the same except that it only targets the vendor dir in this case: ...
- id: cache-vendor
uses: actions/cache@v3
env:
cache-name: cache-vendor-dir
with:
path: ./vendor
key: ${{ runner.os }}-go-vendor-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-vendor
- if: ${{ steps.cache-vendor.outputs.cache-hit != 'true' }}
name: Run make vendor
run: make vendor
... We can add more paths to the caching in the future if you think it's worthwhile. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like our job restores & saves cache 2 times: as part of actions/setup-go
and as part of actions/cache
:
Do we need both?
Documentation for actions/setup-go
says that it has a built-in functionality for caching and restoring go modules based on go.sum
. And it seems to be enabled by default in v4.
I haven't looked into this properly, but I assume that once cache is restored go mod vendor
just copies everything from restored cache into vendor dir. Should give us aproximately the same results as caching & restoring vendor directory.
Is there any reason why we can not rely on cache from actions/setup-go
?
Makefile
Outdated
@@ -35,18 +35,20 @@ endif | |||
.PHONY: all | |||
all: clean test build | |||
|
|||
$(CMDS): | |||
$(CMDS): vendor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why we are adding the vendor dependency here? Which seems to eventually run go mod vendor
to fill/create the vendor directory (which is .gitignored)? That seems like quite a slowdown; especailly for those who run git clean -fdxq
a lot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The builds for this repo are all dependent on the presence of the vendor directory and will fail without it. Running make vendor
again when the vendor
dir is already there is essentially a no-op since it won't need to re-download them. From my testing go mod vendor
will not re-download the entire folder every time; it will first grab them from ~/go/pkg/mod
which is a very fast operation. The presence of this folder is also a requirement for the downstream repos, since everything the project is built from needs to exist in the repo, or at least that's my understanding of why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue this is still vendoring; this PR just gets rid of the directory and the build step has to recreate it each time...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess my point is, if everything is already in the GOPATH, why are we copying it over via go mod vendor
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Todd. I think there is no benefit in copying into vendor since we have local cache for modules.
there is essentially a no-op since it won't need to re-download them
It is a no-op on network, but there will still be some IO on a disk. I think it is not critical, but would be nice to get rid of it if it is not a big effort.
The builds for this repo are all dependent on the presence of the vendor directory and will fail without it.
I think this is because our Makefile
has GOFLAGS="-mod=vendor"
which is forcing go build
to use vendor dir.
Try running this in master:
sed -i 's/GO := GOFLAGS="-mod=vendor" go/GO := go/g' ./Makefile
rm -r ./vendor
go mod download
make build
Even go mod download
might not be necessary. I think go build
without -mod=vendor
will be to download modules (if not present) and build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you both here and would prefer to not have the vendor/
dir at all. But I do want to ask the following, not as a challenge but a genuine question as somebody still not terribly familiar with up/down-streaming processes: If we change the build process for the upstream repo to stop using vendor/
, will that not make the downstream cherry-picking process more complicated? Since the downstream repo must use the vendor/
dir for the build (somebody correct me if this is wrong), then aren't we beginning to create a significant divergence between the up and downstream repos? Or is this not what you're recommending?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also not super familiar with downstreaming, but I'm happy to look into it together on next week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking at other upstream+downstream repos I've realized that having differences in build process is really not an issue at all. I've addressed both your concerns and removed all requirements on the vendor/
directory in this PR. Obviously these changes won't go to the downstream repo but it should make the process of downstreaming easier without the directory here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The vendor directory doesn't exist in the downstream staging directory. But there is a root-level vendor.
My concern here is that all this does is get rid of the vendor directory; building recreates the directory. It should be possible to do this without recreating the vendor directory. |
0c03c57
to
3e8b55c
Compare
I'm glad you brought this up; my understanding was that |
The goal of this task was to remove the vendor directory and recreate it from cache when the github actions are run. I think that reworking the build process to remove the need for the vendor directory would be out of scope of the tasks intended purpose; primarily we just wanted to reduce the number of merge conflicts we get from downstreaming with the vendor folder inside source control. I personally don't see any issue with frequent re-runs of That being said though if there was something else you were getting at here that I misunderstood please let me know! |
No, that's basically it. If we want to get rid of vendoring, there's more to do. |
Makefile
Outdated
@@ -35,18 +35,20 @@ endif | |||
.PHONY: all | |||
all: clean test build | |||
|
|||
$(CMDS): | |||
$(CMDS): vendor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Todd. I think there is no benefit in copying into vendor since we have local cache for modules.
there is essentially a no-op since it won't need to re-download them
It is a no-op on network, but there will still be some IO on a disk. I think it is not critical, but would be nice to get rid of it if it is not a big effort.
The builds for this repo are all dependent on the presence of the vendor directory and will fail without it.
I think this is because our Makefile
has GOFLAGS="-mod=vendor"
which is forcing go build
to use vendor dir.
Try running this in master:
sed -i 's/GO := GOFLAGS="-mod=vendor" go/GO := go/g' ./Makefile
rm -r ./vendor
go mod download
make build
Even go mod download
might not be necessary. I think go build
without -mod=vendor
will be to download modules (if not present) and build.
.github/workflows/goreleaser.yaml
Outdated
- id: cache-vendor | ||
uses: actions/cache@v3 | ||
env: | ||
cache-name: cache-vendor-dir | ||
with: | ||
path: ./vendor | ||
key: go-vendor-${{ hashFiles('go.sum') }} | ||
enableCrossOsArchive: true | ||
- if: ${{ steps.cache-vendor.outputs.cache-hit != 'true' }} | ||
name: Run make vendor | ||
run: make vendor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like leftovers in this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - thanks for noticing!
3e8b55c
to
36d1bd1
Compare
Removes the vendor directory from source control and attempts to cache the vendor dir when github actions are run. Also removes a couple of Dockerfiles which are no longer used and relied on the vendor directory. Signed-off-by: dtfranz <dfranz@redhat.com>
36d1bd1
to
69d4237
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No more vendor
!
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dtfranz, everettraven, grokspawn, tmshort The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Description of the change:
Removes the vendor directory from source control and removes the need for it during builds so we don't have to keep re-populating it. Also removes a couple of unused dockerfiles which relied on the vendor directory's presence.
Upgrades to
actions/setup-go@v4
which caches thego mod
packages by default.Motivation for the change:
Makes the process of downstreaming easier and speeds up builds since we don't have to re-download the vendor directory and run setup-go fresh on each run.