Skip to content

Commit 21679a0

Browse files
committed
Added support for delegated build
1 parent f260048 commit 21679a0

File tree

11 files changed

+563
-66
lines changed

11 files changed

+563
-66
lines changed

go.mod

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,30 @@ require (
6464
github.com/caddyserver/zerossl v0.1.3 // indirect
6565
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
6666
github.com/cloudflare/circl v1.6.1 // indirect
67+
github.com/containerd/errdefs v1.0.0 // indirect
68+
github.com/containerd/errdefs/pkg v0.3.0 // indirect
6769
github.com/containerd/stargz-snapshotter/estargz v0.16.3 // indirect
6870
github.com/containerd/typeurl/v2 v2.2.3 // indirect
6971
github.com/cyphar/filepath-securejoin v0.3.6 // indirect
7072
github.com/davecgh/go-spew v1.1.1 // indirect
73+
github.com/distribution/reference v0.6.0 // indirect
7174
github.com/docker/cli v28.2.2+incompatible // indirect
7275
github.com/docker/distribution v2.8.3+incompatible // indirect
76+
github.com/docker/docker v28.2.2+incompatible // indirect
7377
github.com/docker/docker-credential-helpers v0.9.3 // indirect
78+
github.com/docker/go-connections v0.5.0 // indirect
79+
github.com/docker/go-units v0.5.0 // indirect
7480
github.com/dustin/go-humanize v1.0.1 // indirect
7581
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
7682
github.com/emirpasic/gods v1.18.1 // indirect
7783
github.com/felixge/fgprof v0.9.5 // indirect
84+
github.com/felixge/httpsnoop v1.0.4 // indirect
7885
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
7986
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
8087
github.com/go-git/go-billy/v5 v5.6.1 // indirect
8188
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
8289
github.com/go-logr/logr v1.4.3 // indirect
90+
github.com/go-logr/stdr v1.2.2 // indirect
8391
github.com/go-openapi/jsonpointer v0.21.0 // indirect
8492
github.com/go-openapi/jsonreference v0.20.2 // indirect
8593
github.com/go-openapi/swag v0.23.0 // indirect
@@ -122,6 +130,7 @@ require (
122130
github.com/mitchellh/go-homedir v1.1.0 // indirect
123131
github.com/mitchellh/mapstructure v1.5.0 // indirect
124132
github.com/mitchellh/reflectwalk v1.0.2 // indirect
133+
github.com/moby/docker-image-spec v1.3.1 // indirect
125134
github.com/moby/spdystream v0.5.0 // indirect
126135
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
127136
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
@@ -145,6 +154,11 @@ require (
145154
github.com/x448/float16 v0.8.4 // indirect
146155
github.com/xanzy/ssh-agent v0.3.3 // indirect
147156
github.com/zeebo/blake3 v0.2.4 // indirect
157+
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
158+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect
159+
go.opentelemetry.io/otel v1.36.0 // indirect
160+
go.opentelemetry.io/otel/metric v1.36.0 // indirect
161+
go.opentelemetry.io/otel/trace v1.36.0 // indirect
148162
go.uber.org/multierr v1.11.0 // indirect
149163
go.uber.org/zap v1.27.0 // indirect
150164
go.yaml.in/yaml/v2 v2.4.2 // indirect

go.sum

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
7878
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
7979
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
8080
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
81+
github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI=
82+
github.com/containerd/errdefs v1.0.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M=
83+
github.com/containerd/errdefs/pkg v0.3.0 h1:9IKJ06FvyNlexW690DXuQNx2KA2cUJXx151Xdx3ZPPE=
84+
github.com/containerd/errdefs/pkg v0.3.0/go.mod h1:NJw6s9HwNuRhnjJhM7pylWwMyAkmCQvQ4GpJHEqRLVk=
8185
github.com/containerd/stargz-snapshotter/estargz v0.16.3 h1:7evrXtoh1mSbGj/pfRccTampEyKpjpOnS3CyiV1Ebr8=
8286
github.com/containerd/stargz-snapshotter/estargz v0.16.3/go.mod h1:uyr4BfYfOj3G9WBVE8cOlQmXAbPN9VEQpBBeJIuOipU=
8387
github.com/containerd/typeurl/v2 v2.2.3 h1:yNA/94zxWdvYACdYO8zofhrTVuQY73fFU1y++dYSw40=
@@ -91,12 +95,20 @@ github.com/cyphar/filepath-securejoin v0.3.6/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGL
9195
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
9296
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
9397
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
98+
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
99+
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
94100
github.com/docker/cli v28.2.2+incompatible h1:qzx5BNUDFqlvyq4AHzdNB7gSyVTmU4cgsyN9SdInc1A=
95101
github.com/docker/cli v28.2.2+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
96102
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
97103
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
104+
github.com/docker/docker v28.2.2+incompatible h1:CjwRSksz8Yo4+RmQ339Dp/D2tGO5JxwYeqtMOEe0LDw=
105+
github.com/docker/docker v28.2.2+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
98106
github.com/docker/docker-credential-helpers v0.9.3 h1:gAm/VtF9wgqJMoxzT3Gj5p4AqIjCBS4wrsOh9yRqcz8=
99107
github.com/docker/docker-credential-helpers v0.9.3/go.mod h1:x+4Gbw9aGmChi3qTLZj8Dfn0TD20M/fuWy0E5+WDeCo=
108+
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
109+
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
110+
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
111+
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
100112
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
101113
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
102114
github.com/elazarl/goproxy v1.2.3 h1:xwIyKHbaP5yfT6O9KIeYJR5549MXRQkoQMRXGztz8YQ=
@@ -112,6 +124,8 @@ github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4Nij
112124
github.com/felixge/fgprof v0.9.3/go.mod h1:RdbpDgzqYVh/T9fPELJyV7EYJuHB55UTEULNun8eiPw=
113125
github.com/felixge/fgprof v0.9.5 h1:8+vR6yu2vvSKn08urWyEuxx75NWPEvybbkBirEpsbVY=
114126
github.com/felixge/fgprof v0.9.5/go.mod h1:yKl+ERSa++RYOs32d8K6WEXCB4uXdLls4ZaZPpayhMM=
127+
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
128+
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
115129
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
116130
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
117131
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
@@ -133,8 +147,11 @@ github.com/go-git/go-git/v5 v5.13.1 h1:DAQ9APonnlvSWpvolXWIuV6Q6zXy2wHbN4cVlNR5Q
133147
github.com/go-git/go-git/v5 v5.13.1/go.mod h1:qryJB4cSBoq3FRoBRf5A77joojuBcmPJ0qu3XXXVixc=
134148
github.com/go-jose/go-jose/v4 v4.0.5 h1:M6T8+mKZl/+fNNuFHvGIzDz7BTLQPIounk/b9dw3AaE=
135149
github.com/go-jose/go-jose/v4 v4.0.5/go.mod h1:s3P1lRrkT8igV8D9OjyL4WRyHvjB6a4JSllnOrmmBOA=
150+
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
136151
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
137152
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
153+
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
154+
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
138155
github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs=
139156
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
140157
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
@@ -276,6 +293,8 @@ github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zx
276293
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
277294
github.com/moby/buildkit v0.18.1 h1:Iwrz2F/Za2Gjkpwu3aM2LX92AFfJCJe2oNnvGNvh2Rc=
278295
github.com/moby/buildkit v0.18.1/go.mod h1:vCR5CX8NGsPTthTg681+9kdmfvkvqJBXEv71GZe5msU=
296+
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
297+
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
279298
github.com/moby/spdystream v0.5.0 h1:7r0J1Si3QO/kjRitvSLVVFUjxMEb/YLj6S9FF62JBCU=
280299
github.com/moby/spdystream v0.5.0/go.mod h1:xBAYlnt/ay+11ShkdFKNAG7LsyK/tmNBVvVOwrfMgdI=
281300
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -379,6 +398,16 @@ github.com/zeebo/blake3 v0.2.4 h1:KYQPkhpRtcqh0ssGYcKLG1JYvddkEA8QwCM/yBqhaZI=
379398
github.com/zeebo/blake3 v0.2.4/go.mod h1:7eeQ6d2iXWRGF6npfaxl2CU+xy2Fjo2gxeyZGCRUjcE=
380399
github.com/zeebo/pcg v1.0.1 h1:lyqfGeWiv4ahac6ttHs+I5hwtH/+1mrhlCtVNQM2kHo=
381400
github.com/zeebo/pcg v1.0.1/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4=
401+
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
402+
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
403+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 h1:F7Jx+6hwnZ41NSFTO5q4LYDtJRXBf2PD0rNBkeB/lus=
404+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0/go.mod h1:UHB22Z8QsdRDrnAtX4PntOl36ajSxcdUMt1sF7Y6E7Q=
405+
go.opentelemetry.io/otel v1.36.0 h1:UumtzIklRBY6cI/lllNZlALOF5nNIzJVb16APdvgTXg=
406+
go.opentelemetry.io/otel v1.36.0/go.mod h1:/TcFMXYjyRNh8khOAO9ybYkqaDBb/70aVwkNML4pP8E=
407+
go.opentelemetry.io/otel/metric v1.36.0 h1:MoWPKVhQvJ+eeXWHFBOPoBOi20jh6Iq2CcCREuTYufE=
408+
go.opentelemetry.io/otel/metric v1.36.0/go.mod h1:zC7Ks+yeyJt4xig9DEw9kuUFe5C3zLbVjV2PzT6qzbs=
409+
go.opentelemetry.io/otel/trace v1.36.0 h1:ahxWNuqZjpdiFAyrIoQ4GIiAIhxAunQR6MUoKrsNd4w=
410+
go.opentelemetry.io/otel/trace v1.36.0/go.mod h1:gQ+OnDZzrybY4k4seLzPAWNwVBBVlF2szhehOBB/tGA=
382411
go.starlark.net v0.0.0-20241125201518-c05ff208a98f h1:W+3pcCdjGognUT+oE6tXsC3xiCEcCYTaJBXHHRn7aW0=
383412
go.starlark.net v0.0.0-20241125201518-c05ff208a98f/go.mod h1:YKMCv9b1WrfWmeqdV5MAuEHWsu5iC+fe6kYl2sQjdI8=
384413
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=

internal/app/container_handler.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,13 @@ func (h *ContainerHandler) DevReload(ctx context.Context, dryRun bool) error {
610610
return nil
611611
}
612612

613+
if strings.HasPrefix(h.serverConfig.Builder.Mode, "delegate:") {
614+
return fmt.Errorf("delegated builds are not supported in dev mode")
615+
}
616+
if h.serverConfig.Registry.URL != "" {
617+
return fmt.Errorf("remote registry is not supported in dev mode")
618+
}
619+
613620
h.GenImageName = container.ImageName(h.image)
614621
if h.GenImageName == "" {
615622
h.GenImageName = container.GenImageName(h.app.Id, "")

internal/container/command.go

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,37 @@ func (c *ContainerCommand) RemoveImage(ctx context.Context, name ImageName) erro
8585
return nil
8686
}
8787

88-
func (c *ContainerCommand) BuildImage(ctx context.Context, name ImageName, sourceUrl, containerFile string, containerArgs map[string]string) error {
89-
if c.config.Builder.BuilderMode != "command" && c.config.Builder.BuilderMode != "auto" {
90-
return fmt.Errorf("invalid builder mode for command based container manager: %s", c.config.Builder.BuilderMode)
88+
func (c *ContainerCommand) BuildImage(ctx context.Context, imgName ImageName, sourceUrl, containerFile string, containerArgs map[string]string) error {
89+
targetUrl, found := strings.CutPrefix(c.config.Builder.Mode, "delegate:")
90+
if found {
91+
err := sendDelegateBuild(targetUrl, DelegateRequest{
92+
ImageTag: string(imgName),
93+
ContainerFile: containerFile,
94+
ContainerArgs: containerArgs,
95+
RegistryConfig: &c.config.Registry,
96+
}, sourceUrl)
97+
if err != nil {
98+
return fmt.Errorf("error sending delegate build: %w", err)
99+
}
100+
return nil
101+
}
102+
103+
if c.config.Builder.Mode != "command" && c.config.Builder.Mode != "auto" {
104+
return fmt.Errorf("invalid builder mode for command based container manager: %s", c.config.Builder.Mode)
105+
}
106+
107+
if c.config.Registry.URL != "" {
108+
return fmt.Errorf("remote registry in command mode is supported with delegated builds only")
91109
}
92110

93-
releaseLock, err := acquireBuildLock(context.Background(), &c.config.System, string(name))
111+
releaseLock, err := acquireBuildLock(context.Background(), &c.config.System, string(imgName))
94112
if err != nil {
95113
return fmt.Errorf("error acquiring build lock: %w", err)
96114
}
97115
defer releaseLock()
98116

99-
c.Debug().Msgf("Building image %s from %s with %s", name, containerFile, sourceUrl)
100-
args := []string{c.config.System.ContainerCommand, "build", "-t", string(name), "-f", containerFile}
117+
c.Debug().Msgf("Building image %s from %s with %s", imgName, containerFile, sourceUrl)
118+
args := []string{c.config.System.ContainerCommand, "build", "-t", string(imgName), "-f", containerFile}
101119

102120
for k, v := range containerArgs {
103121
args = append(args, "--build-arg", fmt.Sprintf("%s=%s", k, v))
@@ -276,6 +294,15 @@ func (c *ContainerCommand) RunContainer(ctx context.Context, appEntry *types.App
276294
containerName, imageName, port, envMap, mountArgs)
277295
publish := fmt.Sprintf("127.0.0.1::%d", port)
278296

297+
imageUrl := string(imageName)
298+
if c.config.Registry.URL != "" {
299+
if c.config.Registry.Project != "" {
300+
imageUrl = c.config.Registry.URL + "/" + c.config.Registry.Project + "/" + string(imageName)
301+
} else {
302+
imageUrl = c.config.Registry.URL + "/" + string(imageName)
303+
}
304+
}
305+
279306
args := []string{"run", "--name", string(containerName), "--detach", "--publish", publish}
280307
if len(mountArgs) > 0 {
281308
args = append(args, mountArgs...)
@@ -305,7 +332,7 @@ func (c *ContainerCommand) RunContainer(ctx context.Context, appEntry *types.App
305332
}
306333
}
307334

308-
args = append(args, string(imageName))
335+
args = append(args, imageUrl)
309336

310337
c.Debug().Msgf("Running container with args: %v", args)
311338
cmd := exec.CommandContext(ctx, c.config.System.ContainerCommand, args...)

0 commit comments

Comments
 (0)