本站支持搜索的镜像仓库:Docker Hub、gcr.io、ghcr.io、quay.io、k8s.gcr.io、registry.gcr.io、elastic.co、mcr.microsoft.com
mu-cl-resources提供符合JSONAPI规范的接口,用于访问配置中指定的内容。大部分配置在configuration/domain.json或configuration/domain.lisp文件中进行(可选择其一),本仓库中提供了相关示例。
大部分配置在领域文件中完成。参见configuration/domain.json和configuration/domain.lisp了解入门知识。该文件定义了JSON世界与RDF世界之间的连接。定义模型时,需明确两个世界的结构。
本文档内容并非详尽无遗。该组件可处理多种用例,并支持实验性的特殊功能(可能在后续版本纳入核心功能)。因此,本README未涵盖组件的所有功能。
domain.json格式仍在发展中,部分配置参数只能在Lisp版本中设置。可组合使用两种格式,参见教程:组合domain.lisp和domain.json。
在docker-compose.yml的services块中添加以下片段:
services: resource: image: semtech/mu-cl-resources:1.20.0 links: - db:database volumes: - ./config/resources:/config
接下来,将本仓库examples/文件夹中的配置文件复制到项目的./config/resources文件夹中。需复制JSON配置文件examples/domain.json或Lisp配置文件examples/domain.lisp和examples/repository.lisp。
最后,在项目的./config/dispatcher/dispatcher.ex的调度器配置中添加新规则,将/themes的请求转发到新的资源服务:
get "/themes/*path", @any do forward conn, path, "[***]" end
运行docker-compose up -d启动栈。假设标识符在80端口发布,向http://localhost/themes发送请求应返回来自mu-cl-resources的空数组。
由于mu.semte.ch项目通常包含mu-cl-resources,mu.semte.ch项目的默认蓝图mu-semtech/mu-project已集成mu-cl-resources。
该服务由domain.lisp文件驱动,需根据领域需求调整该文件。本节简要说明各部分如何协同工作,以及如何快速启动API。
mu-cl-resources由domain.lisp文件驱动。该文件描述JSONAPI与语义模型之间的连接。其次是repository.lisp文件,可在其中定义新前缀以简化领域描述。本仓库的examples文件夹中提供了这两个文件的示例。
domain.lisp包含应用中每种资源类型的定义。这些定义提供三向连接:
domain.lisp文件中命名事物以建立连接每个资源定义都是这三种视图的组合。假设使用foaf示例,建模一个拥有一个或多个在线账户的Person。可使用WebVOWL可视化该模型。
补充说明:mu-cl-resources主要通过Lisp配置。Lisp使用括号()进行内容分组。括号后接单词通常表示组的内容;无单词时通常为列表。其他字符如反引号(`)或逗号(,)建议从示例中复制使用。
(define-resource person () :class (s-url "[***]") :properties `((:name :string ,(s-url "[***]"))) :resource-base (s-url "[***]") :on-path "people")
一个简单的person定义使用foaf词汇表描述person和person name。
define-resource person表示创建一个新端点,在文件中命名为person(通常使用单数形式)。string类型的内容存储在data.attributes.name中(因:name),该值通过三元组存储中的谓词foaf:name与资源连接。注意属性名可包含连字符,但不区分大小写(忽略大写字母)。/people请求映射到该资源。假设定义了foaf前缀,可简化示例,使用s-prefix:
(define-resource person () :class (s-prefix "foaf:Person") :properties `((:name :string ,(s-prefix "foaf:name"))) :resource-base (s-url "[***]") :on-path "people")
此代码与上述示例功能相同,但更易读。
可添加多个属性,例如添加age属性(数字类型):
(define-resource person () :class (s-prefix "foaf:Person") :properties `((:name :string ,(s-prefix "foaf:name")) (:age :number ,(s-prefix "foaf:age"))) :resource-base (s-url "[***]") :on-path "people")
通过此修改,person支持name和age属性。
大多数资源链接到其他资源。首先定义第二个资源OnlineAccount:
(define-resource account () :class (s-prefix "foaf:OnlineAccount") :properties `((:name :string ,(s-prefix "foaf:accountName"))) :resource-base (s-url "[***]") :on-path "accounts")
account资源的定义与person类似。使用:has-many关键字将person链接到多个account:
(define-resource person () :class (s-prefix "foaf:Person") :properties `((:name :string ,(s-prefix "foaf:name")) (:age :number ,(s-prefix "foaf:age"))) :has-many `((account :via ,(s-prefix "foaf:account") :as "accounts")) :resource-base (s-url "[***]") :on-path "people")
第5-6行指定person可链接到多个account类型的资源。在三元组存储中,通过foaf:account谓词查找链接。该关系通过JSON API的关系名称"accounts"暴露,因此GET /people/42/accounts将返回UUID为42的person的账户。
使用:has-one关键字获取链接到account的person,并添加:inverse t选项表示沿相反方向跟踪关系:
(define-resource account () :class (s-prefix "foaf:OnlineAccount") :properties `((:name :string ,(s-prefix "foaf:accountName"))) :has-one `((person :via ,(s-prefix "foaf:account") :inverse t :as "owner")) :resource-base (s-url "[***]") :on-path "accounts")
完整的user和account设置如下:
(define-resource person () :class (s-prefix "foaf:Person") :properties `((:name :string ,(s-prefix "foaf:name")) (:age :number ,(s-prefix "foaf:age"))) :has-many `((account :via ,(s-prefix "foaf:account") :as "accounts")) :resource-base (s-url "[***]") :on-path "people") (define-resource account () :class (s-prefix "foaf:OnlineAccount") :properties `((:name :string ,(s-prefix "foaf:accountName"))) :has-one `((person :via ,(s-prefix "foaf:account") :inverse t :as "owner")) :resource-base (s-url "[***]") :on-path "accounts")
上述示例使用foaf前缀表示类和属性。/configuration/repositories.lisp允许定义自定义前缀,常用缩写可参考prefix.cc。
(add-prefix "foaf" "[***]")
支持JSONAPI规范,常见调用示例:
# GET /people
# GET /people/0b29a57a-d324-4302-9c92-61958e4cf250/accounts
# GET /people?filter=John
# GET /people?filter[age]=42
# GET /people?include=accounts
# GET /people?filter[:exact:name]=John%20Doe
# GET /people?sort=age
# GET /accounts?sort=-person.age
# POST /people/0b29a57a-d324-4302-9c92-61958e4cf250
# PATCH /people/0b29a57a-d324-4302-9c92-61958e4cf250
# PATCH /people/0b29a57a-d324-4302-9c92-61958e4cf250/relationships/accounts
# DELETE /people/0b29a57a-d324-4302-9c92-61958e4cf250/relationships/accounts
# DELETE /people/0b29a57a-d324-4302-9c92-61958e4cf250
defparameter表达式指定。:class同级的:features关键字可指定修改特定资源行为的选项。mu-cl-resources通过domain.json文件驱动,该文件描述JSONAPI与语义模型之间的连接。本仓库的examples文件夹中提供了示例文件。
domain.json包含应用中每种资源类型的定义,提供三向连接(命名事物、描述JSON属性、描述语义模型)。
{ "version": "0.1", "resources": { "people": { "name": "person", "class": "[***]", "attributes": { "name": { "type": "string", "predicate": "[***]" } }, "new-resource-base": "[***]" } } }
使用前缀简化配置:
{ "version": "0.1", "prefixes": { "foaf": "[***]" }, "resources": { "people": { "name": "person", "class": "foaf:Person", "attributes": { "name": { "type": "string", "predicate": "foaf:name" } }, "new-resource-base": "[***]" } } }
添加多个属性(如age):
{ "version": "0.1", "prefixes": { "foaf": "[***]" }, "resources": { "people": { "name": "person", "class": "foaf:Person", "attributes": { "name": { "type": "string", "predicate": "foaf:name" }, "age": { "type": "number", "predicate": "foaf:age" } }, "new-resource-base": "[***]" } } }
定义关系(如person拥有多个account):
{ "version": "0.1", "prefixes": { "foaf": "[***]" }, "resources": { "people": { "name": "person", "class": "foaf:Person", "attributes": { "name": { "type": "string", "predicate": "foaf:name" }, "age": { "type": "number", "predicate": "foaf:age" } }, "relationships": { "accounts": { "predicate": "foaf:account", "target": "account", "cardinality": "many" } }, "new-resource-base": "[***]" }, "accounts": { "name": "account", "class": "foaf:OnlineAccount", "attributes": { "name": { "type": "string", "predicate": "foaf:accountName" } }, "relationships": { "owner": { "predicate": "foaf:account", "target": "person", "cardinality": "one", "inverse": true } }, "new-resource-base": "[***]" } } }
对于大型应用,可将领域定义分散到多个文件。根领域文件必须为Lisp格式,包含的文件可以是Lisp或JSON格式。在domain.lisp顶部添加read-domain-file语句:
(in-package :mu-cl-resources) (read-domain-file "users.json") (read-domain-file "publications.lisp")
重启服务后,mu-cl-resources将加载额外配置文件。
若使用domain.json定义资源,需创建domain.lisp文件并添加:
(in-package :mu-cl-resources) (read-domain-file "domain.json")
在domain.lisp中添加设置,重启服务后生效。
define-resource结构用于定义资源,示例:
(define-resource person () :class (s-prefix "foaf:Person") :properties `((:name :string ,(s-prefix "foaf:name") :required) (:age :number ,(s-url "[***]"))) :has-one `((location :via ,(s-prefix "foaf:based_near") :as "location")) :has-many `((account :via ,(s-prefix "foaf:account") :as "accounts") (document :via ,(s-prefix "foaf:publications") :as "publications")) :features '(include-uri) :resource-base (s-url "[***]") :on-path "people")
:class:设置实例所属的RDF类。:properties:描述资源属性(对应JSON attributes)。:has-one:描述最多一个的关系。:has-many:描述零个或多个的关系。:features:资源使用的可选功能(如include-uri返回URI)。:resource-base:新资源的URI前缀。免费版仅支持 Docker Hub 加速,不承诺可用性和速度;专业版支持更多镜像源,保证可用性和稳定速度,提供优先客服响应。
免费版仅支持 docker.io;专业版支持 docker.io、gcr.io、ghcr.io、registry.k8s.io、nvcr.io、quay.io、mcr.microsoft.com、docker.elastic.co 等。
当返回 402 Payment Required 错误时,表示流量已耗尽,需要充值流量包以恢复服务。
通常由 Docker 版本过低导致,需要升级到 20.x 或更高版本以支持 V2 协议。
先检查 Docker 版本,版本过低则升级;版本正常则验证镜像信息是否正确。
使用 docker tag 命令为镜像打上新标签,去掉域名前缀,使镜像名称更简洁。
探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录方式配置轩辕镜像加速服务,包含7个详细步骤
在 Linux 系统上配置轩辕镜像源,支持主流发行版
在 Docker Desktop 中配置轩辕镜像加速,适用于桌面系统
在 Docker Compose 中使用轩辕镜像加速,支持容器编排
在 k8s 中配置 containerd 使用轩辕镜像加速
在宝塔面板中配置轩辕镜像加速,提升服务器管理效率
在 Synology 群晖NAS系统中配置轩辕镜像加速
在飞牛fnOS系统中配置轩辕镜像加速
在极空间NAS中配置轩辕镜像加速
在爱快ikuai系统中配置轩辕镜像加速
在绿联NAS系统中配置轩辕镜像加速
在威联通NAS系统中配置轩辕镜像加速
在 Podman 中配置轩辕镜像加速,支持多系统
配置轩辕镜像加速9大主流镜像仓库,包含详细配置步骤
无需登录即可使用轩辕镜像加速服务,更加便捷高效
需要其他帮助?请查看我们的 常见问题 或 官方QQ群: 13763429