Skip to content

Commit

Permalink
New flag for non-standard docker socker location
Browse files Browse the repository at this point in the history
Signed-off-by: Matej Vasek <mvasek@redhat.com>
  • Loading branch information
matejvasek committed Feb 15, 2021
1 parent abc54fa commit 87a9460
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 270 deletions.
4 changes: 4 additions & 0 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ type BuildOptions struct {
// built atop.
RunImage string

// TODO doc
DockerHost string

// Used to determine a run-image mirror if Run Image is empty.
// Used in combination with Builder metadata to determine to the the 'best' mirror.
// 'best' is defined as:
Expand Down Expand Up @@ -284,6 +287,7 @@ func (c *Client) Build(ctx context.Context, opts BuildOptions) error {
RunImage: runImageName,
ClearCache: opts.ClearCache,
Publish: opts.Publish,
DockerHost: opts.DockerHost,
UseCreator: false,
TrustBuilder: opts.TrustBuilder,
LifecycleImage: ephemeralBuilder.Name(),
Expand Down
46 changes: 13 additions & 33 deletions internal/build/lifecycle_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (l *LifecycleExecution) Run(ctx context.Context, phaseFactoryCreator PhaseF
}

l.logger.Info(style.Step("ANALYZING"))
if err := l.Analyze(ctx, l.opts.Image.String(), l.opts.Network, l.opts.Publish, l.opts.ClearCache, buildCache, phaseFactory); err != nil {
if err := l.Analyze(ctx, l.opts.Image.String(), l.opts.Network, l.opts.Publish, l.opts.DockerHost, l.opts.ClearCache, buildCache, phaseFactory); err != nil {
return err
}

Expand All @@ -150,22 +150,10 @@ func (l *LifecycleExecution) Run(ctx context.Context, phaseFactoryCreator PhaseF
}

l.logger.Info(style.Step("EXPORTING"))
return l.Export(ctx, l.opts.Image.String(), l.opts.RunImage, l.opts.Publish, l.opts.Network, buildCache, launchCache, l.opts.AdditionalTags, phaseFactory)
return l.Export(ctx, l.opts.Image.String(), l.opts.RunImage, l.opts.Publish, l.opts.DockerHost, l.opts.Network, buildCache, launchCache, l.opts.AdditionalTags, phaseFactory)
}

return l.Create(
ctx,
l.opts.Publish,
l.opts.ClearCache,
l.opts.RunImage,
l.opts.Image.String(),
l.opts.Network,
buildCache,
launchCache,
l.opts.AdditionalTags,
l.opts.Volumes,
phaseFactory,
)
return l.Create(ctx, l.opts.Publish, l.opts.DockerHost, l.opts.ClearCache, l.opts.RunImage, l.opts.Image.String(), l.opts.Network, buildCache, launchCache, l.opts.AdditionalTags, l.opts.Volumes, phaseFactory)
}

func (l *LifecycleExecution) Cleanup() error {
Expand All @@ -179,15 +167,7 @@ func (l *LifecycleExecution) Cleanup() error {
return reterr
}

func (l *LifecycleExecution) Create(
ctx context.Context,
publish, clearCache bool,
runImage, repoName, networkMode string,
buildCache, launchCache Cache,
additionalTags []string,
volumes []string,
phaseFactory PhaseFactory,
) error {
func (l *LifecycleExecution) Create(ctx context.Context, publish bool, dockerHost string, clearCache bool, runImage, repoName, networkMode string, buildCache, launchCache Cache, additionalTags, volumes []string, phaseFactory PhaseFactory) error {
flags := addTags([]string{
"-cache-dir", l.mountPaths.cacheDir(),
"-run-image", runImage,
Expand Down Expand Up @@ -228,7 +208,7 @@ func (l *LifecycleExecution) Create(
opts = append(opts, WithRoot(), WithRegistryAccess(authConfig))
} else {
opts = append(opts,
WithDaemonAccess(),
WithDaemonAccess(dockerHost),
WithFlags("-daemon", "-launch-cache", l.mountPaths.launchCacheDir()),
WithBinds(fmt.Sprintf("%s:%s", launchCache.Name(), l.mountPaths.launchCacheDir())),
)
Expand Down Expand Up @@ -292,16 +272,16 @@ func (l *LifecycleExecution) Restore(ctx context.Context, networkMode string, bu
return restore.Run(ctx)
}

func (l *LifecycleExecution) Analyze(ctx context.Context, repoName, networkMode string, publish, clearCache bool, cache Cache, phaseFactory PhaseFactory) error {
analyze, err := l.newAnalyze(repoName, networkMode, publish, clearCache, cache, phaseFactory)
func (l *LifecycleExecution) Analyze(ctx context.Context, repoName, networkMode string, publish bool, dockerHost string, clearCache bool, cache Cache, phaseFactory PhaseFactory) error {
analyze, err := l.newAnalyze(repoName, networkMode, publish, dockerHost, clearCache, cache, phaseFactory)
if err != nil {
return err
}
defer analyze.Cleanup()
return analyze.Run(ctx)
}

func (l *LifecycleExecution) newAnalyze(repoName, networkMode string, publish, clearCache bool, buildCache Cache, phaseFactory PhaseFactory) (RunnerCleaner, error) {
func (l *LifecycleExecution) newAnalyze(repoName, networkMode string, publish bool, dockerHost string, clearCache bool, buildCache Cache, phaseFactory PhaseFactory) (RunnerCleaner, error) {
args := []string{
repoName,
}
Expand Down Expand Up @@ -355,7 +335,7 @@ func (l *LifecycleExecution) newAnalyze(repoName, networkMode string, publish, c
fmt.Sprintf("%s=%d", builder.EnvUID, l.opts.Builder.UID()),
fmt.Sprintf("%s=%d", builder.EnvGID, l.opts.Builder.GID()),
),
WithDaemonAccess(),
WithDaemonAccess(dockerHost),
WithArgs(
l.withLogLevel(
prependArg(
Expand Down Expand Up @@ -396,7 +376,7 @@ func determineDefaultProcessType(platformAPI *api.Version, providedValue string)
return providedValue
}

func (l *LifecycleExecution) newExport(repoName, runImage string, publish bool, networkMode string, buildCache, launchCache Cache, additionalTags []string, phaseFactory PhaseFactory) (RunnerCleaner, error) {
func (l *LifecycleExecution) newExport(repoName, runImage string, publish bool, dockerHost, networkMode string, buildCache, launchCache Cache, additionalTags []string, phaseFactory PhaseFactory) (RunnerCleaner, error) {
flags := []string{
"-cache-dir", l.mountPaths.cacheDir(),
"-stack", l.mountPaths.stackPath(),
Expand Down Expand Up @@ -447,7 +427,7 @@ func (l *LifecycleExecution) newExport(repoName, runImage string, publish bool,
} else {
opts = append(
opts,
WithDaemonAccess(),
WithDaemonAccess(dockerHost),
WithFlags("-daemon", "-launch-cache", l.mountPaths.launchCacheDir()),
WithBinds(fmt.Sprintf("%s:%s", launchCache.Name(), l.mountPaths.launchCacheDir())),
)
Expand All @@ -456,8 +436,8 @@ func (l *LifecycleExecution) newExport(repoName, runImage string, publish bool,
return phaseFactory.New(NewPhaseConfigProvider("exporter", l, opts...)), nil
}

func (l *LifecycleExecution) Export(ctx context.Context, repoName string, runImage string, publish bool, networkMode string, buildCache, launchCache Cache, additionalTags []string, phaseFactory PhaseFactory) error {
export, err := l.newExport(repoName, runImage, publish, networkMode, buildCache, launchCache, additionalTags, phaseFactory)
func (l *LifecycleExecution) Export(ctx context.Context, repoName, runImage string, publish bool, dockerHost, networkMode string, buildCache, launchCache Cache, additionalTags []string, phaseFactory PhaseFactory) error {
export, err := l.newExport(repoName, runImage, publish, dockerHost, networkMode, buildCache, launchCache, additionalTags, phaseFactory)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 87a9460

Please sign in to comment.