{"id":208248,"date":"2025-07-08T17:34:01","date_gmt":"2025-07-08T09:34:01","guid":{"rendered":"https:\/\/server.hk\/cnblog\/208248\/"},"modified":"2025-07-08T17:34:01","modified_gmt":"2025-07-08T09:34:01","slug":"%e5%9c%a8-google-cloud-build-%e4%b8%8a%e9%83%a8%e7%bd%b2-golang-appengine-%e4%bc%9a%e4%ba%a7%e7%94%9f%e6%97%a0%e9%99%90%e6%9e%84%e5%bb%ba","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/208248\/","title":{"rendered":"\u5728 Google Cloud Build \u4e0a\u90e8\u7f72 Golang AppEngine \u4f1a\u4ea7\u751f\u65e0\u9650\u6784\u5efa"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u5728 Google Cloud Build \u4e0a\u90e8\u7f72 Golang AppEngine \u4f1a\u4ea7\u751f\u65e0\u9650\u6784\u5efa<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-30 18:12:36<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u6765\u5230\u7684\u5927\u5bb6\uff0c\u76f8\u4fe1\u90fd\u662f\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5e0c\u671b\u5728\u8fd9\u91cc\u5b66\u4e60Golang\u76f8\u5173\u7f16\u7a0b\u77e5\u8bc6\u3002\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u5e26\u5927\u5bb6\u804a\u804a\u300a\u5728 Google Cloud Build \u4e0a\u90e8\u7f72 Golang AppEngine \u4f1a\u4ea7\u751f\u65e0\u9650\u6784\u5efa\u300b\uff0c\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6b63\u5728\u5c1d\u8bd5\u8bbe\u7f6e cloud build \u7ba1\u9053\u4ee5\u5c06 <code>golang<\/code> \u5e94\u7528\u90e8\u7f72\u5230 app engine\uff0c\u4f46\u5b83\u4f3c\u4e4e\u4f1a\u751f\u6210\u65e0\u9650\u7248\u672c\u7684\u81ea\u8eab\uff0c\u7136\u540e\u8d85\u65f6\u3002<\/p>\n<p>\u9996\u5148\uff0c\u8fd9\u662f\u6211\u7684\u914d\u7f6e\u3002<\/p>\n<pre>steps:\n- name: \"gcr.io\/cloud-builders\/go\"\n  args:\n    - get\n    - \"-u\"\n    - \"-d\"\n    - \"github.com\/didip\/tollbooth\"\n    - \"github.com\/lib\/pq\"\n    - \"github.com\/stretchr\/testify\"\n    - \"github.com\/go-redis\/redis\"\n    - \"cloud.google.com\/go\/pubsub\"\n  dir: \"\/workspace\"\n  volumes:\n    - name: 'go'\n      path: '\/gopath'\n  env:\n    - \"gopath=\/gopath\"\n- name: \"gcr.io\/cloud-builders\/gcloud\"\n  args: [\"app\", \"deploy\", \"--stop-previous-version\"]\n  dir: \"\/workspace\"\n  volumes:\n    - name: 'go'\n      path: '\/gopath'\n  env:\n    - \"gopath=\/gopath\"<\/pre>\n<p>\u8fd9\u662f <code>app.yaml<\/code> \u7684\u76f8\u5173\u90e8\u5206\uff1a<\/p>\n<pre>service: \"myservice\"\nruntime: custom\nenv: flex<\/pre>\n<p>\u5f53\u6211\u90e8\u7f72\u5230\u5206\u652f\u65f6\uff0c\u6211\u5df2\u5c06\u5176\u914d\u7f6e\u4e3a\u76d1\u89c6\uff0c\u5b83\u5f88\u597d\u5730\u5f00\u59cb\u6784\u5efa\uff0c\u5e76\u5b8c\u6210\u6b65\u9aa4 0\u3002\u7136\u540e\u5b83\u5f00\u59cb\u6b65\u9aa4 1\uff0c\u5373 <code>gcloud \u5e94\u7528\u7a0b\u5e8f\u90e8\u7f72<\/code>\uff0c\u5b83\u4f3c\u4e4e\u9012\u5f52\u5730\u751f\u6210\u53e6\u4e00\u4e2a\u5b9e\u4f8b\u7ba1\u9053\uff08\u53c2\u89c1\u4e0b\u9762\u7684\u65e5\u5fd7\uff09\u3002\u8fd9\u4e00\u76f4\u6301\u7eed\u5230\u4e00\u5207\u8d85\u65f6\u4e3a\u6b62\u3002<\/p>\n<p>\u8fd9\u662f\u65e5\u5fd7\u7684\u5f00\u5934\uff08\u5230\u6700\u540e\u60a8\u4f1a\u770b\u5230\u5b83\u518d\u6b21\u5728\u6b65\u9aa4 1 \u4e2d\u9012\u5f52\u5730\u5f00\u59cb\u6b65\u9aa4 0\uff09\u3002<\/p>\n<pre>starting build \"e5ad47ed-5332-4bc7-b4ac-618e243f05a5\"\n\nfetchsource\nfetching storage object: gs:\/\/staging.myproject-event.appspot.com\/asia.gcr.io\/myproject-event\/appengine\/myservice.20190130t095428:latest#1548842070817530\ncopying gs:\/\/staging.myproject-event.appspot.com\/asia.gcr.io\/myproject-event\/appengine\/myservice.20190130t095428:latest#1548842070817530...\n\/ [0 files][ 0.0 b\/ 10.9 kib] \n-\n- [1 files][ 10.9 kib\/ 10.9 kib] \noperation completed over 1 objects\/10.9 kib. \nbuild\nstarting step #0\nstep #0: already have image (with digest): gcr.io\/cloud-builders\/go\nstep #0: documentation at https:\/\/github.com\/googlecloudplatform\/cloud-builders\/blob\/master\/go\/readme.md\nstep #0: running: go get -u -d github.com\/didip\/tollbooth github.com\/lib\/pq github.com\/stretchr\/testify github.com\/go-redis\/redis cloud.google.com\/go\/pubsub\nfinished step #0\nstarting step #1\nstep #1: already have image (with digest): gcr.io\/cloud-builders\/gcloud\nstep #1: services to deploy:\nstep #1: \nstep #1: descriptor: [\/workspace\/app.yaml]\nstep #1: source: [\/workspace]\nstep #1: target project: [myproject-event]\nstep #1: target service: [myservice]\nstep #1: target version: [20190130t095546]\nstep #1: target url: [https:\/\/myservice-dot-myproject-event.appspot.com]\nstep #1: \nstep #1: \nstep #1: do you want to continue (y\/n)? \nstep #1: warning: unable to verify that the appengine flexible api is enabled for project [myproject-event]. you may not have permission to list enabled services on this project. if it is not enabled, this may cause problems in running your deployment. please ask the project owner to ensure that the appengine flexible api has been enabled and that this account has permission to list enabled apis.\nstep #1: beginning deployment of service [myservice]...\nstep #1: building and pushing image for service [myservice]\nstep #1: started cloud build [b41069a6-2ef7-4eaf-8b49-de36bc620be2].\nstep #1: to see logs in the cloud console: https:\/\/console.cloud.google.com\/gcr\/builds\/b41069a6-2ef7-4eaf-8b49-de36bc620be2?project=954549095871\nstep #1: ----------------------------- remote build output ------------------------------\nstep #1: starting build \"b41069a6-2ef7-4eaf-8b49-de36bc620be2\"\nstep #1: \nstep #1: fetchsource\nstep #1: fetching storage object: gs:\/\/staging.myproject-event.appspot.com\/asia.gcr.io\/myproject-event\/appengine\/myservice.20190130t095546:latest#1548842148386512\nstep #1: copying gs:\/\/staging.myproject-event.appspot.com\/asia.gcr.io\/myproject-event\/appengine\/myservice.20190130t095546:latest#1548842148386512...\nstep #1: \/ [0 files][ 0.0 b\/ 10.9 kib] \n\/ [0 files][ 10.9 kib\/ 10.9 kib] \n-\n- [1 files][ 10.9 kib\/ 10.9 kib] \nstep #1: operation completed over 1 objects\/10.9 kib. \nstep #1: build\nstep #1: starting step #0\nstep #1: step #0: already have image (with digest): gcr.io\/cloud-builders\/go\nstep #1: step #0: documentation at https:\/\/github.com\/googlecloudplatform\/cloud-builders\/blob\/master\/go\/readme.md\nstep #1: step #0: running: go get -u -d github.com\/didip\/tollbooth github.com\/lib\/pq github.com\/stretchr\/testify github.com\/go-redis\/redis cloud.google.com\/go\/pubsub\nstep #1: finished step #0\nstep #1: starting step #1\nstep #1: step #1: already have image (with digest): gcr.io\/cloud-builders\/gcloud\nstep #1: step #1: services to deploy:<\/pre>\n<p>\u8fd9\u79cd\u60c5\u51b5\u4e00\u76f4\u6301\u7eed\u5230\u6211\u624b\u52a8\u7ec8\u6b62\u6700\u540e\u4e00\u4e2a\u6784\u5efa\uff1a<\/p>\n<pre>Step #1: Step #1: Step #1: Step #1: Step #1: Step #1: Copying gs:\/\/staging.solution360-event.appspot.com\/asia.gcr.io\/solution360-event\/appengine\/authproxy.20190130t100329:latest#1548842611410114...\nStep #1: Step #1: Step #1: Step #1: Step #1: Step #1: \/ [0 files][ 0.0 B\/ 10.9 KiB] \n-\n- [1 files][ 10.9 KiB\/ 10.9 KiB] \nStep #1: Step #1: Step #1: Step #1: Step #1: Step #1: Operation completed over 1 objects\/10.9 KiB. \nStep #1: Step #1: Step #1: Step #1: Step #1: Step #1: BUILD\nStep #1: Step #1: Step #1: Step #1: Step #1: Step #1: Starting Step #0\nStep #1: Step #1: Step #1: Step #1: Step #1: Step #1: Step #0: Already have image (with digest): gcr.io\/cloud-builders\/go\nStep #1: Step #1: Step #1: Step #1: Step #1: Step #1: Step #0: Documentation at https:\/\/github.com\/GoogleCloudPlatform\/cloud-builders\/blob\/master\/go\/README.md\nStep #1: Step #1: Step #1: Step #1: Step #1: Step #1: Step #0: Running: go get -u -d github.com\/didip\/tollbooth github.com\/lib\/pq github.com\/stretchr\/testify github.com\/go-redis\/redis cloud.google.com\/go\/pubsub<\/pre>\n<p>\u6211\u5c1d\u8bd5\u8fc7\u7684\uff1a<\/p>\n<ul>\n<li>\u4ece\u547d\u4ee4\u4e2d\u5220\u9664\u201c&#8211;stop-previous-versions\u201d\u6807\u5fd7\u3002<\/li>\n<li>\u5c06 <code>gopath<\/code> \u5b89\u88c5\u5728\u4e0d\u540c\u7684\u5377\u4e2d\uff0c\u4ee5\u9632\u5bfc\u81f4 gcloud \u9012\u5f52\u4e0b\u964d\u5230\u5176\u4e2d\u3002<\/li>\n<li>\u4ec5\u8fd0\u884c\u7b2c 1 \u6b65\uff0c\u7ed3\u679c\u76f8\u540c\u3002<\/li>\n<\/ul>\n<p>\u8bf7\u53c2\u9605\u968f\u9644\u7684\u5b9e\u9645\u751f\u6210\u751f\u6210\u7684\u5c4f\u5e55\u622a\u56fe\uff1a <\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u4e8b\u5b9e\u8bc1\u660e\uff0c\u8fd9\u662f <code>Google Cloud Build<\/code> \u5982\u4f55\u5904\u7406\u914d\u7f6e\u6587\u4ef6 <code>cloudbuild.yaml<\/code> \u7684\u95ee\u9898\u3002\u6bcf\u6b21\u770b\u5230\u4e00\u4e2a\u7248\u672c\u65f6\uff0c\u5b83\u90fd\u5fc5\u987b\u751f\u6210\u4e00\u4e2a\u65b0\u7248\u672c\uff0c\u65e0\u8bba\u5b83\u662f\u5426\u5df2\u7ecf\u88ab\u770b\u5230\u3002<\/p>\n<p>\u5c31\u6211\u800c\u8a00\uff0c\u7531\u4e8e\u9879\u76ee\u5f88\u5c0f\uff0c\u56e0\u6b64 <code>cloudbuild.yaml<\/code> \u548c\u6211\u7684 go \u6e90\u4ee3\u7801\u90fd\u4f4d\u4e8e\u9879\u76ee\u7684\u6839\u76ee\u5f55\u3002\u8fd9\u5bfc\u81f4\u4e86\u4ee5\u4e0b\u60c5\u51b5\uff1a<\/p>\n<ul>\n<li>\u521d\u59cb <code>git Push<\/code> \u4f1a\u89e6\u53d1\u6784\u5efa\uff0c\u8be5\u6784\u5efa\u4f1a\u8bfb\u53d6 <code>cloudbuild.yaml<\/code>\u3002<\/li>\n<li>\u6784\u5efa\u53d1\u73b0\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u4e2d\u6709\u4e00\u4e2a <code>cloudbuild.yaml<\/code> \u5e76\u4e3a\u6b64\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u6784\u5efa\u3002<\/li>\n<\/ul>\n<p>\u6211\u8ba4\u4e3a\u8fd9\u5f88\u6709\u7528\uff0c\u56e0\u4e3a\u60a8\u53ef\u4ee5\u4e3a\u9879\u76ee\u4e2d\u7684\u5404\u79cd\u4e8b\u7269\u62e5\u6709\u591a\u4e2a\u6784\u5efa\u914d\u7f6e\uff0c\u8fd9\u4e9b\u914d\u7f6e\u5c06\u5728\u9047\u5230\u65f6\u6784\u5efa\u3002<\/p>\n<p>\u5c06 go \u6e90\u79fb\u81f3 <code>src\/<\/code>\uff08\u8fdc\u79bb cloudbuild\uff09\u89e3\u51b3\u4e86\u8be5\u95ee\u9898\u3002<\/p>\n<p><code>tl;dr<\/code> \u4e0d\u8981\u5c06\u60a8\u7684 <code>cloudbuild.yaml<\/code> \u653e\u5165\u5de5\u4f5c\u76ee\u5f55\u4e2d\u3002<\/p>\n<p>\u6211\u65e0\u6cd5\u91cd\u65b0\u521b\u5efa\u65e0\u9650\u6784\u5efa\uff0c\u4f46\u6709\u4e00\u4e9b\u4e8b\u60c5<\/p>\n<ul>\n<li>\n<p>\u81ea\u5b9a\u4e49\u8fd0\u884c\u65f6\u9700\u8981 Dockerfile\uff0c\u60a8\u662f\u5426\u5c1d\u8bd5\u8fc7\u5728 go \u8fd0\u884c\u65f6\u4e2d\u8fd0\u884c\u60a8\u7684\u670d\u52a1\uff1f <\/p>\n<ul>\n<li>\n<\/li>\n<li>\n<\/li>\n<li>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u60a8\u4f7f\u7528\u5377\u800c\u4e0d\u662f\u4ec5\u5728\u73af\u5883\u4e2d\u8bbe\u7f6e\u9879\u76ee\u6839\u76ee\u5f55\u662f\u5426\u6709\u7279\u5b9a\u539f\u56e0\uff1f<\/p>\n<ul>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300a\u5728 Google Cloud Build \u4e0a\u90e8\u7f72 Golang AppEngine \u4f1a\u4ea7\u751f\u65e0\u9650\u6784\u5efa\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-208248","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208248","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=208248"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208248\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=208248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=208248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=208248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}