Skip to content

Commit 52c771e

Browse files
committed
add go require & replace
Signed-off-by: Danny Brito <[email protected]>
1 parent c7d1ce1 commit 52c771e

File tree

12 files changed

+655
-24
lines changed

12 files changed

+655
-24
lines changed

docs/spec.schema.json

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,10 @@
900900
],
901901
"description": "Auth is the git authorization to use for gomods. The keys are the hosts, and the values are the auth to use for that host."
902902
},
903+
"edits": {
904+
"$ref": "#/$defs/GomodEdits",
905+
"description": "Edits contains go.mod manipulation directives (replace, require) that are applied\nbefore downloading module dependencies."
906+
},
903907
"paths": {
904908
"items": {
905909
"type": [
@@ -1048,6 +1052,36 @@
10481052
],
10491053
"description": "GoBuildCache is a cache for Go build artifacts."
10501054
},
1055+
"GomodEdits": {
1056+
"properties": {
1057+
"replace": {
1058+
"items": {
1059+
"$ref": "#/$defs/GomodReplace"
1060+
},
1061+
"type": [
1062+
"array"
1063+
],
1064+
"description": "Replace applies go.mod replace directives before downloading module dependencies.\nEach entry can be either a string \"old:new\" or a struct with Old and New fields."
1065+
},
1066+
"require": {
1067+
"items": {
1068+
"$ref": "#/$defs/GomodRequire"
1069+
},
1070+
"type": [
1071+
"array"
1072+
],
1073+
"description": "Require applies go.mod require directives before downloading module dependencies.\nEach entry can be either a string \"module:version\" or a struct with Module and Version fields."
1074+
}
1075+
},
1076+
"additionalProperties": {
1077+
"not": {}
1078+
},
1079+
"type": [
1080+
"object",
1081+
"null"
1082+
],
1083+
"description": "GomodEdits groups the go.mod manipulation directives that can be applied before downloading module dependencies."
1084+
},
10511085
"GomodGitAuth": {
10521086
"properties": {
10531087
"header": {
@@ -1102,6 +1136,62 @@
11021136
"null"
11031137
]
11041138
},
1139+
"GomodReplace": {
1140+
"required": [
1141+
"old",
1142+
"new"
1143+
],
1144+
"properties": {
1145+
"new": {
1146+
"type": [
1147+
"string"
1148+
],
1149+
"description": "New is the replacement module path or local directory"
1150+
},
1151+
"old": {
1152+
"type": [
1153+
"string"
1154+
],
1155+
"description": "Old is the module path to replace (can include @version)"
1156+
}
1157+
},
1158+
"additionalProperties": {
1159+
"not": {}
1160+
},
1161+
"type": [
1162+
"object",
1163+
"null"
1164+
],
1165+
"description": "GomodReplace represents a go.mod replace directive."
1166+
},
1167+
"GomodRequire": {
1168+
"required": [
1169+
"module",
1170+
"version"
1171+
],
1172+
"properties": {
1173+
"module": {
1174+
"type": [
1175+
"string"
1176+
],
1177+
"description": "Module is the module path that appears in go.mod"
1178+
},
1179+
"version": {
1180+
"type": [
1181+
"string"
1182+
],
1183+
"description": "Version is the target module and version (e.g., \"module@version\")"
1184+
}
1185+
},
1186+
"additionalProperties": {
1187+
"not": {}
1188+
},
1189+
"type": [
1190+
"object",
1191+
"null"
1192+
],
1193+
"description": "GomodRequire represents a go.mod require directive."
1194+
},
11051195
"ImageConfig": {
11061196
"properties": {
11071197
"base": {

frontend/debug/handle_sources.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package debug
33
import (
44
"context"
55

6-
"github.com/project-dalec/dalec"
7-
"github.com/project-dalec/dalec/frontend"
86
"github.com/moby/buildkit/client/llb"
97
gwclient "github.com/moby/buildkit/frontend/gateway/client"
108
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
9+
"github.com/project-dalec/dalec"
10+
"github.com/project-dalec/dalec/frontend"
1111
)
1212

1313
// Sources is a handler that outputs all the sources.
@@ -64,6 +64,13 @@ func PatchedSources(ctx context.Context, client gwclient.Client) (*gwclient.Resu
6464
}
6565

6666
pc := dalec.Platform(platform)
67+
68+
// Preprocess the spec to generate patches for gomod edits and other generators
69+
// This must happen before getting sources so that generated patch contexts are available
70+
if err := spec.Preprocess(client, sOpt, worker, pc); err != nil {
71+
return nil, nil, err
72+
}
73+
6774
sources, err := dalec.Sources(spec, sOpt, pc)
6875
if err != nil {
6976
return nil, nil, err

frontend/gateway.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"sync"
77
"sync/atomic"
88

9-
"github.com/project-dalec/dalec"
109
"github.com/moby/buildkit/client/llb"
1110
"github.com/moby/buildkit/frontend/dockerui"
1211
gwclient "github.com/moby/buildkit/frontend/gateway/client"
@@ -15,6 +14,7 @@ import (
1514
"github.com/opencontainers/go-digest"
1615
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
1716
"github.com/pkg/errors"
17+
"github.com/project-dalec/dalec"
1818
)
1919

2020
const (
@@ -128,6 +128,7 @@ func SourceOptFromUIClient(ctx context.Context, c gwclient.Client, dc *dockerui.
128128
return st, err
129129
},
130130
GitCredHelperOpt: withCredHelper(c),
131+
GeneratedStates: make(map[string]llb.State), // Initialize map for generated states
131132
}
132133
}
133134

0 commit comments

Comments
 (0)