简体   繁体   English

在生产上部署发布的最佳实践

[英]Best practice to deploy release on production

We have a production site with more than 350 running instances, so making the site down even for a short time is a big deal. 我们的生产站点具有超过350个正在运行的实例,因此即使在很短的时间内使该站点停机也很重要。
My question: After pushing our code to production, if there is any update on composer we have to update it, during this period the site will be down. 我的问题:将代码推送到生产环境后,如果composer上有任何更新,我们必须对其进行更新,在此期间,该站点将关闭。 So what is the best practice to update composer on production without making the site down while updating? 那么在生产上更新作曲家而不在更新时关闭网站的最佳实践是什么?

I strongly recommend you use a deployment system, like Capistrano ( https://github.com/capistrano/capistrano ). 我强烈建议您使用像Capistrano( https://github.com/capistrano/capistrano )这样的部署系统。

Capistrano will per example clone your branch/commit into a dedicated folder, run scripts like Composer and if everything is fine, then it create/move a symlink to this folder. 例如,Capistrano会将您的分支/提交克隆到一个专用文件夹中,运行诸如Composer之类的脚本,如果一切正常,则它将创建/移动一个符号链接到该文件夹​​。

It's transparent for your user. 对您的用户而言是透明的。

And if anything goes wrong, you can ask Capistrano to "rollback", it will make the symlink point to the last working version (folder). 如果有任何问题,您可以要求Capistrano“回滚”,这将使符号链接指向最后一个可用的版本(文件夹)。

I suggests to use this approach to achieve almost zero down time: The root directory of the web server must be just a symbolic link. 我建议使用这种方法来实现几乎零停机时间:Web服务器的根目录必须只是一个符号链接。

  • Create a new directory for every release and upload the files into it. 为每个发行版创建一个新目录,并将文件上传到其中。
  • Install your dependencies. 安装依赖项。
  • Run your tests. 运行测试。
  • Create a symbolic link as the root directory of the web server that points to the new release directory. 创建一个符号链接作为指向新发行目录的Web服务器的根目录。

So you don't have to shutdown your website for coping and uploading files directly to the root directory. 因此,您不必关闭网站即可处理和直接将文件上传到根目录。 Just use symbolic links. 只需使用符号链接。 Also in this way it is much easier to rollback to any old release. 同样,以这种方式回滚到任何旧版本也更加容易。

I am using azure to host my websites and I noticed what they do is the following: 我正在使用azure托管我的网站,我注意到它们的作用如下:

  1. Pull the code from git to a staging folder 将代码从git拉到暂存文件夹
  2. Install composer dependencies in this folder 在此文件夹中安装composer依赖项
  3. Copy all contents for this folder to the live folder 将此文件夹的所有内容复制到活动文件夹

By running the composer install on another folder the packages on live are always available. 通过在另一个文件夹上运行composer安装,实时可用的软件包将始终可用。 The only time a down time can occur is when you are copying the files to the live directory, but this will be very briefly. 只有在将文件复制到活动目录时,才会出现停机时间,但这将非常短暂。

You don't need either composer or git in production/stage servers. 在生产/阶段服务器中不需要作曲家或git。

This is the steps I follow: 这是我遵循的步骤:

  1. Release: Use ci tool (like circleci, travis, etc.) to run your tests, but also to create a release build. 发布:使用ci工具(例如circleci,travis等)运行测试,还可以创建发布版本。

  2. Deployment: Use a deployment tool (like chef, puppet, ansible), which would automate the release, ideally working beside some orchestration tool (like kubernetes, terraform,...) 部署:使用部署工具(例如chef,puppet,ansible),该工具将自动执行发行,理想情况下是在一些编排工具(例如kubernetes,terraform等)旁边工作

Step 1: CI Release 步骤1:发布CI

(only in your release branch, ex: master) (仅在您的发布分支中,例如:master)

1.1 composer archive 1.1 composer archive

1.2 Uncompress into a distribution directory mkdir -p dist/ && tar -C dist/ -xf *.tar && cd dist 1.2解压缩到分发目录中mkdir -p dist/ && tar -C dist/ -xf *.tar && cd dist

1.3 composer install --no-ansi --no-dev --no-interaction --no-progress --no-scripts --optimize-autoloader 1.3 composer install --no-ansi --no-dev --no-interaction --no-progress --no-scripts --optimize-autoloader

1.4 Compress again with vendor repositories 1.4使用供应商存储库再次压缩

1.5 Make a git release throw the api. 1.5使git release抛出api。 You can use a tool like https://github.com/tcnksm/ghr or make your own code there 您可以使用https://github.com/tcnksm/ghr之类的工具,也可以在此处编写自己的代码

Step 2: Deployment 步骤2:部署

2.1 Download your code into /some/path/{release-version} 2.1将代码下载到/ some / path / {release-version}

2.2 When finished, remove the actual symlink (if any) and create a new symlink to /some/path/{release-version} 2.2完成后,删除实际的符号链接(如果有)并创建一个新的符号链接到/ some / path / {release-version}

2.3 Remove any previous versions to avoid memory issues 2.3删除任何以前的版本以避免内存问题

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

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