/cuemod

experimental cuelang mod tool

Primary LanguageGoMIT LicenseMIT

CUE Mod

GoDoc Widget Go Report Card

ALPHA VERSION

May deprecated when cue modules official supported

dependency management for CUE without committing cue.mod

Requirements

  • git or other vcs tool supported by go for vcs downloading.

Install

go install github.com/octohelm/cuemod/cmd/cuem@latest

Usage

Quick Start

mkdir -p ./demo && cd ./demo

cat << EOT > kube.cue
package kube

import (
   apps_v1 "k8s.io/api/apps/v1"
)

deployment: [string]: apps_v1.#Deployment

_labels: { "app": "nginx" }

deployment: nginx: spec: selector: matchLabels: _labels
deployment: nginx: spec: template: metadata: labels: _labels
deployment: nginx: spec: template: spec: {
	containers: [{
		name: "nginx"
		image: "nginx:1.11.10-alpine"
	}]
}
EOT
 
cuem eval -o kube.yaml ./kube.cue
# build, will automately install deps if not exists or generator if needed.

cuem eval -o ./kube.single-file.cue ./kube.cue
# will bundle to one single cue file

Dependency management

# auto added deps
cuem get ./...

# upgrade deps
cuem get -u ./...

# install dep with special version
cuem get github.com/grafana/jsonnet-libs@latest

Features

  • Dependency management based on go modules
    • all dependency codes will download under $(go env GOMODCACHE)
    • GOPROXY supported to speed up downloading
  • Extract to cue pkg from other language or schema spec.
    • golang supported
    • k8s crd json supported

Spec cue.mod/module.cue

// module name
// for sub mod import, <module>/path/to/sub
// NOTICE: the module name should be a valid repo name
module: "github.com/octohelm/cuemod"

require: {
	"dagger.io":          "v0.2.8-0.20220512005159-64cb4f755695" 
	"k8s.io/api":         "v0.24.0" 
	"universe.dagger.io": "v0.2.8-0.20220512005159-64cb4f755695"
}

require: {
	"k8s.io/apimachinery": "v0.24.0" @indirect() 
}

replace: {
	// replace module with spec version
	"dagger.io":          "github.com/morlay/dagger/pkg/dagger.io@#release-main"
	"universe.dagger.io": "github.com/morlay/dagger/pkg/universe.dagger.io@#release-main"
	
	 // **notice** only works for current mod
    "github.com/x/a": "../a"
}

replace: {
	"k8s.io/api": "" @import("go")
	"k8s.io/apimachinery": "" @import("go")
}

Known issues

pkg name may not same as path

Some path like github.com/istio/istio/manifests/charts/istio-operator, the istio-operator is not a valid identifier in cue-lang. Should import with github.com/istio/istio/manifests/charts/istio-operator:istio_operator