-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from adrianliechti/feature/registry
Include Registry
- Loading branch information
Showing
6 changed files
with
264 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package cluster | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
|
||
"github.com/adrianliechti/devkube/app" | ||
"github.com/adrianliechti/devkube/pkg/cli" | ||
"github.com/adrianliechti/devkube/pkg/kubectl" | ||
) | ||
|
||
func RegistryCommand() *cli.Command { | ||
return &cli.Command{ | ||
Name: "registry", | ||
Usage: "Connect Registry", | ||
|
||
Flags: []cli.Flag{ | ||
app.ProviderFlag, | ||
app.ClusterFlag, | ||
app.PortFlag, | ||
}, | ||
|
||
Before: func(c *cli.Context) error { | ||
if _, _, err := kubectl.Info(c.Context); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
|
||
Action: func(c *cli.Context) error { | ||
provider, cluster := app.MustCluster(c) | ||
|
||
kubeconfig, closer := app.MustClusterKubeconfig(c, provider, cluster) | ||
defer closer() | ||
|
||
port := 5000 | ||
|
||
if runtime.GOOS == "darwin" { | ||
port = 5001 | ||
} | ||
|
||
port = app.MustPortOrRandom(c, port) | ||
|
||
cli.Info("Configure Docker to use this registry") | ||
cli.Info(" {") | ||
cli.Info(" ...") | ||
cli.Info(" \"insecure-registries\": [") | ||
cli.Infof(" \"localhost:%d\",", port) | ||
cli.Infof(" \"host.docker.internal:%d\"", port) | ||
cli.Info(" ]") | ||
cli.Info(" ...") | ||
cli.Info(" }") | ||
cli.Info(" (see https://docs.docker.com/registry/insecure/#deploy-a-plain-http-registry)") | ||
cli.Info() | ||
cli.Info() | ||
cli.Info("Push an image") | ||
cli.Infof(" docker tag my-image host.docker.internal:%d/my-image", port) | ||
cli.Infof(" docker push host.docker.internal:%d/my-image", port) | ||
cli.Info() | ||
cli.Info("Push an image (not using BuildKit)") | ||
cli.Infof(" docker tag my-image localhost:%d/my-image", port) | ||
cli.Infof(" docker push localhost:%d/my-image", port) | ||
cli.Info() | ||
cli.Info() | ||
|
||
if err := kubectl.Invoke(c.Context, []string{"port-forward", "service/registry", fmt.Sprintf("%d:80", port)}, kubectl.WithKubeconfig(kubeconfig), kubectl.WithNamespace(DefaultNamespace), kubectl.WithDefaultOutput()); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package registry | ||
|
||
import ( | ||
"context" | ||
_ "embed" | ||
"strings" | ||
|
||
"github.com/adrianliechti/devkube/pkg/kubectl" | ||
) | ||
|
||
var ( | ||
//go:embed registry.yaml | ||
manifest string | ||
) | ||
|
||
func Install(ctx context.Context, kubeconfig, namespace string) error { | ||
if namespace == "" { | ||
namespace = "default" | ||
} | ||
|
||
return kubectl.Invoke(ctx, []string{"apply", "-f", "-"}, kubectl.WithKubeconfig(kubeconfig), kubectl.WithNamespace(namespace), kubectl.WithInput(strings.NewReader(manifest)), kubectl.WithDefaultOutput()) | ||
} | ||
|
||
func Uninstall(ctx context.Context, kubeconfig, namespace string) error { | ||
if namespace == "" { | ||
namespace = "default" | ||
} | ||
|
||
return kubectl.Invoke(ctx, []string{"delete", "-f", "-"}, kubectl.WithKubeconfig(kubeconfig), kubectl.WithNamespace(namespace), kubectl.WithInput(strings.NewReader(manifest)), kubectl.WithDefaultOutput()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
apiVersion: cert-manager.io/v1 | ||
kind: Certificate | ||
metadata: | ||
name: registry | ||
labels: | ||
app: registry | ||
spec: | ||
secretName: registry-tls | ||
dnsNames: | ||
- registry.loop | ||
- registry | ||
- localhost | ||
issuerRef: | ||
name: platform | ||
kind: Issuer | ||
group: cert-manager.io | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: registry | ||
labels: | ||
app: registry | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: registry | ||
template: | ||
metadata: | ||
labels: | ||
app: registry | ||
spec: | ||
containers: | ||
- name: registry | ||
image: registry:2 | ||
env: | ||
- name: REGISTRY_HTTP_ADDR | ||
value: 0.0.0.0:80 | ||
ports: | ||
- containerPort: 80 | ||
volumeMounts: | ||
- name: data | ||
mountPath: /var/lib/registry | ||
resources: {} | ||
- name: proxy | ||
image: adrianliechti/loop-proxy | ||
args: | ||
- "-port" | ||
- "443" | ||
- "-target" | ||
- "http://localhost" | ||
- "-key-file" | ||
- "certs/tls.key" | ||
- "-cert-file" | ||
- "certs/tls.crt" | ||
ports: | ||
- containerPort: 443 | ||
volumeMounts: | ||
- name: certs | ||
mountPath: "/app/certs" | ||
resources: {} | ||
volumes: | ||
- name: data | ||
persistentVolumeClaim: | ||
claimName: registry | ||
- name: certs | ||
secret: | ||
secretName: registry-tls | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: registry | ||
labels: | ||
app: registry | ||
spec: | ||
type: ClusterIP | ||
selector: | ||
app: registry | ||
ports: | ||
- name: http | ||
port: 80 | ||
targetPort: 80 | ||
- name: https | ||
port: 443 | ||
targetPort: 443 | ||
--- | ||
kind: PersistentVolumeClaim | ||
apiVersion: v1 | ||
metadata: | ||
name: registry | ||
labels: | ||
app: registry | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 8Gi | ||
--- | ||
apiVersion: apps/v1 | ||
kind: DaemonSet | ||
metadata: | ||
name: registry-proxy | ||
labels: | ||
app: registry-proxy | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: registry-proxy | ||
template: | ||
metadata: | ||
labels: | ||
app: registry-proxy | ||
spec: | ||
hostPID: true | ||
initContainers: | ||
- name: init | ||
image: busybox | ||
securityContext: | ||
privileged: true | ||
command: | ||
- nsenter | ||
- --mount=/proc/1/ns/mnt | ||
- -- | ||
- sh | ||
- -c | ||
- "grep -q 'registry' /etc/hosts || echo 127.88.0.10 registry registry.loop >> /etc/hosts" | ||
containers: | ||
- name: proxy | ||
image: adrianliechti/loop-proxy | ||
args: | ||
- "-port" | ||
- "443" | ||
- "-target" | ||
- "http://registry" | ||
- "-key-file" | ||
- "certs/tls.key" | ||
- "-cert-file" | ||
- "certs/tls.crt" | ||
ports: | ||
- containerPort: 443 | ||
hostIP: 127.88.0.10 | ||
hostPort: 443 | ||
volumeMounts: | ||
- name: certs | ||
mountPath: "/app/certs" | ||
resources: {} | ||
volumes: | ||
- name: certs | ||
secret: | ||
secretName: registry-tls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters