Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,15 @@ deploy: ## 🚀 Deploy to k8s context defined by $KUBECTX (default: kind-rig)
--set image.tag=$(TAG) \
--set mongodb.enabled=true \
--set rig.telemetry.enabled=false \
--set rig.cluster.dev_registry.host="localhost:30000" \
--set rig.cluster.dev_registry.cluster_host="registry:5000" \
--create-namespace
$(KUBECTL) rollout restart deployment -n rig-system rig

.PHONY: kind-create
kind-create: kind ## 🐋 Create kind cluster with rig dependencies
$(KIND) get clusters | grep '^rig$$' || \
$(KIND) create cluster --name rig
./deploy/kind/create.sh $(KIND)

.PHONY: kind-load
kind-load: kind docker ## 🐋 Load docker image into kind cluster
Expand All @@ -159,6 +161,10 @@ kind-deploy: kind kind-load deploy ## 🐋 Deploy rig to kind cluster
kind-clean: ## 🧹 Clean kind cluster
$(KIND) delete clusters rig

.PHONY: kind-registry
kind-registry: ## 🐋 Install docker registry in
$(KUBECTL) apply -f ./deploy/registry/registry.yaml -n rig-system

##@ Release

.PHONY: release
Expand Down
3 changes: 1 addition & 2 deletions cmd/rig-server/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import (
"github.com/rigdev/rig/internal/handler"
"github.com/rigdev/rig/internal/handler/registry"
"github.com/rigdev/rig/internal/service/operator"
"github.com/spf13/cobra"

pkg_service "github.com/rigdev/rig/pkg/service"
"github.com/spf13/cobra"
"go.uber.org/dig"
"go.uber.org/fx"
"go.uber.org/fx/fxevent"
Expand Down
5 changes: 3 additions & 2 deletions cmd/rig/cmd/capsule/create_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ func CapsuleCreateBuild(ctx context.Context, cmd *cobra.Command, args []string,
var buildID string
if res, err := nc.Capsule().CreateBuild(ctx, &connect.Request[capsule.CreateBuildRequest]{
Msg: &capsule.CreateBuildRequest{
CapsuleId: capsuleID.String(),
Image: image,
CapsuleId: capsuleID.String(),
Image: image,
SkipImageCheck: skipImageCheck,
},
}); err != nil {
return err
Expand Down
10 changes: 6 additions & 4 deletions cmd/rig/cmd/capsule/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ var (
)

var (
deploy bool
follow bool
interactive bool
outputJSON bool
deploy bool
follow bool
interactive bool
outputJSON bool
skipImageCheck bool
)

var (
Expand Down Expand Up @@ -70,6 +71,7 @@ func Setup(parent *cobra.Command) {
}
createBuild.Flags().StringVarP(&image, "image", "i", "", "image to use for the build")
createBuild.Flags().BoolVarP(&deploy, "deploy", "d", false, "deploy build after successful creation")
createBuild.Flags().BoolVarP(&skipImageCheck, "skip-image-check", "s", false, "skip validating that the docker image exists")
capsule.AddCommand(createBuild)

deploy := &cobra.Command{
Expand Down
6 changes: 6 additions & 0 deletions deploy/charts/rig/templates/_config.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ client:
{{- end }}
cluster:
type: k8s
{{- with .Values.rig.cluster.dev_registry }}
dev_registry:
Comment thread
MatiasFrank marked this conversation as resolved.
enabled: {{ .enabled }}
host: {{ .host }}
cluster_host: {{ .cluster_host }}
{{- end }}
{{- with .Values.rig.email }}
email:
type: {{ .type | quote }}
Expand Down
13 changes: 13 additions & 0 deletions deploy/kind/create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

cat <<EOF | $1 create cluster --name rig --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 30000
hostPort: 30000
listenAddress: "127.0.0.1"
protocol: TCP
EOF
38 changes: 38 additions & 0 deletions deploy/registry/registry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
run: registry
name: registry
namespace: rig-system
spec:
replicas: 1
selector:
matchLabels:
run: registry
template:
metadata:
labels:
run: registry
spec:
containers:
- name: registry
image: registry:2
ports:
- containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
name: registry
namespace: rig-system
spec:
type: NodePort
selector:
run: registry
ports:
- name: registry-tcp
nodePort: 30000
protocol: TCP
port: 5000
targetPort: 5000
9 changes: 8 additions & 1 deletion internal/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,14 @@ type OAuthClientCredentials struct {
}

type Cluster struct {
Type ClusterType `mapstructure:"type"`
Type ClusterType `mapstructure:"type"`
DevRegistry DevRegistry `mapstructure:"dev_registry"`
}

type DevRegistry struct {
Host string `mapstructure:"host"`
ClusterHost string `mapstructure:"cluster_host"`
Size uint64 `mapstructure:"size"`
}

type ClusterType string
Expand Down
24 changes: 23 additions & 1 deletion internal/service/capsule/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ func (s *Service) validateImage(ctx context.Context, ref name.Reference) (string
}))
}

img, err := remote.Image(ref, opts...)
lookupRef, err := s.getLookupDockerRef(ref)
if err != nil {
return "", err
}
img, err := remote.Image(lookupRef, opts...)
if err != nil {
if terr, ok := err.(*transport.Error); ok {
if len(terr.Errors) > 0 {
Expand All @@ -111,3 +115,21 @@ func (s *Service) validateImage(ctx context.Context, ref name.Reference) (string

return d.String(), nil
}

func (s *Service) getLookupDockerRef(ref name.Reference) (name.Reference, error) {
cfg := s.cfg.Cluster.DevRegistry
if cfg.Host == "" || cfg.ClusterHost == "" {
return ref, nil
}

if ref.Context().RegistryStr() != cfg.Host {
return ref, nil
}

r, err := name.NewRegistry(cfg.ClusterHost, name.Insecure)
if err != nil {
return nil, err
}
repo := r.Repo(ref.Context().RepositoryStr())
return repo.Tag(ref.Identifier()), nil
}
5 changes: 4 additions & 1 deletion internal/service/capsule/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/rigdev/rig-go-api/api/v1/capsule"
"github.com/rigdev/rig-go-api/model"
"github.com/rigdev/rig/internal/config"
"github.com/rigdev/rig/internal/gateway/cluster"
"github.com/rigdev/rig/internal/repository"
"github.com/rigdev/rig/internal/service/auth"
Expand All @@ -24,16 +25,18 @@ type Service struct {
as *auth.Service
ps project.Service
q *Queue[Job]
cfg config.Config
}

func NewService(cr repository.Capsule, sr repository.Secret, cg cluster.Gateway, as *auth.Service, ps project.Service, logger *zap.Logger) *Service {
func NewService(cr repository.Capsule, sr repository.Secret, cg cluster.Gateway, as *auth.Service, ps project.Service, cfg config.Config, logger *zap.Logger) *Service {
s := &Service{
cr: cr,
sr: sr,
cg: cg,
as: as,
ps: ps,
q: NewQueue[Job](),
cfg: cfg,
logger: logger,
}

Expand Down