@@ -937,27 +937,21 @@ func dispatch(d *dispatchState, cmd command, opt dispatchOpt) error {
937
937
case * instructions.WorkdirCommand :
938
938
err = dispatchWorkdir (d , c , true , & opt )
939
939
case * instructions.AddCommand :
940
- var checksum digest.Digest
941
- if c .Checksum != "" {
942
- checksum , err = digest .Parse (c .Checksum )
943
- }
944
- if err == nil {
945
- err = dispatchCopy (d , copyConfig {
946
- params : c .SourcesAndDest ,
947
- excludePatterns : c .ExcludePatterns ,
948
- source : opt .buildContext ,
949
- isAddCommand : true ,
950
- cmdToPrint : c ,
951
- chown : c .Chown ,
952
- chmod : c .Chmod ,
953
- link : c .Link ,
954
- keepGitDir : c .KeepGitDir ,
955
- checksum : checksum ,
956
- location : c .Location (),
957
- ignoreMatcher : opt .dockerIgnoreMatcher ,
958
- opt : opt ,
959
- })
960
- }
940
+ err = dispatchCopy (d , copyConfig {
941
+ params : c .SourcesAndDest ,
942
+ excludePatterns : c .ExcludePatterns ,
943
+ source : opt .buildContext ,
944
+ isAddCommand : true ,
945
+ cmdToPrint : c ,
946
+ chown : c .Chown ,
947
+ chmod : c .Chmod ,
948
+ link : c .Link ,
949
+ keepGitDir : c .KeepGitDir ,
950
+ checksum : c .Checksum ,
951
+ location : c .Location (),
952
+ ignoreMatcher : opt .dockerIgnoreMatcher ,
953
+ opt : opt ,
954
+ })
961
955
if err == nil {
962
956
for _ , src := range c .SourcePaths {
963
957
if ! strings .HasPrefix (src , "http://" ) && ! strings .HasPrefix (src , "https://" ) {
@@ -1470,8 +1464,8 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error {
1470
1464
if len (cfg .params .SourcePaths ) != 1 {
1471
1465
return errors .New ("checksum can't be specified for multiple sources" )
1472
1466
}
1473
- if ! isHTTPSource (cfg .params .SourcePaths [0 ]) {
1474
- return errors .New ("checksum can't be specified for non- HTTP(S) sources" )
1467
+ if ! isHTTPSource (cfg .params .SourcePaths [0 ]) && ! isGitSource ( cfg . params . SourcePaths [ 0 ]) {
1468
+ return errors .New ("checksum requires HTTP(S) or Git sources" )
1475
1469
}
1476
1470
}
1477
1471
@@ -1519,6 +1513,9 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error {
1519
1513
if cfg .keepGitDir {
1520
1514
gitOptions = append (gitOptions , llb .KeepGitDir ())
1521
1515
}
1516
+ if cfg .checksum != "" {
1517
+ gitOptions = append (gitOptions , llb .GitChecksum (cfg .checksum ))
1518
+ }
1522
1519
st := llb .Git (gitRef .Remote , commit , gitOptions ... )
1523
1520
opts := append ([]llb.CopyOption {& llb.CopyInfo {
1524
1521
Mode : chopt ,
@@ -1547,7 +1544,15 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error {
1547
1544
}
1548
1545
}
1549
1546
1550
- st := llb .HTTP (src , llb .Filename (f ), llb .WithCustomName (pgName ), llb .Checksum (cfg .checksum ), dfCmd (cfg .params ))
1547
+ var checksum digest.Digest
1548
+ if cfg .checksum != "" {
1549
+ checksum , err = digest .Parse (cfg .checksum )
1550
+ if err != nil {
1551
+ return err
1552
+ }
1553
+ }
1554
+
1555
+ st := llb .HTTP (src , llb .Filename (f ), llb .WithCustomName (pgName ), llb .Checksum (checksum ), dfCmd (cfg .params ))
1551
1556
1552
1557
opts := append ([]llb.CopyOption {& llb.CopyInfo {
1553
1558
Mode : chopt ,
@@ -1674,7 +1679,7 @@ type copyConfig struct {
1674
1679
chmod string
1675
1680
link bool
1676
1681
keepGitDir bool
1677
- checksum digest. Digest
1682
+ checksum string
1678
1683
parents bool
1679
1684
location []parser.Range
1680
1685
ignoreMatcher * patternmatcher.PatternMatcher
@@ -2265,11 +2270,15 @@ func isHTTPSource(src string) bool {
2265
2270
if ! strings .HasPrefix (src , "http://" ) && ! strings .HasPrefix (src , "https://" ) {
2266
2271
return false
2267
2272
}
2273
+ return ! isGitSource (src )
2274
+ }
2275
+
2276
+ func isGitSource (src string ) bool {
2268
2277
// https://github.com/ORG/REPO.git is a git source, not an http source
2269
2278
if gitRef , gitErr := gitutil .ParseGitRef (src ); gitRef != nil && gitErr == nil {
2270
- return false
2279
+ return true
2271
2280
}
2272
- return true
2281
+ return false
2273
2282
}
2274
2283
2275
2284
func isEnabledForStage (stage string , value string ) bool {
0 commit comments