refactor: docker build BuildContext field (#1914)
The old Container input parameter was not flexible enough Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
73d5f78294
commit
f0ca0abc40
|
@ -53,11 +53,11 @@ type Container interface {
|
||||||
|
|
||||||
// NewDockerBuildExecutorInput the input for the NewDockerBuildExecutor function
|
// NewDockerBuildExecutorInput the input for the NewDockerBuildExecutor function
|
||||||
type NewDockerBuildExecutorInput struct {
|
type NewDockerBuildExecutorInput struct {
|
||||||
ContextDir string
|
ContextDir string
|
||||||
Dockerfile string
|
Dockerfile string
|
||||||
Container Container
|
BuildContext io.Reader
|
||||||
ImageTag string
|
ImageTag string
|
||||||
Platform string
|
Platform string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDockerPullExecutorInput the input for the NewDockerPullExecutor function
|
// NewDockerPullExecutorInput the input for the NewDockerPullExecutor function
|
||||||
|
|
|
@ -48,8 +48,8 @@ func NewDockerBuildExecutor(input NewDockerBuildExecutorInput) common.Executor {
|
||||||
Dockerfile: input.Dockerfile,
|
Dockerfile: input.Dockerfile,
|
||||||
}
|
}
|
||||||
var buildContext io.ReadCloser
|
var buildContext io.ReadCloser
|
||||||
if input.Container != nil {
|
if input.BuildContext != nil {
|
||||||
buildContext, err = input.Container.GetContainerArchive(ctx, input.ContextDir+"/.")
|
buildContext = io.NopCloser(input.BuildContext)
|
||||||
} else {
|
} else {
|
||||||
buildContext, err = createBuildContext(ctx, input.ContextDir, input.Dockerfile)
|
buildContext, err = createBuildContext(ctx, input.ContextDir, input.Dockerfile)
|
||||||
}
|
}
|
||||||
|
|
|
@ -257,16 +257,20 @@ func execAsDocker(ctx context.Context, step actionStep, actionName string, based
|
||||||
|
|
||||||
if !correctArchExists || rc.Config.ForceRebuild {
|
if !correctArchExists || rc.Config.ForceRebuild {
|
||||||
logger.Debugf("image '%s' for architecture '%s' will be built from context '%s", image, rc.Config.ContainerArchitecture, contextDir)
|
logger.Debugf("image '%s' for architecture '%s' will be built from context '%s", image, rc.Config.ContainerArchitecture, contextDir)
|
||||||
var actionContainer container.Container
|
var buildContext io.ReadCloser
|
||||||
if localAction {
|
if localAction {
|
||||||
actionContainer = rc.JobContainer
|
buildContext, err = rc.JobContainer.GetContainerArchive(ctx, contextDir+"/.")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer buildContext.Close()
|
||||||
}
|
}
|
||||||
prepImage = container.NewDockerBuildExecutor(container.NewDockerBuildExecutorInput{
|
prepImage = container.NewDockerBuildExecutor(container.NewDockerBuildExecutorInput{
|
||||||
ContextDir: contextDir,
|
ContextDir: contextDir,
|
||||||
Dockerfile: fileName,
|
Dockerfile: fileName,
|
||||||
ImageTag: image,
|
ImageTag: image,
|
||||||
Container: actionContainer,
|
BuildContext: buildContext,
|
||||||
Platform: rc.Config.ContainerArchitecture,
|
Platform: rc.Config.ContainerArchitecture,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
logger.Debugf("image '%s' for architecture '%s' already exists", image, rc.Config.ContainerArchitecture)
|
logger.Debugf("image '%s' for architecture '%s' already exists", image, rc.Config.ContainerArchitecture)
|
||||||
|
|
Loading…
Reference in New Issue