Skip to content
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

Makefile: Enable reusing local Go module cache during compile #20261

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

palhotel
Copy link

Enable Reusing Local Go Modules During Compile by Mapping the Cache Directory to Build Container

This commit adds support for leveraging the local go mod cache when building Harbor components. By mounting the host's Go module cache directory, as specified by go env GOMODCACHE, into the build container at /go/pkg/mod, subsequent builds can benefit from cached dependencies. This leads to faster build times due to reduced network activity and redundant downloads.

Updated a file: Makefile in the root directory of the Harbor source code.

  • Add a parameter GOLOCALMODCACHE=$(shell go env GOMODCACHE).
  • Modify the compile commands, such as:
@$(DOCKERCMD) run --rm -v $(GOLOCALMODCACHE):/go/pkg/mod -v $(BUILDPATH):$(GOBUILDPATHINCONTAINER) -w $(GOBUILDPATH_CORE) $(GOBUILDIMAGE) $(GOIMAGEBUILD_CORE) -o $(GOBUILDPATHINCONTAINER)/$(GOBUILDMAKEPATH_CORE)/$(CORE_BINARYNAME)

Copy link

codecov bot commented Apr 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.18%. Comparing base (b7b8847) to head (949631c).
Report is 140 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #20261      +/-   ##
==========================================
+ Coverage   67.56%   69.18%   +1.61%     
==========================================
  Files         991      793     -198     
  Lines      109181    98973   -10208     
  Branches     2719        0    -2719     
==========================================
- Hits        73768    68471    -5297     
+ Misses      31449    26793    -4656     
+ Partials     3964     3709     -255     
Flag Coverage Δ
unittests 69.18% <ø> (+1.61%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 313 files with indirect coverage changes

@MinerYang
Copy link
Contributor

Hi @palhotel,

Thanks for your contributions!
We prefer to add this as an option and do not modified current behavior.

Best,
Miner

@wy65701436
Copy link
Contributor

While this could offer benefits for developers, from a build perspective, we prioritize ensuring the binary is built from scratch to mitigate potential issues stemming from cached builds.

So, I propose providing developers with an option to accelerate the build speed if desired.

@palhotel
Copy link
Author

Thanks for the feedback, @MinerYang @wy65701436. I've added the option as suggested. Could you please review it again?

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.

None yet

5 participants