我们的情况是这样的:

We have 3 different Laravel projects and all 3 projects rely on our Core project. This Core project is a separate Laravel package hosted on our private repo and is used as a dependency for other projects.

以前,每当核心项目发生变化时,我们都会在服务器上运行composer update ourvendor/ourcorepackage, for each 项目引入核心变化.然而,直到最近,当我们试图在带有512 MB Ram的数字海洋登台环境上运行更新时,composer似乎遇到了严重的内存问题.见:https://github.com/composer/composer/issues/1898

The solution I always come across is people saying that you should always run composer install on your production servers. I can relate to that in terms of security because it can be dangerous if you update to a new version of some 3rd party package that can possibly break your code. But in our case we only update our own core package so we know what we're doing but this memory issue forces us to use the composer install method because it is less memory demanding.

基本上这就是我们目前的工作流程:

  1. 当我们的核心包中发生变化时,我们需要运行编写器 在本地更新每个项目的供应商/软件包这将生成 Composer.lock文件
  2. We commit the composer.lock file in our repo

  3. 在每个项目的服务器上,我们运行git pull和composer

然而,这种解决方案提出了两个问题:

  1. Since we're working with multiple devs on the same project we sometimes end up having merge conflicts for the composer.lock file when pulling in the changes locally.
  2. 在服务器上运行git pull会出现错误:对以下文件的本地更改将被merge:composer覆盖.锁

So what am I supposed to do here? Before the pull on the server remove the composer.lock file? How should we handle the merge conflicts for the composer.lock file?

遗憾的是,Composer更新受到内存问题的困扰,因为该方法似乎更符合逻辑.只需更新您想要的软件包,就可以轻松地使用Composer.lock文件.

请建议在我们的情况下,使用GIT和Composer的正确工作流程应该是怎样的,以及如何解决上面的冲突?

非常感谢您的意见

推荐答案

如果开发人员自己不做这一步,如何测试核心更新(或任何其他更新的依赖项)不会 destruct 使用它的项目中的东西?

That's why the usual workflow is expecting the composer update being run on a development machine having enough RAM (i.e. probably more than 1GB set as memory limit for PHP), and the update should be triggered manually by the developer (and if triggered automatically by a continuous integration build, the memory requirements apply to this machine as well).

There is no way around this memory requirement. A web server with only 512 MB RAM installed might be able to function as a staging server with barely any concurrent users present, but it shouldn't be used to update the Composer dependencies.

Personally I fix the merge conflicts in the composer.lock with a very easy system: Delete the lock file and run composer update. This will update all dependencies to the latest versions that satisfy the version requirements, and create a new working composer.lock file that get's committed during the merge.

I am not afraid to potentially update everything, because either it works as expected, or my tests will catch errors quickly.

I do select the 3rd party packages I use carefully:

  • they have to tag their versions, preferably using semantic versioning.
  • 对于发布版本,我不使用任何分支(在开发期间有人使用它们的罕见情况是令人痛苦的)
  • they should ship a new major version if they make backwards incompatible changes
  • 本地开发的软件包也遵循这些要求

This works with around 270 packages served by our local Satis instance (probably also a factor to consider when trying to reduce memory footprint - only the packages known to Composer can end up in memory: Compare the ten thousand packages potentially available on packagist.org with 270 local packages). 60 packages of the 270 are locally developed by 20 developers, and randomly releasing new versions. The update failures in the last 2 years are very rare, and should be handled like other bugs: If a tagged version is detected to be incompatible, we release a bugfix release reverting the change, and tag the original change with a new major release, if the incompatible change is necessary.

So the workflow you ask for is probably like this:

  • Anytime, any developer should be able to run composer update on their local machine.
  • 他们应该能够检测到这是否 destruct 了本地机器上的东西.
  • If nothing is broken, they commit the changes including the composer.lock file to Git
  • The staging server only runs composer install and will use exactly the versions that the developer used on his machine.
  • If nothing is broken on staging, that version is ready to be used on production.

在另一台开发人员机器上合并已经提交的版本可能会显示与composer.lock的合并冲突.

  • 解决所有其他文件上的冲突.
  • composer.lock文件应该被删除.
  • From here, the workflow is like above, i.e.:
  • 开发者应该能够在本地机器上运行composer update.
  • 他们应该能够检测到这是否 destruct 了他本地机器上的东西.
  • If nothing is broken... and so on.

Laravel相关问答推荐

Laravel带S3存储器

Laravel mail send Amazon SES不再支持TLS 1.0和TLS 1.1连接

按回车键时如何防止此功能运行?

不能在 laravel 中使用控制器名称,必须使用命名空间

Laravel 从 5.1 升级到 5.2.0 错误

Laravel Eloquent - 随叫随到的加密/解密数据

Laravel 重定向数据不工作

PHP Laravel:如何设置或获取会话数据?

如何使用 Eloquent Laravel 更新集合

Laravel Eloquent:访问属性和动态表名

Laravel 4:读取由 javascript 设置的 cookie

使用数据库中的值进行动态邮件配置 [Laravel]

如何在 Laravel 5.2 中手动发送密码重置请求?

如何从不是控制器方法的方法发送响应?

在 Laravel 测试用例中模拟一个 http 请求并解析路由参数

如何从 Laravel 中的资源中获取图像?

Laravel 5 - 判断日期是否是今天

在 laravel 的自定义路径中创建模型

是否可以在 Laravel 的不同数据库中引用外键?

Distinct values with pluck