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:
ChristopherHX 2023-08-08 17:02:11 +02:00 committed by GitHub
parent 73d5f78294
commit f0ca0abc40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 14 deletions

View File

@ -55,7 +55,7 @@ type Container interface {
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
} }

View File

@ -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)
} }

View File

@ -257,15 +257,19 @@ 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 {