@@ -1464,7 +1464,11 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error {
1464
1464
if len (cfg .params .SourcePaths ) != 1 {
1465
1465
return errors .New ("checksum can't be specified for multiple sources" )
1466
1466
}
1467
- if ! isHTTPSource (cfg .params .SourcePaths [0 ]) {
1467
+ ok , err := isHTTPSource (cfg .params .SourcePaths [0 ])
1468
+ if err != nil {
1469
+ return err
1470
+ }
1471
+ if ! ok {
1468
1472
return errors .New ("checksum can't be specified for non-HTTP(S) sources" )
1469
1473
}
1470
1474
}
@@ -1523,77 +1527,83 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error {
1523
1527
} else {
1524
1528
a = a .Copy (st , "/" , dest , opts ... )
1525
1529
}
1526
- } else if isHTTPSource (src ) {
1527
- if ! cfg .isAddCommand {
1528
- return errors .New ("source can't be a URL for COPY" )
1530
+ } else {
1531
+ isHTTPSourceV , err := isHTTPSource (src )
1532
+ if err != nil {
1533
+ return err
1529
1534
}
1535
+ if isHTTPSourceV {
1536
+ if ! cfg .isAddCommand {
1537
+ return errors .New ("source can't be a URL for COPY" )
1538
+ }
1530
1539
1531
- // Resources from remote URLs are not decompressed.
1532
- // https://docs.docker.com/engine/reference/builder/#add
1533
- //
1534
- // Note: mixing up remote archives and local archives in a single ADD instruction
1535
- // would result in undefined behavior: https://github.com/moby/buildkit/pull/387#discussion_r189494717
1536
- u , err := url .Parse (src )
1537
- f := "__unnamed__"
1538
- if err == nil {
1539
- if base := path .Base (u .Path ); base != "." && base != "/" {
1540
- f = base
1540
+ // Resources from remote URLs are not decompressed.
1541
+ // https://docs.docker.com/engine/reference/builder/#add
1542
+ //
1543
+ // Note: mixing up remote archives and local archives in a single ADD instruction
1544
+ // would result in undefined behavior: https://github.com/moby/buildkit/pull/387#discussion_r189494717
1545
+ u , err := url .Parse (src )
1546
+ f := "__unnamed__"
1547
+ if err == nil {
1548
+ if base := path .Base (u .Path ); base != "." && base != "/" {
1549
+ f = base
1550
+ }
1541
1551
}
1542
- }
1543
1552
1544
- st := llb .HTTP (src , llb .Filename (f ), llb .WithCustomName (pgName ), llb .Checksum (cfg .checksum ), dfCmd (cfg .params ))
1553
+ st := llb .HTTP (src , llb .Filename (f ), llb .WithCustomName (pgName ), llb .Checksum (cfg .checksum ), dfCmd (cfg .params ))
1545
1554
1546
- opts := append ([]llb.CopyOption {& llb.CopyInfo {
1547
- Mode : chopt ,
1548
- CreateDestPath : true ,
1549
- }}, copyOpt ... )
1555
+ opts := append ([]llb.CopyOption {& llb.CopyInfo {
1556
+ Mode : chopt ,
1557
+ CreateDestPath : true ,
1558
+ }}, copyOpt ... )
1550
1559
1551
- if a == nil {
1552
- a = llb .Copy (st , f , dest , opts ... )
1553
- } else {
1554
- a = a .Copy (st , f , dest , opts ... )
1555
- }
1556
- } else {
1557
- validateCopySourcePath (src , & cfg )
1558
- var patterns []string
1559
- if cfg .parents {
1560
- // detect optional pivot point
1561
- parent , pattern , ok := strings .Cut (src , "/./" )
1562
- if ! ok {
1563
- pattern = src
1564
- src = "/"
1560
+ if a == nil {
1561
+ a = llb .Copy (st , f , dest , opts ... )
1565
1562
} else {
1566
- src = parent
1563
+ a = a . Copy ( st , f , dest , opts ... )
1567
1564
}
1565
+ } else {
1566
+ validateCopySourcePath (src , & cfg )
1567
+ var patterns []string
1568
+ if cfg .parents {
1569
+ // detect optional pivot point
1570
+ parent , pattern , ok := strings .Cut (src , "/./" )
1571
+ if ! ok {
1572
+ pattern = src
1573
+ src = "/"
1574
+ } else {
1575
+ src = parent
1576
+ }
1577
+
1578
+ pattern , err = system .NormalizePath ("/" , pattern , d .platform .OS , false )
1579
+ if err != nil {
1580
+ return errors .Wrap (err , "removing drive letter" )
1581
+ }
1568
1582
1569
- pattern , err = system .NormalizePath ("/" , pattern , d .platform .OS , false )
1583
+ patterns = []string {strings .TrimPrefix (pattern , "/" )}
1584
+ }
1585
+
1586
+ src , err = system .NormalizePath ("/" , src , d .platform .OS , false )
1570
1587
if err != nil {
1571
1588
return errors .Wrap (err , "removing drive letter" )
1572
1589
}
1573
1590
1574
- patterns = []string {strings .TrimPrefix (pattern , "/" )}
1575
- }
1576
-
1577
- src , err = system .NormalizePath ("/" , src , d .platform .OS , false )
1578
- if err != nil {
1579
- return errors .Wrap (err , "removing drive letter" )
1580
- }
1581
-
1582
- opts := append ([]llb.CopyOption {& llb.CopyInfo {
1583
- Mode : chopt ,
1584
- FollowSymlinks : true ,
1585
- CopyDirContentsOnly : true ,
1586
- IncludePatterns : patterns ,
1587
- AttemptUnpack : cfg .isAddCommand ,
1588
- CreateDestPath : true ,
1589
- AllowWildcard : true ,
1590
- AllowEmptyWildcard : true ,
1591
- }}, copyOpt ... )
1592
-
1593
- if a == nil {
1594
- a = llb .Copy (cfg .source , src , dest , opts ... )
1595
- } else {
1596
- a = a .Copy (cfg .source , src , dest , opts ... )
1591
+ opts := append ([]llb.CopyOption {& llb.CopyInfo {
1592
+ Mode : chopt ,
1593
+ FollowSymlinks : true ,
1594
+ CopyDirContentsOnly : true ,
1595
+ IncludePatterns : patterns ,
1596
+ AttemptUnpack : cfg .isAddCommand ,
1597
+ CreateDestPath : true ,
1598
+ AllowWildcard : true ,
1599
+ AllowEmptyWildcard : true ,
1600
+ }}, copyOpt ... )
1601
+
1602
+ if a == nil {
1603
+ a = llb .Copy (cfg .source , src , dest , opts ... )
1604
+ } else {
1605
+ a = a .Copy (cfg .source , src , dest , opts ... )
1606
+ }
1597
1607
}
1598
1608
}
1599
1609
}
@@ -2255,15 +2265,22 @@ func commonImageNames() []string {
2255
2265
return out
2256
2266
}
2257
2267
2258
- func isHTTPSource (src string ) bool {
2268
+ func isHTTPSource (src string ) ( bool , error ) {
2259
2269
if ! strings .HasPrefix (src , "http://" ) && ! strings .HasPrefix (src , "https://" ) {
2260
- return false
2270
+ return false , nil
2261
2271
}
2262
2272
// https://github.com/ORG/REPO.git is a git source, not an http source
2263
- if gitRef , gitErr := gitutil .ParseGitRef (src ); gitRef != nil && gitErr == nil {
2264
- return false
2273
+ gitRef , gitErr := gitutil .ParseGitRef (src )
2274
+ var eiuf * gitutil.ErrInvalidURLFragemnt
2275
+ if errors .As (gitErr , & eiuf ) {
2276
+ // this is a git source, and it has an invalid URL fragment
2277
+ // (e.g., both tag and branch are specified)
2278
+ return false , gitErr
2279
+ }
2280
+ if gitRef != nil && gitErr == nil {
2281
+ return false , nil
2265
2282
}
2266
- return true
2283
+ return true , nil
2267
2284
}
2268
2285
2269
2286
func isEnabledForStage (stage string , value string ) bool {
0 commit comments