CUE 是一种开源数据约束语言,旨在简化涉及定义和使用数据的任务(The CUE Data Constraint Language)

CUE 是一种开源数据约束语言,旨在简化涉及定义和使用数据的任务。

BCL/CUE

BCL 全名 Borg Configuration Language,是 Google 内部基于 GCL (Generic Configuration Language) 在 Borg 场景的实践。用户通过 BCL 描述对 Borg 的使用需求,通过基于 BCL 的抽象省去对 Borg 复杂配置细节的感知提高单位效率,通过工程化手段满足可抽象、可复用、可测试的协作方式提高团队效率和稳定性,并在其上建立了相应的生态平台,作为 Borg 生态的重要抽象层在 Google 内部服务了超过 10 年,帮助 Google 内部数万开发者更好的使用 Infra。遗憾的是 BCL 并未开源,无法对 BCL 的实现、使用、生态做更多深入的解析。

CUE 是一种服务于云化配置的强类型配置语言,由 Go team 成员 Marcel van Lohiuzen 结合 BCL 及多种其他语言研发并开源,可以说是 BCL 思路的开源版实现。

The CUE Language Specification:https://github.com/cuelang/cue/blob/master/doc/ref/spec.md

CUE 延续了 JSON 超集的思路,额外提供了丰富的类型、表达式、import 语句等常用能力;与 JSONNET 不同,CUE 不支持自定义 function,支持基于 typed feature structure 思路的外置 schema,并通过显式的合一化、分离化操作支持类型和数据的融合,但这样的设定及外置类型推导同样增加了理解难度和编写复杂性。

CUE 项目完全由 Golang 编写,同时背靠 Golang,允许通过 “import” 引入 CUE 提供的必需能力协助用户完成如 encoding, strings, math 等配置编写常用功能。可以说 CUE 既属于 JSON 系的模板语言,同时也带有了很多 Configuration Language 的思考,提供了良好的样本,无论是其语言设计思路,还是基于成熟高级编程语言引入能力的工程方式都值得深入学习,但由于其部分设定过于晦涩也使得其难于理解,上手难度高。目前 CUE 在部分开源项目中使用,如在 ISTIO 中有小规模使用。

BCL 在 Google 内部虽然被广泛推广使用,但由于其语言特性定义不清晰、研发测试支持较差、新语言学习成本等问题在一线受到较多的吐槽。CUE 试图解决其中的语言特性问题,并提供了较为清晰的 spec 帮助使用者理解语言定义,但在研发测试支持、新语言理解难度、上手成本上没有较大的提升,使用者仍然无法较好的编写、测试,不能容易的 debug;语言自创的 schema 模板及大量私货写法对于使用者来说仍然意味着学习一种新的难写的语言,受众需要足够 geek 且有足够的耐心来让自己成为专家。归根到底模板定义区别于编程语言的一个重点就在于完善可编程性的缺失,这使得编写总会遇到这样那样的麻烦。

The CUE Data Constraint Language

Configure, Unify, Execute

CUE is an open source data constraint language which aims
to simplify tasks involving defining and using data.

It is a superset of JSON,
allowing users familiar with JSON to get started quickly.

What is it for?

You can use CUE to

  • define a detailed validation schema for your data (manually or automatically from data)
  • reduce boilerplate in your data (manually or automatically from schema)
  • extract a schema from code
  • generate type definitions and validation code
  • merge JSON in a principled way
  • define and run declarative scripts

How?

CUE merges the notion of schema and data.
The same CUE definition can simultaneously be used for validating data
and act as a template to reduce boilerplate.
Schema definition is enriched with fine-grained value definitions
and default values.
At the same time,
data can be simplified by removing values implied by such detailed definitions.
The merging of these two concepts enables
many tasks to be handled in a principled way.

Constraints provide a simple and well-defined, yet powerful, alternative
to inheritance,
a common source of complexity with configuration languages.

CUE Scripting

The CUE scripting layer defines declarative scripting, expressed in CUE,
on top of data.
This solves three problems:
working around the closedness of CUE definitions (we say CUE is hermetic),
providing an easy way to share common scripts and workflows for using data,
and giving CUE the knowledge of how data is used to optimize validation.

There are many tools that interpret data or use a specialized language for
a specific domain (Kustomize, Ksonnet).
This solves dealing with data on one level, but the problem it solves may repeat
itself at a higher level when integrating other systems in a workflow.
CUE scripting is generic and allows users to define any workflow.

Tooling

CUE is designed for automation.
Some aspects of this are:

  • convert existing YAML and JSON
  • automatically simplify configurations
  • rich APIs designed for automated tooling
  • formatter
  • arbitrary-precision arithmetic
  • generate CUE templates from source code
  • generate source code from CUE definitions (TODO)

Download and Install

Install using Homebrew

Using Homebrew, you can install using the CUE Homebrew tap:

brew install cuelang/tap/cue

Install From Source

If you already have Go installed, the short version is:

go get -u cuelang.org/go/cmd/cue

This will install the cue command line tool.

For more details see Installing CUE.

Learning CUE

The fastest way to learn the basics is to follow the
tutorial on basic language constructs.

A more elaborate tutorial demonstrating of how to convert and restructure
an existing set of Kubernetes configurations is available in
written form.

References

Contributing

Our canonical Git repository is located at https://cue.googlesource.com.

To contribute, please read the Contribution Guide.

To report issues or make a feature request, use the
issue tracker.

Changes can be contributed using Gerrit or Github pull requests.

Contact

You can get in touch with the cuelang community in the following ways:


Unless otherwise noted, the CUE source files are distributed
under the Apache 2.0 license found in the LICENSE file.

This is not an officially supported Google product.

参考资料:
https://github.com/cuelang/cue/blob/master/README.md
https://python.ctolib.com/cuelang-cue.html

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 218,386评论 6 506
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,142评论 3 394
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,704评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,702评论 1 294
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,716评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,573评论 1 305
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,314评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,230评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,680评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,873评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,991评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,706评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,329评论 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,910评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,038评论 1 270
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,158评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,941评论 2 355

推荐阅读更多精彩内容