{"id":151,"date":"2020-12-02T21:27:11","date_gmt":"2020-12-02T12:27:11","guid":{"rendered":"http:\/\/localhost:8000\/?p=151"},"modified":"2021-01-11T21:28:14","modified_gmt":"2021-01-11T12:28:14","slug":"gitlab-ci-tips","status":"publish","type":"post","link":"http:\/\/localhost:8000\/2020\/12\/gitlab-ci-tips.html","title":{"rendered":"GitLab-CI\u306eTips"},"content":{"rendered":"
GitLab CI\u306eTips\u7684\u306a\u3082\u306e\u3092\u8a18\u8f09\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n
\u5b9f\u969b\u306e\u904b\u7528\u3067\u306f\u3001staging\u3068production\u306eDocker\u30a4\u30e1\u30fc\u30b8\u3092\u3001\u7570\u306a\u308b\u30ec\u30b8\u30b9\u30c8\u30ea\u3067\u7ba1\u7406\u3059\u308b\u3053\u3068\u3082\u3042\u308b\u3068\u601d\u3044\u307e\u3059\u3002\u305d\u306e\u3088\u3046\u306a\u30b1\u30fc\u30b9\u3067\u306fEnvironment scope\u3092\u4f7f\u3046\u3068\u826f\u3044\u3068\u601d\u3044\u307e\u3059\u3002
\n\u307e\u305a\u3001\u4ee5\u4e0b\u306e\u30a4\u30e1\u30fc\u30b8\u306e\u3088\u3046\u306b\u540c\u540d\u306e\u30ab\u30b9\u30bf\u30e0\u5909\u6570\u3092\u7570\u306a\u308bEnvironment scope\uff08stg \/ prd\uff09\u3067\u767b\u9332\u3057\u307e\u3059\u3002
\n<\/p>\n
\u305d\u306e\u4e0a\u3067\u3001.gitlab-ci.yml\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n
.build<\/code>\u3068\u3057\u3066\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5316\u3059\u308b<\/li>\nbuild_stg<\/code>\u3068build_prd<\/code>\u3092\u65b0\u305f\u306b\u4f5c\u3063\u3066.build<\/code>\u3092extend\u3059\u308b<\/li>\n- \n
\u30bf\u30b0\u540d$CI_COMMIT_TAG<\/code>\u306e\u30d1\u30bf\u30fc\u30f3\u30de\u30c3\u30c1\u3067\u3001x.y.z<\/code>\u306e\u5f62\u5f0f\u306a\u3089\u74b0\u5883\u540d\u3092prd<\/code>\u3068\u3057\u3001\u305d\u308c\u4ee5\u5916\u306a\u3089\u74b0\u5883\u540d\u3092stg<\/code>\u3068\u3059\u308b\uff08\u305d\u308c\u306b\u3088\u308a\u8aad\u307f\u8fbc\u307e\u308c\u308b\u30ab\u30b9\u30bf\u30e0\u5909\u6570\u304c\u5207\u308a\u66ff\u308f\u308b\uff09<\/p>\nstages:\n - build_stage\n\n.build:\n stage: build_stage\n image:\n name: gcr.io\/kaniko-project\/executor:debug\n # \u7701\u7565\uff08\u4e0a\u306e\u5b9f\u4f8b\u3068\u5168\u304f\u540c\u3058\uff09\n\nbuild_stg:\n extends: .build\n environment:\n name: stg\n except:\n variables:\n - $CI_COMMIT_TAG =~ \/^([\\d]+\\.){2,3}[\\d]+$\/\n\nbuild_prd:\n extends: .build\n environment:\n name: prd\n only:\n variables:\n - $CI_COMMIT_TAG =~ \/^([\\d]+\\.){2,3}[\\d]+$\/<\/code><\/pre>\n<\/li>\n<\/ul>\n\u3053\u308c\u3067\u3001\u30bf\u30b0\u540d\u306b\u3088\u3063\u3066push\u5148\u306e\u30ec\u30b8\u30b9\u30c8\u30ea\u3092\u5909\u66f4\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n
\u521d\u3081\u3066\u306e\u30d1\u30a4\u30d7\u30e9\u30a4\u30f3\u304c\u767b\u9332\u3055\u308c\u306a\u3044<\/h3>\n
\u3053\u3061\u3089\u306eissue<\/a>\u306b\u3042\u308b\u3088\u3046\u306b\u3001master\u30d6\u30e9\u30f3\u30c1\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\u30d6\u30e9\u30f3\u30c1\uff09\u306b.gitlab-ci.yml\u304c\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u3001\u305f\u3068\u3048\u5225\u30d6\u30e9\u30f3\u30c1\u306b.gitlab-ci.yml\u304c\u5b58\u5728\u3057\u3066\u3082\u3001GitLab CI\u304c\u6709\u52b9\u306b\u306a\u3089\u306a\u3044\u3088\u3046\u3067\u3059\u3002<\/p>\n\u81ea\u5206\u306e\u5834\u5408\u306f\u3001master\u30d6\u30e9\u30f3\u30c1\u306b\u5b58\u5728\u3057\u306a\u3044\u72b6\u6cc1\u3067\u3001topic\u30d6\u30e9\u30f3\u30c1\u3092\u5207\u3063\u3066.gitlab-ci.yml\u3092\u4f5c\u6210\u3057\u305f\u305f\u3081\u3001\u307e\u3055\u306b\u3053\u306e\u554f\u984c\u306b\u5f53\u305f\u3063\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002<\/p>\n
\u7d50\u5c40\u3001master\u30d6\u30e9\u30f3\u30c1\u306b.gitlab-ci.yml\u3092\u914d\u7f6e\u3057\u3066\u3042\u3052\u308b\u3068\u3046\u307e\u304f\u30d1\u30a4\u30d7\u30e9\u30a4\u30f3\u304c\u767b\u9332\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n
GitLab CI\u3067GCR\u4e0a\u306eDocker\u30a4\u30e1\u30fc\u30b8\u3092pull\u3057\u3066\u4f7f\u3046<\/h3>\n
\u4ee5\u4e0b\u306e\u69d8\u306a\u611f\u3058\u3067\u3001GCR\u4e0a\u306eDocker\u30a4\u30e1\u30fc\u30b8\u3092\u5229\u7528\u3057\u3066GitLab CI\u306e\u51e6\u7406\u3092\u884c\u3046\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n
test:\n stage: test\n image:\n name: asia.gcr.io\/myproject\/myimage:1.2.3\n script:\n - poetry run python -m unittest<\/code><\/pre>\n\u4f55\u3082\u8a2d\u5b9a\u306a\u3057\u306b\u5b9f\u884c\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u69d8\u306a\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n
\nERROR: Preparation failed: Error response from daemon: unauthorized: You don\u2019t have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in: https:\/\/cloud.google.com\/container-registry\/docs\/advanced-authentication<\/a> (executor_docker.go:192:0s) <\/p>\n<\/blockquote>\nGCR\u306f\u30d7\u30e9\u30a4\u30d9\u30fc\u30c8\u30ea\u30dd\u30b8\u30c8\u30ea\u306a\u306e\u3067 docker pull\u3059\u308b\u969b\u306b\u3001\u8a8d\u8a3c\u3092\u884c\u3063\u3066\u3042\u3052\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u8a2d\u5b9a\u65b9\u6cd5\u306f\u3053\u3061\u3089\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/a>\u306b\u66f8\u3044\u3066\u3042\u308a\u307e\u3059\u3002<\/p>\n\u65b9\u6cd5\u306f\u3044\u304f\u3064\u304b\u3042\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n
\n- \u68481)
DOCKER_AUTH_CONFIG<\/code>\u5909\u6570\u306b\u30af\u30ec\u30c7\u30f3\u30b7\u30e3\u30eb\u60c5\u5831\u3092\u8a2d\u5b9a\u3059\u308b\n\n- UI\u304b\u3089\u30ab\u30b9\u30bf\u30e0\u5909\u6570\u3068\u3057\u3066\u767b\u9332\u3059\u308b\u3010\u63a1\u7528\u3011\n
\n- \u25cb \u958b\u767a\u62c5\u5f53\u8005\u304c\u597d\u304d\u306b\u8a2d\u5b9a\u3067\u304d\u308b<\/li>\n
- \u25cb \u30af\u30ec\u30c7\u30f3\u30b7\u30e3\u30eb\u60c5\u5831\u3082commit\u5bfe\u8c61\u306b\u306a\u3089\u306a\u3044<\/li>\n<\/ul>\n<\/li>\n
- .gitlab-ci.yml\u3067variable\u3068\u3057\u3066\u767b\u9332\u3059\u308b\u3010\u4e0d\u63a1\u7528\u3011\n
\n- \u25cb \u958b\u767a\u62c5\u5f53\u8005\u304c\u597d\u304d\u306b\u8a2d\u5b9a\u3067\u304d\u308b<\/li>\n
- \u00d7 \u30af\u30ec\u30c7\u30f3\u30b7\u30e3\u30eb\u60c5\u5831\u304ccommit\u5bfe\u8c61\u306b\u306a\u308b<\/li>\n<\/ul>\n<\/li>\n
- config.toml\u306b\u8a18\u8f09\u3059\u308b\u3010\u4e0d\u63a1\u7528\u3011\n
\n- \u00d7 \u30a4\u30f3\u30d5\u30e9\u62c5\u5f53\u8005\uff08GitLab\u304c\u52d5\u3044\u3066\u3044\u308b\u30b5\u30fc\u30d0\u306b\u5165\u3063\u3066\u8a2d\u5b9a\u3067\u304d\u308b\u4eba\uff09\u3057\u304b\u8a2d\u5b9a\u3067\u304d\u306a\u3044<\/li>\n
- \u00d7 runner\u306b\u5bfe\u3057\u3066\u30af\u30ec\u30c7\u30f3\u30b7\u30e3\u30eb\u8a2d\u5b9a\u304c\u56fa\u5b9a\u306b\u306a\u3063\u3066\u3057\u307e\u3046\uff08\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u3088\u3063\u3066\u4f7f\u3044\u5206\u3051\u305f\u308a\u3067\u304d\u306a\u3044\uff09<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n
- \u6848\uff12\uff09 config.json\u306bcredential helper\u3084credential store\u306e\u60c5\u5831\u3092\u8a18\u8f09\u3059\u308b\u3010\u4e0d\u63a1\u7528\u3011\n
\n- \u00d7 \u30a4\u30f3\u30d5\u30e9\u62c5\u5f53\u8005\uff08GitLab\u304c\u52d5\u3044\u3066\u3044\u308b\u30b5\u30fc\u30d0\u306b\u5165\u3063\u3066\u8a2d\u5b9a\u3067\u304d\u308b\u4eba\uff09\u3057\u304b\u8a2d\u5b9a\u3067\u304d\u306a\u3044<\/li>\n
- \u00d7 \u30b5\u30fc\u30d0\u306b\u5bfe\u3057\u3066\u30af\u30ec\u30c7\u30f3\u30b7\u30e3\u30eb\u8a2d\u5b9a\u304c\u56fa\u5b9a\u306b\u306a\u3063\u3066\u3057\u307e\u3046<\/li>\n
- \u00d7 shared runner\u3060\u3068\u4f7f\u3048\u306a\u3044<\/li>\n
- \u00d7 Credentials Store and Credential Helpers require binaries to be added to the GitLab Runner\u2019s $PATH<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n
\u7d50\u5c40\u3001UI\u304b\u3089\u30ab\u30b9\u30bf\u30e0\u5909\u6570\u3068\u3057\u3066DOCKER_AUTH_CONFIG<\/code>\u3092\u8a2d\u5b9a\u3059\u308b\u65b9\u6cd5\u3092\u63a1\u7528\u3057\u307e\u3057\u305f\u3002<\/p>\nGitLab\u7ba1\u7406\u753b\u9762\u306e\u5bfe\u8c61\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067 Settings > CI\/CD > Variables > Add variable \u3067\u3001DOCKER_AUTH_CONFIG<\/code>\u3068\u3044\u3046\u540d\u524d\u306e\u30ab\u30b9\u30bf\u30e0\u5909\u6570\u3092\u767b\u9332\u3057\u307e\u3059\u3002\u5024\u306f\u4ee5\u4e0b\u306e\u5f62\u5f0f\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n{\n "auths": {\n "asia.gcr.io": {\n "auth": "Base64\u306e\u6587\u5b57\u5217"\n }\n }\n}<\/code><\/pre>\n\u3053\u306eBase64\u306e\u6587\u5b57\u5217\u3067\u3059\u304c\u3001\u4ee5\u4e0b\u306e\u5f62\u5f0f\u306e\u6587\u5b57\u5217\u3092Base64\u306b\u5909\u63db\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n
$ echo -n "username:password" | base64\nbXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ= # \u30b5\u30f3\u30d7\u30eb\u3067\u3059<\/code><\/pre>\nGCR\u306e\u5834\u5408\u306f\u3001username\u304c_json_key<\/code>\u56fa\u5b9a\u3067\u3001password\u304cjson\u30ad\u30fc\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u8eab\u306eJSON\u305d\u306e\u3082\u306e\u306b\u306a\u308a\u307e\u3059\uff08\u3053\u306e\u60c5\u5831\u304c\u306a\u304b\u306a\u304b\u5206\u304b\u3089\u305a\u63a2\u3059\u306e\u306b\u6642\u9593\u304c\u304b\u304b\u3063\u305fw\uff09\u3002\u5b9f\u969b\u306b\u306f\u4ee5\u4e0b\u306e\u69d8\u306a\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u3042\u3052\u3066\u51fa\u3066\u304d\u305f\u6587\u5b57\u5217\u3092\u3001DOCKER_AUTH_CONFIG<\/code>\u306eauth\u306e\u3068\u3053\u308d\u306b\u8cbc\u308a\u4ed8\u3051\u3066\u3042\u3052\u308c\u3070OK\u3067\u3059\u3002<\/p>\n$ echo -n "_json_key:$(cat .\/key.json)" | base64\nZW5fdXJpIda90jmad@spkfvfadm,dGgyLmdvb2dsZWFwaXMuYerqwrw29tL3Rva2VuIiwKICAiYXV0aF9wcm92aWRlcl94NTA5X2Nadsabag:sdpakmfpadsmfajfe8bfnpuqwehfjhsdnv7qewjkbvdsag1MDkvc2NyYXBlciU0MHByZC1hc3RhbXVzZS1hc3RhbXVzZS5pYW0uZ3NlcnZpY2VhY2NvdW50LmNvbSIKfQ== # \u30b5\u30f3\u30d7\u30eb\u3067\u3059<\/code><\/pre>\n\u3053\u308c\u3067\u8a2d\u5b9a\u306f\u5b8c\u4e86\u3067\u3001\u30b8\u30e7\u30d6\u3092\u5b9f\u884c\u3059\u308c\u3070\u3061\u3083\u3093\u3068GCR\u304b\u3089docker pull\u3067\u304d\u308b\u3068\u601d\u3044\u307e\u3059\u3002
\n\u3061\u306a\u307f\u306b\u3046\u307e\u304f\u3044\u304f\u3068\u3001\u4ee5\u4e0b\u306e\u69d8\u306a\u30ed\u30b0\u304c\u51fa\u529b\u3055\u308c\u3001$DOCKER_AUTH_CONFIG\u3092\u4f7f\u3063\u3066\u8a8d\u8a3c\u304c\u884c\u308f\u308c\u3066\u3044\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n
Running with gitlab-runner 12.2.0 (88hrewe6q)\n on my-runner 9jqf932qe\nUsing Docker executor with image asia.gcr.io\/myproject\/myimage:1.2.3 ...\n03:06\nAuthenticating with credentials from $DOCKER_AUTH_CONFIG\nPulling docker image asia.gcr.io\/myproject\/myimage:1.2.3 ...\nUsing docker image sha256:sa9nfbpiahfp98qwendpjoahv09ufheqwofndnoafnsfa for asia.gcr.io\/myproject\/myimage:1.2.3<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"GitLab CI\u306eTips\u7684\u306a\u3082\u306e\u3092\u8a18\u8f09\u3057\u3066\u3044\u304d\u307e\u3059\u3002 \u74b0\u5883\uff08stg \/ prd\uff09\u6bce\u306b\u7570\u306a\u308b\u30ec\u30b8\u30b9\u30c8\u30ea\u306bpush\u3059\u308b \u5b9f\u969b\u306e\u904b\u7528\u3067\u306f\u3001staging\u3068production\u306eDocker\u30a4\u30e1\u30fc\u30b8\u3092\u3001\u7570\u306a\u308b\u30ec\u30b8\u30b9\u30c8\u30ea\u3067\u7ba1\u7406\u3059\u308b\u3053\u3068\u3082\u3042\u308b\u3068\u601d\u3044\u307e\u3059\u3002\u305d\u306e\u3088\u3046\u306a\u30b1\u30fc\u30b9\u3067\u306fEnvironment scope\u3092\u4f7f\u3046\u3068\u826f\u3044\u3068\u601d\u3044\u307e\u3059\u3002 \u307e\u305a\u3001\u4ee5\u4e0b\u306e\u30a4\u30e1\u30fc\u30b8\u306e\u3088\u3046\u306b\u540c\u540d\u306e\u30ab\u30b9\u30bf\u30e0\u5909\u6570\u3092\u7570\u306a\u308bEnvironment scope\uff08stg \/ prd\uff09\u3067\u767b\u9332\u3057\u307e\u3059\u3002 \u305d\u306e\u4e0a\u3067\u3001.gitlab-ci.yml\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002 \u5143\u3005\u306ebuild\u306e\u5185\u5bb9\u306f.build\u3068\u3057\u3066\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5316\u3059\u308b build_stg\u3068build_prd\u3092\u65b0\u305f\u306b\u4f5c\u3063\u3066.build\u3092extend\u3059\u308b \u30bf\u30b0\u540d$CI_COMMIT_TAG\u306e\u30d1\u30bf\u30fc\u30f3\u30de\u30c3\u30c1\u3067\u3001x.y.z\u306e\u5f62\u5f0f\u306a\u3089\u74b0\u5883\u540d\u3092prd\u3068\u3057\u3001\u305d\u308c\u4ee5\u5916\u306a\u3089\u74b0\u5883\u540d\u3092stg\u3068\u3059\u308b\uff08\u305d\u308c\u306b\u3088\u308a\u8aad <\/span>Continue Reading<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[],"_links":{"self":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/151"}],"collection":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/comments?post=151"}],"version-history":[{"count":0,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/151\/revisions"}],"wp:attachment":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/media?parent=151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/categories?post=151"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/tags?post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}