Skip to content

Commit 3dc4ad3

Browse files
authored
Merge pull request #2584 from 89luca89/local_docker_build
feat: support local builds with docker/podman for local registry
2 parents 34fcfbe + 86ab9d0 commit 3dc4ad3

210 files changed

Lines changed: 30267 additions & 814 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ tags
2424
# VS Code
2525
.vscode/ipch
2626

27+
# Vim
28+
*.vim
29+
2730
/ui/node_modules
2831
/ui/build/static/js/*.js.map
2932

devspace-schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,10 @@
12301230
"type": "boolean",
12311231
"description": "Enabled enables the local registry for pushing images.\nWhen unset the local registry will be used as a fallback if there are no push permissions for the registry.\nWhen `true` the local registry will always be used.\nWhen `false` the local registry will never be used."
12321232
},
1233+
"localbuild": {
1234+
"type": "boolean",
1235+
"description": "LocalBuild enables use of local docker builder instead of building in the cluster"
1236+
},
12331237
"namespace": {
12341238
"type": "string",
12351239
"description": "Namespace where the local registry is deployed. Default is the current context's namespace"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
<details className="config-field" data-expandable="false" open>
3+
<summary>
4+
5+
### `localbuild` <span className="config-field-required" data-required="false">required</span> <span className="config-field-type">boolean</span> <span className="config-field-default">false</span> <span className="config-field-enum"></span> {#localRegistry-localbuild}
6+
7+
LocalBuild enables use of local docker builder instead of building in the cluster
8+
9+
</summary>
10+
11+
12+
13+
</details>

docs/pages/configuration/_partials/v2beta1/localRegistry_reference.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
import PartialEnabled from "./localRegistry/enabled.mdx"
3+
import PartialLocalbuild from "./localRegistry/localbuild.mdx"
34
import PartialNamespace from "./localRegistry/namespace.mdx"
45
import PartialName from "./localRegistry/name.mdx"
56
import PartialImage from "./localRegistry/image.mdx"
@@ -10,6 +11,9 @@ import PartialPersistencereference from "./localRegistry/persistence_reference.m
1011
<PartialEnabled />
1112

1213

14+
<PartialLocalbuild />
15+
16+
1317
<PartialNamespace />
1418

1519

docs/pages/configuration/localRegistry/README.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Local registry configuration is defined in the `localRegistry` section of the `d
1717
defaultValue="default"
1818
values={[
1919
{ label: 'Defaults', value: 'default', },
20+
{ label: 'Build locally with Docker/Podman', value: 'localbuild', },
2021
{ label: 'Force Local Registry', value: 'force', },
2122
{ label: 'Persistence', value: 'persistence', },
2223
]
@@ -30,10 +31,21 @@ Local registry configuration is defined in the `localRegistry` section of the `d
3031
# localRegistry:
3132
# name: registry
3233
# namespace: [KUBE CONTEXT NAMESPACE]
34+
# localbuild: false
3335
# image: registry:2.8.1
3436
# port: 5000
3537
```
3638

39+
</TabItem>
40+
<TabItem value="localbuild">
41+
42+
```yaml
43+
# The local registry will not use buildkit on the cluster, but your docker/podman daemon
44+
# and then push it to the local registry in the cluster
45+
localRegistry:
46+
localbuild: true
47+
```
48+
3749
</TabItem>
3850
<TabItem value="persistence">
3951

docs/schemas/config-openapi.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,10 @@
12381238
"type": "boolean",
12391239
"description": "Enabled enables the local registry for pushing images.\nWhen unset the local registry will be used as a fallback if there are no push permissions for the registry.\nWhen `true` the local registry will always be used.\nWhen `false` the local registry will never be used."
12401240
},
1241+
"localbuild": {
1242+
"type": "boolean",
1243+
"description": "LocalBuild enables use of local docker builder instead of building in the cluster"
1244+
},
12411245
"namespace": {
12421246
"type": "string",
12431247
"description": "Namespace where the local registry is deployed. Default is the current context's namespace"

e2e/tests/deploy/deploy.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ var _ = DevSpaceDescribe("deploy", func() {
482482
framework.ExpectNoError(err)
483483
framework.ExpectEqual(deployment.Spec.Template.Spec.Containers[0].Name, "nginx")
484484
framework.ExpectEqual(deployment.Spec.Template.Spec.Containers[0].Image, "nginx:1.23.3")
485-
framework.ExpectEqual(deployment.Spec.Template.GetObjectMeta().GetLabels(), map[string]string {"app": "nginx", "test": "test123"})
485+
framework.ExpectEqual(deployment.Spec.Template.GetObjectMeta().GetLabels(), map[string]string{"app": "nginx", "test": "test123"})
486486
framework.ExpectEqual(deployment.Spec.Template.Spec.Containers[1].Name, "busybox")
487487
framework.ExpectEqual(deployment.Spec.Template.Spec.Containers[2].Name, "alpine")
488488
// Ensure the wildcard works
@@ -533,7 +533,7 @@ var _ = DevSpaceDescribe("deploy", func() {
533533
framework.ExpectNoError(err)
534534
framework.ExpectEqual(deployment.Spec.Template.Spec.Containers[0].Name, "nginx")
535535
framework.ExpectEqual(deployment.Spec.Template.Spec.Containers[0].Image, "nginx:1.23.3")
536-
framework.ExpectEqual(deployment.Spec.Template.GetObjectMeta().GetLabels(), map[string]string {"app": "nginx", "test": "test123"})
536+
framework.ExpectEqual(deployment.Spec.Template.GetObjectMeta().GetLabels(), map[string]string{"app": "nginx", "test": "test123"})
537537
framework.ExpectEqual(deployment.Spec.Template.Spec.Containers[1].Name, "busybox")
538538
framework.ExpectEqual(deployment.Spec.Template.Spec.Containers[2].Name, "alpine")
539539
// Ensure the wildcard works
@@ -542,7 +542,6 @@ var _ = DevSpaceDescribe("deploy", func() {
542542
framework.ExpectEqual(deployment.Spec.Template.Spec.Containers[2].Env[0], v1.EnvVar{Name: "test", Value: "test123"})
543543
})
544544

545-
546545
ginkgo.It("should deploy helm chart from specific branch in git repo", func() {
547546
tempDir, err := framework.CopyToTempDir("tests/deploy/testdata/helm_git_branch")
548547
framework.ExpectNoError(err)

e2e/tests/localregistry/localregistry.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ package localregistry
33
import (
44
"bytes"
55
"context"
6-
"github.com/loft-sh/devspace/pkg/devspace/build/localregistry"
7-
"github.com/onsi/ginkgo/v2"
6+
"fmt"
87
"os"
98
"time"
109

10+
"github.com/google/go-containerregistry/pkg/name"
11+
"github.com/google/go-containerregistry/pkg/v1/remote"
12+
"github.com/loft-sh/devspace/pkg/devspace/build/localregistry"
13+
"github.com/onsi/ginkgo/v2"
14+
1115
"github.com/sirupsen/logrus"
1216
appsv1 "k8s.io/api/apps/v1"
1317
corev1 "k8s.io/api/core/v1"
@@ -83,6 +87,7 @@ var _ = DevSpaceDescribe("localregistry", func() {
8387
done <- devCmd.RunDefault(f)
8488
}()
8589

90+
var registryHost string
8691
ginkgo.By("Waiting for registry service node port")
8792
gomega.Eventually(func() (*corev1.Service, error) {
8893
service, err := getRegistryService(ctx, kubeClient, ns)
@@ -93,6 +98,7 @@ var _ = DevSpaceDescribe("localregistry", func() {
9398
if service != nil {
9499
registryPort := localregistry.GetServicePort(service)
95100
if registryPort.NodePort != 0 {
101+
registryHost = fmt.Sprintf("localhost:%d", registryPort.NodePort)
96102
return service, nil
97103
}
98104
}
@@ -109,6 +115,11 @@ var _ = DevSpaceDescribe("localregistry", func() {
109115
gomega.Eventually(selectContainerImage(kubeClient, ns, "app", "container2"), pollingDurationLong, pollingInterval).
110116
Should(gomega.MatchRegexp(`^localhost`))
111117

118+
// make sure we've pushed the image correctly
119+
ginkgo.By("Checking registry for pushed image")
120+
gomega.Eventually(getImages(ctx, registryHost), pollingDurationLong, pollingInterval).
121+
Should(gomega.ContainElement("my-docker-username/helloworld"))
122+
112123
err = <-done
113124
framework.ExpectNoError(err)
114125
})
@@ -480,3 +491,18 @@ func readFile(name string) func() (string, error) {
480491
return string(out), nil
481492
}
482493
}
494+
func getImages(ctx context.Context, registryHost string) func() ([]string, error) {
495+
return func() ([]string, error) {
496+
registry, err := name.NewRegistry(registryHost)
497+
if err != nil {
498+
return nil, err
499+
}
500+
501+
images, err := remote.Catalog(ctx, registry)
502+
if err != nil {
503+
return nil, err
504+
}
505+
506+
return images, nil
507+
}
508+
}

e2e/tests/localregistry/testdata/local-registry-docker/devspace.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
version: v2beta1
22
name: local-registry
3-
localRegistry:
3+
localRegistry:
44
enabled: true
5+
localbuild: true
56
images:
67
app:
78
image: my-docker-username/helloworld

go.mod

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ require (
2020
github.com/ghodss/yaml v1.0.0
2121
github.com/gliderlabs/ssh v0.3.5
2222
github.com/go-resty/resty/v2 v2.7.0
23-
github.com/google/go-containerregistry v0.7.0
23+
github.com/google/go-containerregistry v0.13.0
24+
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
2425
github.com/google/uuid v1.3.0
2526
github.com/gorilla/websocket v1.4.2
2627
github.com/invopop/jsonschema v0.3.0
@@ -45,7 +46,7 @@ require (
4546
github.com/sabhiram/go-gitignore v0.0.0-20180611051255-d3107576ba94
4647
github.com/sirupsen/logrus v1.9.0
4748
github.com/skratchdot/open-golang v0.0.0-20160302144031-75fb7ed4208c
48-
github.com/spf13/cobra v1.5.0
49+
github.com/spf13/cobra v1.6.0
4950
github.com/spf13/pflag v1.0.5
5051
github.com/vmware-labs/yaml-jsonpath v0.3.2
5152
golang.org/x/crypto v0.2.0
@@ -70,7 +71,7 @@ require (
7071

7172
require (
7273
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
73-
github.com/Microsoft/go-winio v0.5.2 // indirect
74+
github.com/Microsoft/go-winio v0.6.0 // indirect
7475
github.com/PuerkitoBio/purell v1.1.1 // indirect
7576
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
7677
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
@@ -79,6 +80,7 @@ require (
7980
github.com/containerd/console v1.0.3 // indirect
8081
github.com/containerd/containerd v1.6.18 // indirect
8182
github.com/containerd/continuity v0.3.0 // indirect
83+
github.com/containerd/stargz-snapshotter/estargz v0.13.0 // indirect
8284
github.com/containerd/typeurl v1.0.2 // indirect
8385
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
8486
github.com/davecgh/go-spew v1.1.1 // indirect
@@ -111,7 +113,7 @@ require (
111113
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0 // indirect
112114
github.com/imdario/mergo v0.3.12 // indirect
113115
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf // indirect
114-
github.com/inconshreveable/mousetrap v1.0.0 // indirect
116+
github.com/inconshreveable/mousetrap v1.0.1 // indirect
115117
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
116118
github.com/josharian/intern v1.0.0 // indirect
117119
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
@@ -135,7 +137,7 @@ require (
135137
github.com/morikuni/aec v1.0.0 // indirect
136138
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
137139
github.com/opencontainers/go-digest v1.0.0 // indirect
138-
github.com/opencontainers/image-spec v1.0.3-0.20220303224323-02efb9a75ee1 // indirect
140+
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
139141
github.com/opencontainers/runc v1.1.3 // indirect
140142
github.com/prometheus/client_golang v1.14.0 // indirect
141143
github.com/prometheus/client_model v0.3.0 // indirect
@@ -151,6 +153,7 @@ require (
151153
github.com/tonistiigi/vt100 v0.0.0-20210615222946-8066bb97264f // indirect
152154
github.com/toqueteos/trie v1.0.0 // indirect
153155
github.com/ulikunitz/xz v0.5.9 // indirect
156+
github.com/vbatts/tar-split v0.11.2 // indirect
154157
github.com/xanzy/ssh-agent v0.2.1 // indirect
155158
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
156159
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
@@ -161,11 +164,13 @@ require (
161164
go.opentelemetry.io/otel/sdk v1.4.1 // indirect
162165
go.opentelemetry.io/otel/trace v1.4.1 // indirect
163166
go.opentelemetry.io/proto/otlp v0.12.0 // indirect
164-
golang.org/x/oauth2 v0.0.0-20220718184931-c8730f7fcb92 // indirect
167+
golang.org/x/mod v0.8.0 // indirect
168+
golang.org/x/oauth2 v0.1.0 // indirect
165169
golang.org/x/sync v0.1.0 // indirect
166170
golang.org/x/sys v0.5.0 // indirect
167171
golang.org/x/term v0.5.0 // indirect
168172
golang.org/x/time v0.1.0 // indirect
173+
golang.org/x/tools v0.6.0 // indirect
169174
google.golang.org/appengine v1.6.7 // indirect
170175
google.golang.org/genproto v0.0.0-20220706185917-7780775163c4 // indirect
171176
gopkg.in/inf.v0 v0.9.1 // indirect

0 commit comments

Comments
 (0)