Merge pull request #594 from tonistiigi/override-copy
dockerfile: allow overriding copy imagedocker-18.09
commit
94b009b27e
|
@ -40,6 +40,7 @@ const (
|
|||
keyImageResolveMode = "image-resolve-mode"
|
||||
keyGlobalAddHosts = "add-hosts"
|
||||
keyForceNetwork = "force-network-mode"
|
||||
keyOverrideCopyImage = "override-copy-image" // remove after CopyOp implemented
|
||||
)
|
||||
|
||||
var httpPrefix = regexp.MustCompile("^https?://")
|
||||
|
@ -136,7 +137,11 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {
|
|||
return nil, errors.Errorf("failed to read downloaded context")
|
||||
}
|
||||
if isArchive(dt) {
|
||||
unpack := llb.Image(dockerfile2llb.CopyImage, dockerfile2llb.WithInternalName("helper image for file operations")).
|
||||
copyImage := opts[keyOverrideCopyImage]
|
||||
if copyImage == "" {
|
||||
copyImage = dockerfile2llb.DefaultCopyImage
|
||||
}
|
||||
unpack := llb.Image(copyImage, dockerfile2llb.WithInternalName("helper image for file operations")).
|
||||
Run(llb.Shlex("copy --unpack /src/context /out/"), llb.ReadonlyRootFS(), dockerfile2llb.WithInternalName("extracting build context"))
|
||||
unpack.AddMount("/src", httpContext, llb.Readonly)
|
||||
src = unpack.AddMount("/out", llb.Scratch())
|
||||
|
@ -252,20 +257,21 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {
|
|||
func(i int, tp *specs.Platform) {
|
||||
eg.Go(func() error {
|
||||
st, img, err := dockerfile2llb.Dockerfile2LLB(ctx, dtDockerfile, dockerfile2llb.ConvertOpt{
|
||||
Target: opts[keyTarget],
|
||||
MetaResolver: c,
|
||||
BuildArgs: filter(opts, buildArgPrefix),
|
||||
Labels: filter(opts, labelPrefix),
|
||||
SessionID: c.BuildOpts().SessionID,
|
||||
BuildContext: buildContext,
|
||||
Excludes: excludes,
|
||||
IgnoreCache: ignoreCache,
|
||||
TargetPlatform: tp,
|
||||
BuildPlatforms: buildPlatforms,
|
||||
ImageResolveMode: resolveMode,
|
||||
PrefixPlatform: exportMap,
|
||||
ExtraHosts: extraHosts,
|
||||
ForceNetMode: defaultNetMode,
|
||||
Target: opts[keyTarget],
|
||||
MetaResolver: c,
|
||||
BuildArgs: filter(opts, buildArgPrefix),
|
||||
Labels: filter(opts, labelPrefix),
|
||||
SessionID: c.BuildOpts().SessionID,
|
||||
BuildContext: buildContext,
|
||||
Excludes: excludes,
|
||||
IgnoreCache: ignoreCache,
|
||||
TargetPlatform: tp,
|
||||
BuildPlatforms: buildPlatforms,
|
||||
ImageResolveMode: resolveMode,
|
||||
PrefixPlatform: exportMap,
|
||||
ExtraHosts: extraHosts,
|
||||
ForceNetMode: defaultNetMode,
|
||||
OverrideCopyImage: opts[keyOverrideCopyImage],
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -33,7 +33,7 @@ const (
|
|||
localNameContext = "context"
|
||||
historyComment = "buildkit.dockerfile.v0"
|
||||
|
||||
CopyImage = "tonistiigi/copy:v0.1.3@sha256:e57a3b4d6240f55bac26b655d2cfb751f8b9412d6f7bb1f787e946391fb4b21b"
|
||||
DefaultCopyImage = "tonistiigi/copy:v0.1.3@sha256:e57a3b4d6240f55bac26b655d2cfb751f8b9412d6f7bb1f787e946391fb4b21b"
|
||||
)
|
||||
|
||||
type ConvertOpt struct {
|
||||
|
@ -48,13 +48,14 @@ type ConvertOpt struct {
|
|||
// Empty slice means ignore cache for all stages. Nil doesn't disable cache.
|
||||
IgnoreCache []string
|
||||
// CacheIDNamespace scopes the IDs for different cache mounts
|
||||
CacheIDNamespace string
|
||||
ImageResolveMode llb.ResolveMode
|
||||
TargetPlatform *specs.Platform
|
||||
BuildPlatforms []specs.Platform
|
||||
PrefixPlatform bool
|
||||
ExtraHosts []llb.HostIP
|
||||
ForceNetMode pb.NetMode
|
||||
CacheIDNamespace string
|
||||
ImageResolveMode llb.ResolveMode
|
||||
TargetPlatform *specs.Platform
|
||||
BuildPlatforms []specs.Platform
|
||||
PrefixPlatform bool
|
||||
ExtraHosts []llb.HostIP
|
||||
ForceNetMode pb.NetMode
|
||||
OverrideCopyImage string
|
||||
}
|
||||
|
||||
func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State, *Image, error) {
|
||||
|
@ -302,6 +303,10 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State,
|
|||
buildPlatforms: platformOpt.buildPlatforms,
|
||||
targetPlatform: platformOpt.targetPlatform,
|
||||
extraHosts: opt.ExtraHosts,
|
||||
copyImage: opt.OverrideCopyImage,
|
||||
}
|
||||
if opt.copyImage == "" {
|
||||
opt.copyImage = DefaultCopyImage
|
||||
}
|
||||
|
||||
if err = dispatchOnBuild(d, d.image.Config.OnBuild, opt); err != nil {
|
||||
|
@ -406,6 +411,7 @@ type dispatchOpt struct {
|
|||
targetPlatform specs.Platform
|
||||
buildPlatforms []specs.Platform
|
||||
extraHosts []llb.HostIP
|
||||
copyImage string
|
||||
}
|
||||
|
||||
func dispatch(d *dispatchState, cmd command, opt dispatchOpt) error {
|
||||
|
@ -613,7 +619,7 @@ func dispatchWorkdir(d *dispatchState, c *instructions.WorkdirCommand, commit bo
|
|||
|
||||
func dispatchCopy(d *dispatchState, c instructions.SourcesAndDest, sourceState llb.State, isAddCommand bool, cmdToPrint fmt.Stringer, chown string, opt dispatchOpt) error {
|
||||
// TODO: this should use CopyOp instead. Current implementation is inefficient
|
||||
img := llb.Image(CopyImage, llb.MarkImageInternal, llb.Platform(opt.buildPlatforms[0]), WithInternalName("helper image for file operations"))
|
||||
img := llb.Image(opt.copyImage, llb.MarkImageInternal, llb.Platform(opt.buildPlatforms[0]), WithInternalName("helper image for file operations"))
|
||||
|
||||
dest := path.Join(".", pathRelativeToWorkingDir(d.state, c.Dest()))
|
||||
if c.Dest() == "." || c.Dest()[len(c.Dest())-1] == filepath.Separator {
|
||||
|
|
Loading…
Reference in New Issue