Merge pull request #594 from tonistiigi/override-copy

dockerfile: allow overriding copy image
docker-18.09
Tibor Vass 2018-08-31 14:35:06 -07:00 committed by GitHub
commit 94b009b27e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 24 deletions

View File

@ -40,6 +40,7 @@ const (
keyImageResolveMode = "image-resolve-mode" keyImageResolveMode = "image-resolve-mode"
keyGlobalAddHosts = "add-hosts" keyGlobalAddHosts = "add-hosts"
keyForceNetwork = "force-network-mode" keyForceNetwork = "force-network-mode"
keyOverrideCopyImage = "override-copy-image" // remove after CopyOp implemented
) )
var httpPrefix = regexp.MustCompile("^https?://") 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") return nil, errors.Errorf("failed to read downloaded context")
} }
if isArchive(dt) { 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")) Run(llb.Shlex("copy --unpack /src/context /out/"), llb.ReadonlyRootFS(), dockerfile2llb.WithInternalName("extracting build context"))
unpack.AddMount("/src", httpContext, llb.Readonly) unpack.AddMount("/src", httpContext, llb.Readonly)
src = unpack.AddMount("/out", llb.Scratch()) src = unpack.AddMount("/out", llb.Scratch())
@ -266,6 +271,7 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {
PrefixPlatform: exportMap, PrefixPlatform: exportMap,
ExtraHosts: extraHosts, ExtraHosts: extraHosts,
ForceNetMode: defaultNetMode, ForceNetMode: defaultNetMode,
OverrideCopyImage: opts[keyOverrideCopyImage],
}) })
if err != nil { if err != nil {

View File

@ -33,7 +33,7 @@ const (
localNameContext = "context" localNameContext = "context"
historyComment = "buildkit.dockerfile.v0" historyComment = "buildkit.dockerfile.v0"
CopyImage = "tonistiigi/copy:v0.1.3@sha256:e57a3b4d6240f55bac26b655d2cfb751f8b9412d6f7bb1f787e946391fb4b21b" DefaultCopyImage = "tonistiigi/copy:v0.1.3@sha256:e57a3b4d6240f55bac26b655d2cfb751f8b9412d6f7bb1f787e946391fb4b21b"
) )
type ConvertOpt struct { type ConvertOpt struct {
@ -55,6 +55,7 @@ type ConvertOpt struct {
PrefixPlatform bool PrefixPlatform bool
ExtraHosts []llb.HostIP ExtraHosts []llb.HostIP
ForceNetMode pb.NetMode ForceNetMode pb.NetMode
OverrideCopyImage string
} }
func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State, *Image, error) { 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, buildPlatforms: platformOpt.buildPlatforms,
targetPlatform: platformOpt.targetPlatform, targetPlatform: platformOpt.targetPlatform,
extraHosts: opt.ExtraHosts, extraHosts: opt.ExtraHosts,
copyImage: opt.OverrideCopyImage,
}
if opt.copyImage == "" {
opt.copyImage = DefaultCopyImage
} }
if err = dispatchOnBuild(d, d.image.Config.OnBuild, opt); err != nil { if err = dispatchOnBuild(d, d.image.Config.OnBuild, opt); err != nil {
@ -406,6 +411,7 @@ type dispatchOpt struct {
targetPlatform specs.Platform targetPlatform specs.Platform
buildPlatforms []specs.Platform buildPlatforms []specs.Platform
extraHosts []llb.HostIP extraHosts []llb.HostIP
copyImage string
} }
func dispatch(d *dispatchState, cmd command, opt dispatchOpt) error { 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 { 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 // 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())) dest := path.Join(".", pathRelativeToWorkingDir(d.state, c.Dest()))
if c.Dest() == "." || c.Dest()[len(c.Dest())-1] == filepath.Separator { if c.Dest() == "." || c.Dest()[len(c.Dest())-1] == filepath.Separator {