{"id":7046,"date":"2024-10-11T13:51:17","date_gmt":"2024-10-11T05:51:17","guid":{"rendered":"https:\/\/www.aisharenet.com\/?p=7046"},"modified":"2024-10-11T13:51:17","modified_gmt":"2024-10-11T05:51:17","slug":"cloudflare-serverless-registry","status":"publish","type":"post","link":"https:\/\/www.kdjingpai.com\/en\/cloudflare-serverless-registry\/","title":{"rendered":"Cloudflare Serverless Registry\uff1a\u57fa\u4e8eCloudflare Workers\u7684\u65e0\u670d\u52a1\u5668\u5bb9\u5668\u6ce8\u518c\u8868"},"content":{"rendered":"<p>Cloudflare Serverless Registry \u662f\u4e00\u4e2a\u57fa\u4e8e Cloudflare Workers \u548c R2 \u5b58\u50a8\u7684\u65e0\u670d\u52a1\u5668\u5bb9\u5668\u6ce8\u518c\u8868\u3002\u5b83\u652f\u6301\u955c\u50cf\u7684\u63a8\u9001\u548c\u62c9\u53d6\uff0c\u5e76\u63d0\u4f9b\u7528\u6237\u540d\u5bc6\u7801\u548c\u57fa\u4e8e\u516c\u94a5\u7684 JWT \u8ba4\u8bc1\u3002\u8be5\u9879\u76ee\u6613\u4e8e\u90e8\u7f72\uff0c\u517c\u5bb9 Docker \u64cd\u4f5c\uff0c\u9002\u5408\u5728\u65e0\u670d\u52a1\u5668\u73af\u5883\u4e2d\u7ba1\u7406\u5bb9\u5668\u955c\u50cf\u3002\u5c3d\u7ba1\u5b58\u5728\u4e00\u4e9b\u9650\u5236\uff0cServerless Registry \u4ecd\u4e3a\u5f00\u53d1\u8005\u63d0\u4f9b\u4e86\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u4e14\u53ef\u6269\u5c55\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u529f\u80fd\u5217\u8868<\/h2>\n<ul>\n<li>\u652f\u6301\u955c\u50cf\u63a8\u9001\u548c\u62c9\u53d6<\/li>\n<li>\u63d0\u4f9b\u7528\u6237\u540d\u5bc6\u7801\u548c JWT \u8ba4\u8bc1<\/li>\n<li>\u517c\u5bb9 Docker \u64cd\u4f5c<\/li>\n<li>\u652f\u6301\u56de\u9000\u5230\u5176\u4ed6\u6ce8\u518c\u8868<\/li>\n<li>\u6613\u4e8e\u90e8\u7f72\u548c\u7ba1\u7406<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>\u4f7f\u7528\u5e2e\u52a9<\/h2>\n<h3>\u5b89\u88c5\u548c\u90e8\u7f72<\/h3>\n<ol>\n<li><strong>\u5b89\u88c5\u4f9d\u8d56\u9879<\/strong>\uff1a\u4f7f\u7528 pnpm \u5b89\u88c5\u6240\u6709\u4f9d\u8d56\u9879\uff08\u5176\u4ed6\u5305\u7ba1\u7406\u5668\u53ef\u80fd\u4e5f\u53ef\u4ee5\u4f7f\u7528\uff0c\u4f46\u53ea\u652f\u6301 pnpm\uff09\u3002\n<pre><code class=\"language-bash\">$ pnpm install\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u51c6\u5907 wrangler \u6587\u4ef6<\/strong>\uff1a\u590d\u5236\u793a\u4f8b\u6587\u4ef6\u5e76\u8fdb\u884c\u914d\u7f6e\u3002\n<pre><code class=\"language-bash\">$ <span class=\"hljs-built_in\">cp<\/span> wrangler.toml.example wrangler.toml\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u8bbe\u7f6e R2 \u5b58\u50a8\u6876<\/strong>\uff1a\u521b\u5efa R2 \u5b58\u50a8\u6876\u3002\n<pre><code class=\"language-bash\">$ npx wrangler --<span class=\"hljs-built_in\">env<\/span> production r2 bucket create r2-registry\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u914d\u7f6e wrangler.toml<\/strong>\uff1a\u5728 wrangler.toml \u6587\u4ef6\u4e2d\u6dfb\u52a0 R2 \u5b58\u50a8\u6876\u914d\u7f6e\u3002\n<pre><code class=\"language-toml\"><span class=\"hljs-attr\">r2_buckets<\/span> = [\r\n  { binding = <span class=\"hljs-string\">\"REGISTRY\"<\/span>, bucket_name = <span class=\"hljs-string\">\"r2-registry\"<\/span> }\r\n]\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u90e8\u7f72\u6ce8\u518c\u8868<\/strong>\uff1a\u5c06\u6ce8\u518c\u8868\u90e8\u7f72\u5230\u751f\u4ea7\u73af\u5883\u3002\n<pre><code class=\"language-bash\">$ npx wrangler deploy --<span class=\"hljs-built_in\">env<\/span> production\r\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<h3>\u7528\u6237\u540d\u5bc6\u7801\u8ba4\u8bc1<\/h3>\n<ol>\n<li><strong>\u8bbe\u7f6e\u7528\u6237\u540d\u548c\u5bc6\u7801<\/strong>\uff1a\u5c06\u7528\u6237\u540d\u548c\u5bc6\u7801\u8bbe\u7f6e\u4e3a\u673a\u5bc6\u3002\n<pre><code class=\"language-bash\">$ npx wrangler secret put USERNAME --<span class=\"hljs-built_in\">env<\/span> production\r\n$ npx wrangler secret put PASSWORD --<span class=\"hljs-built_in\">env<\/span> production\r\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<h3>JWT \u8ba4\u8bc1<\/h3>\n<ol>\n<li><strong>\u6dfb\u52a0 JWT \u516c\u94a5<\/strong>\uff1a\u6dfb\u52a0 base64 \u7f16\u7801\u7684 JWT \u516c\u94a5\u4ee5\u9a8c\u8bc1\u5bc6\u7801\u6216\u4ee4\u724c\u3002\n<pre><code class=\"language-bash\">$ npx wrangler secret put JWT_REGISTRY_TOKENS_PUBLIC_KEY --<span class=\"hljs-built_in\">env<\/span> production\r\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<h3>\u4f7f\u7528 Docker \u63a8\u9001\u548c\u62c9\u53d6\u955c\u50cf<\/h3>\n<ol>\n<li><strong>\u767b\u5f55 Docker<\/strong>\uff1a\u4f7f\u7528\u7528\u6237\u540d\u548c\u5bc6\u7801\u767b\u5f55 Docker\u3002\n<pre><code class=\"language-bash\"><span class=\"hljs-built_in\">export<\/span> REGISTRY_URL=your-url-here\r\n<span class=\"hljs-built_in\">echo<\/span> <span class=\"hljs-variable\">$PASSWORD<\/span> | docker login --username <span class=\"hljs-variable\">$USERNAME<\/span> --password-stdin <span class=\"hljs-variable\">$REGISTRY_URL<\/span>\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u63a8\u9001\u955c\u50cf<\/strong>\uff1a\u63a8\u9001\u955c\u50cf\u5230\u6ce8\u518c\u8868\u3002\n<pre><code class=\"language-bash\">docker pull ubuntu:latest\r\ndocker tag ubuntu:latest <span class=\"hljs-variable\">$REGISTRY_URL<\/span>\/ubuntu:latest\r\ndocker push <span class=\"hljs-variable\">$REGISTRY_URL<\/span>\/ubuntu:latest\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u62c9\u53d6\u955c\u50cf<\/strong>\uff1a\u4ece\u6ce8\u518c\u8868\u62c9\u53d6\u955c\u50cf\u3002\n<pre><code class=\"language-bash\">docker rmi ubuntu:latest\r\ndocker pull <span class=\"hljs-variable\">$REGISTRY_URL<\/span>\/ubuntu:latest\r\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<h3>\u914d\u7f6e\u62c9\u53d6\u56de\u9000<\/h3>\n<ol>\n<li><strong>\u8bbe\u7f6e\u56de\u9000\u6ce8\u518c\u8868<\/strong>\uff1a\u5728 wrangler.toml \u6587\u4ef6\u4e2d\u914d\u7f6e\u56de\u9000\u6ce8\u518c\u8868\u3002\n<pre><code class=\"language-toml\"><span class=\"hljs-section\">[env.production]<\/span>\r\n<span class=\"hljs-attr\">REGISTRIES_JSON<\/span> = <span class=\"hljs-string\">\"[{ \\\"registry\\\": \\\"url-to-other-registry\\\", \\\"password_env\\\": \\\"REGISTRY_TOKEN\\\", \\\"username\\\": \\\"username-to-use\\\" }]\"<\/span>\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u8bbe\u7f6e\u6ce8\u518c\u8868\u4ee4\u724c<\/strong>\uff1a\u5c06\u6ce8\u518c\u8868\u4ee4\u724c\u8bbe\u7f6e\u4e3a\u673a\u5bc6\u3002\n<pre><code class=\"language-bash\"><span class=\"hljs-built_in\">cat<\/span> .\/registry-service-credentials.json | <span class=\"hljs-built_in\">base64<\/span> | wrangler --<span class=\"hljs-built_in\">env<\/span> production secrets put REGISTRY_TOKEN\r\n<\/code><\/pre>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Cloudflare Serverless Registry \u662f\u4e00\u4e2a\u57fa\u4e8e Cloudflare Workers \u548c R2 \u5b58\u50a8\u7684\u65e0\u670d\u52a1\u5668\u5bb9\u5668\u6ce8\u518c\u8868\u3002\u5b83\u652f\u6301\u955c\u50cf\u7684\u63a8\u9001\u548c\u62c9\u53d6\uff0c\u5e76\u63d0\u4f9b\u7528\u6237\u540d\u5bc6\u7801\u548c\u57fa\u4e8e\u516c\u94a5\u7684 JWT \u8ba4\u8bc1\u3002\u8be5\u9879\u76ee\u6613\u4e8e\u90e8\u7f72\uff0c\u517c\u5bb9 D&#8230;<\/p>\n","protected":false},"author":1,"featured_media":61090,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[230],"class_list":["post-7046","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tool","tag-aikaiyuanxiangmu"],"_links":{"self":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts\/7046","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/comments?post=7046"}],"version-history":[{"count":0,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts\/7046\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/media\/61090"}],"wp:attachment":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/media?parent=7046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/categories?post=7046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/tags?post=7046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}