Skip to content

Commit

Permalink
feat: allow to set gitImage via config file #2027 (#2486)
Browse files Browse the repository at this point in the history
This adds support to set the `gitImage` via an entry in the config file:

```yaml
global:
   git_image: my/gitimage:v1.2.3
```
  • Loading branch information
hojerst committed Dec 29, 2022
1 parent 6d239f0 commit fd943e8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
7 changes: 6 additions & 1 deletion buildcontext/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
type gitResolver struct {
cleanCollection *cleanup.Collection

gitImage string
projectCache *synccache.SyncCache // "gitURL#gitRef" -> *resolvedGitProject
buildFileCache *synccache.SyncCache // project ref -> local path
gitLookup *GitLookup
Expand Down Expand Up @@ -193,8 +194,12 @@ func (gr *gitResolver) resolveGitProject(ctx context.Context, gwClient gwclient.
}

gitState := llb.Git(gitURL, gitRef, gitOpts...)
gitImage := gr.gitImage
if gitImage == "" {
gitImage = defaultGitImage
}
opImg := pllb.Image(
defaultGitImage, llb.MarkImageInternal, llb.ResolveModePreferLocal,
gitImage, llb.MarkImageInternal, llb.ResolveModePreferLocal,
llb.Platform(platr.LLBNative()))

// Get git hash.
Expand Down
6 changes: 6 additions & 0 deletions buildcontext/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@ type Resolver struct {

// NewResolver returns a new NewResolver.
func NewResolver(cleanCollection *cleanup.Collection, gitLookup *GitLookup, console conslogging.ConsoleLogger, featureFlagOverrides string) *Resolver {
return NewResolverCustomGit(cleanCollection, gitLookup, console, featureFlagOverrides, "")
}

// NewResolverCustomGit returns a new Resolver instance with a custom gitImage.
func NewResolverCustomGit(cleanCollection *cleanup.Collection, gitLookup *GitLookup, console conslogging.ConsoleLogger, featureFlagOverrides string, gitImage string) *Resolver {
return &Resolver{
gr: &gitResolver{
gitImage: gitImage,
cleanCollection: cleanCollection,
projectCache: synccache.New(),
buildFileCache: synccache.New(),
Expand Down
3 changes: 2 additions & 1 deletion builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type Opt struct {
InternalSecretStore *secretprovider.MutableMapStore
InteractiveDebugging bool
InteractiveDebuggingDebugLevelLogging bool
GitImage string
}

// BuildOpt is a collection of build options.
Expand Down Expand Up @@ -132,7 +133,7 @@ func NewBuilder(ctx context.Context, opt Opt) (*Builder, error) {
opt: opt,
resolver: nil, // initialized below
}
b.resolver = buildcontext.NewResolver(opt.CleanCollection, opt.GitLookup, opt.Console, opt.FeatureFlagOverrides)
b.resolver = buildcontext.NewResolverCustomGit(opt.CleanCollection, opt.GitLookup, opt.Console, opt.FeatureFlagOverrides, opt.GitImage)
return b, nil
}

Expand Down
1 change: 1 addition & 0 deletions cmd/earthly/build_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ func (app *earthlyApp) actionBuildImp(cliCtx *cli.Context, flagArgs, nonFlagArgs
InternalSecretStore: internalSecretStore,
InteractiveDebugging: app.interactiveDebugging,
InteractiveDebuggingDebugLevelLogging: app.debug,
GitImage: app.cfg.Global.GitImage,
}
b, err := builder.NewBuilder(cliCtx.Context, builderOpts)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type GlobalConfig struct {
IPTables string `yaml:"ip_tables" help:"Which iptables binary to use. Valid values are iptables-legacy or iptables-nft. Bypasses any autodetection."`
DisableLogSharing bool `yaml:"disable_log_sharing" help:"Disable cloud log sharing when logged in with an Earthly account, see https://ci.earthly.dev for details."`
SecretProvider string `yaml:"secret_provider" help:"Command to execute to retrieve secret."`
GitImage string `yaml:"git_image" help:"Image used to resolve git repositories"`

// Obsolete.
CachePath string `yaml:"cache_path" help:" *Deprecated* The path to keep Earthly's cache."`
Expand Down

0 comments on commit fd943e8

Please sign in to comment.