{"id":362744,"date":"2024-05-21T01:41:18","date_gmt":"2024-05-21T01:41:18","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=362744"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=362744","title":{"rendered":"<span>\u0418\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f: \u043a\u0430\u043a \u043f\u043e\u0434\u043d\u044f\u0442\u044c GitLab CI\/CD \u043d\u0430 GoLang-\u043f\u0440\u043e\u0435\u043a\u0442\u0435<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u043a \u0437\u0430\u043c\u0435\u0442\u043a\u0435 <a href=\"https:\/\/habr.com\/ru\/companies\/agima\/articles\/779028\/\" rel=\"noopener noreferrer nofollow\">\u0418\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f: \u043a\u0430\u043a \u0431\u044b\u0441\u0442\u0440\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c GitLab CI\/CD \u043d\u0430 Flutter-\u043f\u0440\u043e\u0435\u043a\u0442\u0435<\/a>.<\/p>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0430\u0432\u0442\u043e\u0440\u0443, \u0432\u0441\u0451 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u0435\u0433\u043a\u043e. \u042f \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u043b \u0437\u0430\u0434\u0430\u0447\u0443: \u043f\u043e\u0434\u043d\u044f\u043b GitLab \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u043d\u0430 \u0425\u0430\u043a\u0438\u043d\u0442\u043e\u0448\u0435, \u043f\u0440\u0438\u043a\u0440\u0443\u0442\u0438\u043b <code>executor = \"docker\"<\/code> \u0432\u043c\u0435\u0441\u0442\u043e <code>\"shell\"<\/code>. \u0418 \u043d\u0430\u0447\u0430\u043b\u043e\u0441\u044c \u0432\u0435\u0441\u0435\u043b\u044c\u0435.<\/p>\n<h3>Docker Desktop<\/h3>\n<p>\u041d\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0439\u0442\u0435 \u043c\u043e\u044e \u043e\u0448\u0438\u0431\u043a\u0443: \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u043d\u0430\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432 Docker-\u043e\u0431\u0440\u0430\u0437\u0430\u0445. \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0438\u0432\u0430\u044e \u0441 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0430\u0439\u0442\u0430, \u0447\u0435\u0440\u0435\u0437 \u0441\u043a\u0430\u0447\u0430\u043d\u043d\u044b\u0439 Docker.dmg <a href=\"https:\/\/docs.docker.com\/desktop\/release-notes\/#4252\" rel=\"noopener noreferrer nofollow\">v4.25.2<\/a>:<\/p>\n<pre><code class=\"bash\">$ docker -v Docker version 24.0.6, build ed223bc $ docker-compose version Docker Compose version v2.23.0-desktop.1 <\/code><\/pre>\n<h3>\u041b\u043e\u043a\u0430\u043b\u044c\u043d\u0430\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 GitLab \u0432 Docker<\/h3>\n<pre><code class=\"yaml\"># docker-compose.yml version: '3' services:   web:     image: 'gitlab\/gitlab-ce:latest'     restart: always     hostname: 'localhost'     environment:       GITLAB_OMNIBUS_CONFIG: |         external_url 'http:\/\/localhost'     ports:       - '80:80'       # - '443:443'       - '22:22'     volumes:       - '~\/.gitlab\/config:\/etc\/gitlab'       - '~\/.gitlab\/logs:\/var\/log\/gitlab'       - '~\/.gitlab\/data:\/var\/opt\/gitlab' <\/code><\/pre>\n<pre><code class=\"bash\">$ docker-compose up -d <\/code><\/pre>\n<p>\u041f\u043e\u0448\u0443\u0440\u0448\u0438\u0442 \u043f\u0430\u0440\u0443 \u043c\u0438\u043d\u0443\u0442, \u043f\u043e\u0442\u043e\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <code>http:\/\/localhost<\/code>. \u0421\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u044e \u043f\u0430\u0440\u043e\u043b\u044c:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d98\/364\/fb5\/d98364fb50f3b01859fda0294013f18a.png\" alt=\"Docker Desktop\" title=\"Docker Desktop\" width=\"1930\" height=\"670\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d98\/364\/fb5\/d98364fb50f3b01859fda0294013f18a.png\"\/><\/p>\n<div><figcaption>Docker Desktop<\/figcaption><\/div>\n<\/figure>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0430\u0440\u043e\u043b\u044c \u0431\u044b\u043b \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d \u0440\u0430\u043d\u0435\u0435 \u0434\u043b\u044f \u0432\u0445\u043e\u0434\u0430 \u0432 <code>git<\/code> \u0447\u0435\u0440\u0435\u0437 VSCode, \u0442\u043e\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u0431\u0440\u043e\u0441\u0438\u0442\u044c:<\/p>\n<pre><code class=\"bash\">$ git credential-osxkeychain erase host=localhost protocol=http <\/code><\/pre>\n<h3>DOCKER_AUTH_CONFIG<\/h3>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u044e \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0443 \u0432 <a href=\"http:\/\/docker.io\" rel=\"noopener noreferrer nofollow\">docker.io<\/a>:<\/p>\n<pre><code class=\"bash\">$ docker logout $ docker login Login Succeeded <\/code><\/pre>\n<p>\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e \u0445\u044d\u0448:<\/p>\n<pre><code class=\"bash\">$ printf \"my_username:my_password\" | openssl base64 -A # Example output to copy bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ= <\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u0445\u044d\u0448 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433:<\/p>\n<pre><code class=\"bash\">$ nano ~\/.docker\/config.json <\/code><\/pre>\n<pre><code class=\"json\">{   \"auths\": {     \"docker.io\": {       \"auth\": \"bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ=\"     }   },   \"credsStore\": \"desktop\",   \"currentContext\": \"desktop-linux\",   \"plugins\": {     \"-x-cli-hints\": {       \"enabled\": \"true\"     }   } } <\/code><\/pre>\n<p>\u041f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e <code>DOCKER_AUTH_CONFIG<\/code>:<\/p>\n<pre><code class=\"json\">{   \"auths\": {     \"docker.io\": {       \"auth\": \"bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ=\"     }   } } <\/code><\/pre>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/829\/74d\/35d\/82974d35d97a039bbcd4acb11ae2e5b2.png\" alt=\"GitLab > Settings > CI\/CD > Variables&#187; title=&#187;GitLab > Settings > CI\/CD > Variables&#187; width=&#187;1484&#8243; height=&#187;1076&#8243; data-src=&#187;https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/829\/74d\/35d\/82974d35d97a039bbcd4acb11ae2e5b2.png&#187;\/><\/p>\n<div><figcaption>GitLab > Settings > CI\/CD > Variables<\/figcaption><\/div>\n<\/figure>\n<h3>\u0420\u044b\u0431\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h3>\n<p>\u0421\u043e\u0437\u0434\u0430\u044e \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 GitLab \u0438 \u043a\u043b\u043e\u043d\u0438\u0440\u0443\u044e \u0435\u0433\u043e \u043a \u0441\u0435\u0431\u0435:<\/p>\n<pre><code class=\"bash\">$ git clone http:\/\/localhost\/root\/my-project.git $ cd my-project <\/code><\/pre>\n<p>\u041f\u043e\u0440\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0431\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 <code>main.go<\/code>:<\/p>\n<pre><code class=\"bash\">$ go mod init my-project $ nano main.go <\/code><\/pre>\n<pre><code class=\"go\">package main  import ( \"log\" \"time\" )  func main() { for { time.Sleep(time.Second) log.Println(\"OK\") } } <\/code><\/pre>\n<p>\u041c\u043d\u0435 \u043d\u0443\u0436\u0435\u043d <code>Dockerfile<\/code> \u0434\u043b\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0431\u043e\u0440\u043a\u0438:<\/p>\n<pre><code>$ nano Dockerfile<\/code><\/pre>\n<pre><code class=\"bash\">FROM golang:onbuild AS build WORKDIR \/build COPY . . RUN CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -o .\/app  FROM ubuntu:20.04 AS ubuntu RUN apt-get update RUN DEBIAN_FRONTEND=noninteractive apt-get install -y upx RUN apt-get clean &amp;&amp; \\     rm -rf \/var\/lib\/apt\/lists\/* COPY --from=build \/build\/app \/build\/app RUN upx \/build\/app  FROM scratch COPY --from=ubuntu \/build\/app \/build\/app  ENTRYPOINT [\"\/build\/app\"] <\/code><\/pre>\n<p>\u0412\u0441\u044f \u044d\u0442\u0430 \u0441\u0443\u0435\u0442\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0437 (image) \u043d\u0430 577KB:<\/p>\n<ul>\n<li>\n<p><code>ubuntu<\/code> \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u0432\u043e\u043b\u0448\u0435\u0431\u043d\u044b\u0439 <a href=\"https:\/\/github.com\/upx\/upx\" rel=\"noopener noreferrer nofollow\">upx<\/a>;<\/p>\n<\/li>\n<li>\n<p><code>scratch<\/code> \u0442\u043e\u0436\u0435 \u0441\u043e\u043a\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440.<\/p>\n<\/li>\n<\/ul>\n<p>\u0418 \u0434\u043b\u044f \u043f\u043e\u0440\u044f\u0434\u043a\u0430:<\/p>\n<pre><code class=\"bash\">$ nano .dockerignore <\/code><\/pre>\n<pre><code>.git <\/code><\/pre>\n<p>\u0412\u0438\u0448\u0435\u043d\u043a\u0430 \u043d\u0430 \u0442\u043e\u0440\u0442\u0435:<\/p>\n<pre><code class=\"bash\">$ nano docker-compose.yml<\/code><\/pre>\n<pre><code class=\"yaml\">version: '3' name: 'my-project' services:   app:     build: .<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0431\u0443\u044e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432 \u0434\u043e\u043a\u0435\u0440\u0435:<\/p>\n<pre><code class=\"bash\">$ docker-compose up -d --build <\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b41\/5da\/5ff\/b415da5ff2845cbd021f2df038ac0a5c.png\" alt=\"Docker Desktop\" title=\"Docker Desktop\" width=\"1912\" height=\"716\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b41\/5da\/5ff\/b415da5ff2845cbd021f2df038ac0a5c.png\"\/><\/p>\n<div><figcaption>Docker Desktop<\/figcaption><\/div>\n<\/figure>\n<h3>gitlab-runner<\/h3>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430:<\/p>\n<pre><code class=\"bash\">$ brew install gitlab-runner $ brew services start gitlab-runner <\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u0442\u0435\u0433\u0438 &#8216;ci, cd&#8217;:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/691\/cfa\/f4d\/691cfaf4dbb58bb3c24706a1c68ee8aa.png\" alt=\"GitLab > Settings > CI\/CD > Runners > New Project Runner&#187; title=&#187;GitLab > Settings > CI\/CD > Runners > New Project Runner&#187; width=&#187;1384&#8243; height=&#187;1390&#8243; data-src=&#187;https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/691\/cfa\/f4d\/691cfaf4dbb58bb3c24706a1c68ee8aa.png&#187;\/><\/p>\n<div><figcaption>GitLab > Settings > CI\/CD > Runners > New Project Runner<\/figcaption><\/div>\n<\/figure>\n<p>\u0418 \u043f\u043e\u043b\u0443\u0447\u0430\u044e \u0442\u043e\u043a\u0435\u043d:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/019\/e25\/873\/019e258739c3117afd333de02eefd1a7.png\" alt=\"GitLab > Settings > CI\/CD > Runners > New Project Runner > Create Runner&#187; title=&#187;GitLab > Settings > CI\/CD > Runners > New Project Runner > Create Runner&#187; width=&#187;1490&#8243; height=&#187;904&#8243; data-src=&#187;https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/019\/e25\/873\/019e258739c3117afd333de02eefd1a7.png&#187;\/><\/p>\n<div><figcaption>GitLab > Settings > CI\/CD > Runners > New Project Runner > Create Runner<\/figcaption><\/div>\n<\/figure>\n<p>\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u044e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e:<\/p>\n<pre><code class=\"bash\">$ gitlab-runner register \\  --url \"http:\/\/localhost\" \\  --description \"via docker\" \\  --docker-image \"alpine\" \\  --executor \"docker\" \\  --docker-privileged \\  --docker-volumes \"\/certs\/client\" \\  --docker-network-mode host \\  --docker-helper-image \"registry.gitlab.com\/gitlab-org\/gitlab-runner\/gitlab-runner-helper:x86_64-e0218c92\" <\/code><\/pre>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u044e \u043d\u0430 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 <code>config.toml<\/code>:<\/p>\n<pre><code class=\"bash\">$ nano ~\/.gitlab-runner\/config.toml <\/code><\/pre>\n<p>\u0423\u0434\u0430\u043b\u044f\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u043b\u044e\u0447\u0430 <code>image<\/code>:<\/p>\n<pre><code>[[runners]]   name = \"via docker\"   # ...   [runners.docker]     image = \"\"     # ... <\/code><\/pre>\n<h3>.gitlab-ci.yml<\/h3>\n<pre><code class=\"bash\">$ nano .gitlab-ci.yml <\/code><\/pre>\n<p><strong>\u042f:<\/strong> \u041a\u0430\u043a \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 <code>Dockerfile<\/code> \u0432 \u0444\u043e\u0440\u043c\u0430\u0442 <code>.gitlab-ci.yml<\/code>?<\/p>\n<pre><code>FROM golang:onbuild AS build WORKDIR \/build COPY . . RUN CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -o .\/app <\/code><\/pre>\n<p><strong>ChatGPT:<\/strong><\/p>\n<pre><code class=\"yaml\">stages:   - build  variables:   GOARCH: amd64   GOOS: linux   CGO_ENABLED: 0  build:   stage: build   image: golang:onbuild   script:     - go build -o .\/app   artifacts:     paths:       - .\/app <\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u043e\u0442 \u0441\u0435\u0431\u044f:<\/p>\n<pre><code class=\"yaml\">  tags:     - cd  workflow:   rules:     - if: '$CI_PIPELINE_SOURCE == \"merge_request_event\"'       when: always <\/code><\/pre>\n<p>\u0412\u0441\u0451, \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043c\u043c\u0438\u0442\u0438\u0442\u044c. \u041f\u0440\u044f\u043c\u043e \u0432\u0435\u0442\u043a\u0443 <code>main<\/code>, \u043a\u0430\u043a \u043c\u044b \u043b\u044e\u0431\u0438\u043c. \u041f\u043e\u0442\u043e\u043c \u0434\u0435\u043b\u0430\u044e \u043d\u043e\u0432\u0443\u044e \u0432\u0435\u0442\u043a\u0443 \u0441 \u043a\u0430\u043a\u0438\u043c-\u043b\u0438\u0431\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u0438 \u043e\u0444\u043e\u0440\u043c\u043b\u044f\u044e &#171;merge request&#187;.<\/p>\n<p>\u0417\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0439 job \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0443\u0441\u043f\u0435\u0448\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3b7\/1fd\/c32\/3b71fdc32feee1dcd5ba11e75d60c69b.png\" width=\"1380\" height=\"740\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3b7\/1fd\/c32\/3b71fdc32feee1dcd5ba11e75d60c69b.png\"\/><\/figure>\n<p><strong>UPD:<\/strong> \u0440\u0435\u0448\u0438\u043b \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0441 \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c <code>gitlab-runner<\/code> \u0438 \u043e\u0442\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043e\u0442 Docker Desktop 4.26.0.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/780172\/\"> https:\/\/habr.com\/ru\/articles\/780172\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u043a \u0437\u0430\u043c\u0435\u0442\u043a\u0435 <a href=\"https:\/\/habr.com\/ru\/companies\/agima\/articles\/779028\/\" rel=\"noopener noreferrer nofollow\">\u0418\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f: \u043a\u0430\u043a \u0431\u044b\u0441\u0442\u0440\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c GitLab CI\/CD \u043d\u0430 Flutter-\u043f\u0440\u043e\u0435\u043a\u0442\u0435<\/a>.<\/p>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0430\u0432\u0442\u043e\u0440\u0443, \u0432\u0441\u0451 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u0435\u0433\u043a\u043e. \u042f \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u043b \u0437\u0430\u0434\u0430\u0447\u0443: \u043f\u043e\u0434\u043d\u044f\u043b GitLab \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u043d\u0430 \u0425\u0430\u043a\u0438\u043d\u0442\u043e\u0448\u0435, \u043f\u0440\u0438\u043a\u0440\u0443\u0442\u0438\u043b <code>executor = \"docker\"<\/code> \u0432\u043c\u0435\u0441\u0442\u043e <code>\"shell\"<\/code>. \u0418 \u043d\u0430\u0447\u0430\u043b\u043e\u0441\u044c \u0432\u0435\u0441\u0435\u043b\u044c\u0435.<\/p>\n<h3>Docker Desktop<\/h3>\n<p>\u041d\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0439\u0442\u0435 \u043c\u043e\u044e \u043e\u0448\u0438\u0431\u043a\u0443: \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u043d\u0430\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432 Docker-\u043e\u0431\u0440\u0430\u0437\u0430\u0445. \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0438\u0432\u0430\u044e \u0441 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0430\u0439\u0442\u0430, \u0447\u0435\u0440\u0435\u0437 \u0441\u043a\u0430\u0447\u0430\u043d\u043d\u044b\u0439 Docker.dmg <a href=\"https:\/\/docs.docker.com\/desktop\/release-notes\/#4252\" rel=\"noopener noreferrer nofollow\">v4.25.2<\/a>:<\/p>\n<pre><code class=\"bash\">$ docker -v Docker version 24.0.6, build ed223bc $ docker-compose version Docker Compose version v2.23.0-desktop.1 <\/code><\/pre>\n<h3>\u041b\u043e\u043a\u0430\u043b\u044c\u043d\u0430\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 GitLab \u0432 Docker<\/h3>\n<pre><code class=\"yaml\"># docker-compose.yml version: '3' services:   web:     image: 'gitlab\/gitlab-ce:latest'     restart: always     hostname: 'localhost'     environment:       GITLAB_OMNIBUS_CONFIG: |         external_url 'http:\/\/localhost'     ports:       - '80:80'       # - '443:443'       - '22:22'     volumes:       - '~\/.gitlab\/config:\/etc\/gitlab'       - '~\/.gitlab\/logs:\/var\/log\/gitlab'       - '~\/.gitlab\/data:\/var\/opt\/gitlab' <\/code><\/pre>\n<pre><code class=\"bash\">$ docker-compose up -d <\/code><\/pre>\n<p>\u041f\u043e\u0448\u0443\u0440\u0448\u0438\u0442 \u043f\u0430\u0440\u0443 \u043c\u0438\u043d\u0443\u0442, \u043f\u043e\u0442\u043e\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <code>http:\/\/localhost<\/code>. \u0421\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u044e \u043f\u0430\u0440\u043e\u043b\u044c:<\/p>\n<figure class=\"full-width\">\n<div><figcaption>Docker Desktop<\/figcaption><\/div>\n<\/figure>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0430\u0440\u043e\u043b\u044c \u0431\u044b\u043b \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d \u0440\u0430\u043d\u0435\u0435 \u0434\u043b\u044f \u0432\u0445\u043e\u0434\u0430 \u0432 <code>git<\/code> \u0447\u0435\u0440\u0435\u0437 VSCode, \u0442\u043e\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u0431\u0440\u043e\u0441\u0438\u0442\u044c:<\/p>\n<pre><code class=\"bash\">$ git credential-osxkeychain erase host=localhost protocol=http <\/code><\/pre>\n<h3>DOCKER_AUTH_CONFIG<\/h3>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u044e \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0443 \u0432 <a href=\"http:\/\/docker.io\" rel=\"noopener noreferrer nofollow\">docker.io<\/a>:<\/p>\n<pre><code class=\"bash\">$ docker logout $ docker login Login Succeeded <\/code><\/pre>\n<p>\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e \u0445\u044d\u0448:<\/p>\n<pre><code class=\"bash\">$ printf \"my_username:my_password\" | openssl base64 -A # Example output to copy bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ= <\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u0445\u044d\u0448 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433:<\/p>\n<pre><code class=\"bash\">$ nano ~\/.docker\/config.json <\/code><\/pre>\n<pre><code class=\"json\">{   \"auths\": {     \"docker.io\": {       \"auth\": \"bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ=\"     }   },   \"credsStore\": \"desktop\",   \"currentContext\": \"desktop-linux\",   \"plugins\": {     \"-x-cli-hints\": {       \"enabled\": \"true\"     }   } } <\/code><\/pre>\n<p>\u041f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e <code>DOCKER_AUTH_CONFIG<\/code>:<\/p>\n<pre><code class=\"json\">{   \"auths\": {     \"docker.io\": {       \"auth\": \"bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ=\"     }   } } <\/code><\/pre>\n<figure class=\"full-width\"> Settings > CI\/CD > Variables&#187; title=&#187;GitLab > Settings > CI\/CD > Variables&#187; width=&#187;1484&#8243; height=&#187;1076&#8243; data-src=&#187;https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/829\/74d\/35d\/82974d35d97a039bbcd4acb11ae2e5b2.png&#187;\/><\/p>\n<div><figcaption>GitLab > Settings > CI\/CD > Variables<\/figcaption><\/div>\n<\/figure>\n<h3>\u0420\u044b\u0431\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h3>\n<p>\u0421\u043e\u0437\u0434\u0430\u044e \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 GitLab \u0438 \u043a\u043b\u043e\u043d\u0438\u0440\u0443\u044e \u0435\u0433\u043e \u043a \u0441\u0435\u0431\u0435:<\/p>\n<pre><code class=\"bash\">$ git clone http:\/\/localhost\/root\/my-project.git $ cd my-project <\/code><\/pre>\n<p>\u041f\u043e\u0440\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0431\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 <code>main.go<\/code>:<\/p>\n<pre><code class=\"bash\">$ go mod init my-project $ nano main.go <\/code><\/pre>\n<pre><code class=\"go\">package main  import ( \"log\" \"time\" )  func main() { for { time.Sleep(time.Second) log.Println(\"OK\") } } <\/code><\/pre>\n<p>\u041c\u043d\u0435 \u043d\u0443\u0436\u0435\u043d <code>Dockerfile<\/code> \u0434\u043b\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0431\u043e\u0440\u043a\u0438:<\/p>\n<pre><code>$ nano Dockerfile<\/code><\/pre>\n<pre><code class=\"bash\">FROM golang:onbuild AS build WORKDIR \/build COPY . . RUN CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -o .\/app  FROM ubuntu:20.04 AS ubuntu RUN apt-get update RUN DEBIAN_FRONTEND=noninteractive apt-get install -y upx RUN apt-get clean &amp;&amp; \\     rm -rf \/var\/lib\/apt\/lists\/* COPY --from=build \/build\/app \/build\/app RUN upx \/build\/app  FROM scratch COPY --from=ubuntu \/build\/app \/build\/app  ENTRYPOINT [\"\/build\/app\"] <\/code><\/pre>\n<p>\u0412\u0441\u044f \u044d\u0442\u0430 \u0441\u0443\u0435\u0442\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0437 (image) \u043d\u0430 577KB:<\/p>\n<ul>\n<li>\n<p><code>ubuntu<\/code> \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u0432\u043e\u043b\u0448\u0435\u0431\u043d\u044b\u0439 <a href=\"https:\/\/github.com\/upx\/upx\" rel=\"noopener noreferrer nofollow\">upx<\/a>;<\/p>\n<\/li>\n<li>\n<p><code>scratch<\/code> \u0442\u043e\u0436\u0435 \u0441\u043e\u043a\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440.<\/p>\n<\/li>\n<\/ul>\n<p>\u0418 \u0434\u043b\u044f \u043f\u043e\u0440\u044f\u0434\u043a\u0430:<\/p>\n<pre><code class=\"bash\">$ nano .dockerignore <\/code><\/pre>\n<pre><code>.git <\/code><\/pre>\n<p>\u0412\u0438\u0448\u0435\u043d\u043a\u0430 \u043d\u0430 \u0442\u043e\u0440\u0442\u0435:<\/p>\n<pre><code class=\"bash\">$ nano docker-compose.yml<\/code><\/pre>\n<pre><code class=\"yaml\">version: '3' name: 'my-project' services:   app:     build: .<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0431\u0443\u044e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432 \u0434\u043e\u043a\u0435\u0440\u0435:<\/p>\n<pre><code class=\"bash\">$ docker-compose up -d --build <\/code><\/pre>\n<figure class=\"full-width\">\n<div><figcaption>Docker Desktop<\/figcaption><\/div>\n<\/figure>\n<h3>gitlab-runner<\/h3>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430:<\/p>\n<pre><code class=\"bash\">$ brew install gitlab-runner $ brew services start gitlab-runner <\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u0442\u0435\u0433\u0438 &#8216;ci, cd&#8217;:<\/p>\n<figure class=\"full-width\"> Settings > CI\/CD > Runners > New Project Runner&#187; title=&#187;GitLab > Settings > CI\/CD > Runners > New Project Runner&#187; width=&#187;1384&#8243; height=&#187;1390&#8243; data-src=&#187;https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/691\/cfa\/f4d\/691cfaf4dbb58bb3c24706a1c68ee8aa.png&#187;\/><\/p>\n<div><figcaption>GitLab > Settings > CI\/CD > Runners > New Project Runner<\/figcaption><\/div>\n<\/figure>\n<p>\u0418 \u043f\u043e\u043b\u0443\u0447\u0430\u044e \u0442\u043e\u043a\u0435\u043d:<\/p>\n<figure class=\"full-width\"> Settings > CI\/CD > Runners > New Project Runner > Create Runner&#187; title=&#187;GitLab > Settings > CI\/CD > Runners > New Project Runner > Create Runner&#187; width=&#187;1490&#8243; height=&#187;904&#8243; data-src=&#187;https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/019\/e25\/873\/019e258739c3117afd333de02eefd1a7.png&#187;\/><\/p>\n<div><figcaption>GitLab > Settings > CI\/CD > Runners > New Project Runner > Create Runner<\/figcaption><\/div>\n<\/figure>\n<p>\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u044e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e:<\/p>\n<pre><code class=\"bash\">$ gitlab-runner register \\  --url \"http:\/\/localhost\" \\  --description \"via docker\" \\  --docker-image \"alpine\" \\  --executor \"docker\" \\  --docker-privileged \\  --docker-volumes \"\/certs\/client\" \\  --docker-network-mode host \\  --docker-helper-image \"registry.gitlab.com\/gitlab-org\/gitlab-runner\/gitlab-runner-helper:x86_64-e0218c92\" <\/code><\/pre>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u044e \u043d\u0430 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 <code>config.toml<\/code>:<\/p>\n<pre><code class=\"bash\">$ nano ~\/.gitlab-runner\/config.toml <\/code><\/pre>\n<p>\u0423\u0434\u0430\u043b\u044f\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u043b\u044e\u0447\u0430 <code>image<\/code>:<\/p>\n<pre><code>[[runners]]   name = \"via docker\"   # ...   [runners.docker]     image = \"\"     # ... <\/code><\/pre>\n<h3>.gitlab-ci.yml<\/h3>\n<pre><code class=\"bash\">$ nano .gitlab-ci.yml <\/code><\/pre>\n<p><strong>\u042f:<\/strong> \u041a\u0430\u043a \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 <code>Dockerfile<\/code> \u0432 \u0444\u043e\u0440\u043c\u0430\u0442 <code>.gitlab-ci.yml<\/code>?<\/p>\n<pre><code>FROM golang:onbuild AS build WORKDIR \/build COPY . . RUN CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -o .\/app <\/code><\/pre>\n<p><strong>ChatGPT:<\/strong><\/p>\n<pre><code class=\"yaml\">stages:   - build  variables:   GOARCH: amd64   GOOS: linux   CGO_ENABLED: 0  build:   stage: build   image: golang:onbuild   script:     - go build -o .\/app   artifacts:     paths:       - .\/app <\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u043e\u0442 \u0441\u0435\u0431\u044f:<\/p>\n<pre><code class=\"yaml\">  tags:     - cd  workflow:   rules:     - if: '$CI_PIPELINE_SOURCE == \"merge_request_event\"'       when: always <\/code><\/pre>\n<p>\u0412\u0441\u0451, \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043c\u043c\u0438\u0442\u0438\u0442\u044c. \u041f\u0440\u044f\u043c\u043e \u0432\u0435\u0442\u043a\u0443 <code>main<\/code>, \u043a\u0430\u043a \u043c\u044b \u043b\u044e\u0431\u0438\u043c. \u041f\u043e\u0442\u043e\u043c \u0434\u0435\u043b\u0430\u044e \u043d\u043e\u0432\u0443\u044e \u0432\u0435\u0442\u043a\u0443 \u0441 \u043a\u0430\u043a\u0438\u043c-\u043b\u0438\u0431\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u0438 \u043e\u0444\u043e\u0440\u043c\u043b\u044f\u044e &#171;merge request&#187;.<\/p>\n<p>\u0417\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0439 job \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0443\u0441\u043f\u0435\u0448\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p><strong>UPD:<\/strong> \u0440\u0435\u0448\u0438\u043b \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0441 \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c <code>gitlab-runner<\/code> \u0438 \u043e\u0442\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043e\u0442 Docker Desktop 4.26.0.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/780172\/\"> https:\/\/habr.com\/ru\/articles\/780172\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-362744","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/362744","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=362744"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/362744\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=362744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=362744"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=362744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}