简体   繁体   English

带有 GitLab、docker 和 docker 私有注册表的 CD

[英]CD with GitLab, docker and docker private registry

we need to automate the process of deployment.我们需要自动化部署过程。 Let me point out the stack we use.让我指出我们使用的堆栈。 We have our own GitLab CE instance and private docker registry.我们有自己的 GitLab CE 实例和私有 docker 注册表。 On production server, application is run in container.在生产服务器上,应用程序在容器中运行。 After every master commit, GitLab CI builds the image with code in it, sends it to docker registry and this is where automation ends.每次主提交后,GitLab CI 构建包含代码的映像,将其发送到 docker 注册表,这就是自动化结束的地方。

Deployment on production server could be performed by a few steps - stopping current application container, pulling newer one and run it.在生产服务器上的部署可以通过几个步骤来执行 - 停止当前的应用程序容器,拉出新的并运行它。

What is the best way to automate this process?自动化此过程的最佳方法是什么?

I read about a couple of solutions (but I believe there is much more)我阅读了一些解决方案(但我相信还有更多)

  • docker private registry pings to a production server that does all the above steps itself (script on production machine managed by eg. supervisor or something similar) docker 私有注册表 ping 到自己执行所有上述步骤的生产服务器(生产机器上的脚本由例如主管或类似的东西管理)
  • using docker machine to remotely manage run containers使用 docker machine 远程管理运行容器

What is the preferred way?什么是首选方式? Or you can recommend something else?或者你可以推荐其他东西?

No need to use tools like swarm, kubernetes, etc. It's quite simple application.无需使用 swarm、kubernetes 等工具。这是一个非常简单的应用程序。 Thanks in advance.提前致谢。

How about install Gitlab-ci runner on your production machine?在你的生产机器上安装 Gitlab-ci runner 怎么样? And perform a job after the push to registry on master called deploy and pin it to that machine using Gitlab CI tags.并在推送到名为deploy master 上的注册表后执行一项工作,并使用 Gitlab CI 标签deploy其固定到该机器上。

The job simply pulls the image from the registry and restarts your service or whatever you have in place.该作业只是从注册表中提取映像并重新启动您的服务或任何您现有的东西。

Something like:类似的东西:

deploy-job:
  stage: deploy
  tags:
    - production
  script:
    - docker login myprivateregistry.com -u $SECRET_USER -p $SECRET_PASS
    - docker pull $CI_REGISTRY_IMAGE:latest
    - docker-compose down
    - docker-compose up -d

I can think of four solutions我能想到四种解决方案

  1. use watchtower on production server https://github.com/v2tec/watchtower在生产服务器上使用瞭望塔https://github.com/v2tec/watchtower
  2. run a webhook server which is requests by your CI after pushing the image to the registry.运行一个 webhook 服务器,这是你的 CI 在将图像推送到注册表后请求的。 https://github.com/adnanh/webhook https://github.com/adnanh/webhook
  3. as already mentioned, run the CI on production too which finaly triggers your update commands.如前所述,也可以在生产环境中运行 CI,这最终会触发您的更新命令。
  4. enable docker api and update the container by requesting it from the CI启用 docker api 并通过从 CI 请求来更新容器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM