用于生产和登台/开发的不同composer.json文件 [英] Different composer.json files for production and staging/development
问题描述
场景:
我有一个现有的实时站点,它通过dev-master
上的几个GIT存储库加载了composer依赖项.
I have an existing live site that loads in composer dependencies via several GIT repositories on dev-master
.
来自客户端的新功能请求,在我将其从开发合并为主功能之前,我需要将新的(未完成的)功能部署到暂存环境中,以便在继续上线之前从客户端获得批准(我可能需要展示客户端是新功能的早期版本,根本还没有准备好掌握.)
A new feature request comes in from the client and before I merge it from develop into master I need to deploy the new (unfinished) feature to a staging environment to get OK from the client before pushing live (I may need to show the client an early version of the new feature, not at all ready for master).
我通常通过capistrano部署东西(不是我想这有什么区别).
I usually deploy stuff via capistrano (not that it makes any difference I guess).
我不能将require-dev
用于新代码,因为它可能是需要重构的现有插件.
I can't use require-dev
for the new code as it's likely an existing plugin that needs to be refactored.
理想情况下,我可以将dev-develop
用于登台/开发环境上的插件,将dev-master
用于实时环境,但是在同一composer.json文件中不可能有两次相同的存储库.
Ideally I'd be able to use dev-develop
for the plugin on the staging/development environment and dev-master
for the live environment, but it's not possible to have the same repository twice in the same composer.json file.
我该怎么做?
推荐答案
解决方案是使用环境变量.
The solution is to use environmental variables.
我有2个composer.json
文件(还有2个composer.lock
文件).第二个我命名为composer-dev.json
(随后将生成一个名为composer-dev.lock
的锁定文件).
I have 2 composer.json
files (and also 2 composer.lock
files). The 2nd I named composer-dev.json
(this will subsequently generate a lock filed named composer-dev.lock
).
在我的capistrano中,为我添加的舞台服务器部署配置
In my capistrano deploy config for the stage server I added
set :default_env, {
'COMPOSER' => 'composer-dev.json'
}
我可以在本地计算机上动态定义环境变量所以:
I can define the environmental variable on the fly on my local machine like so:
$ COMPOSER=composer-dev.json composer update
生成composer-dev.lock
文件,然后我可以将其部署到登台服务器.
which generates the composer-dev.lock
file I can then deploy to the staging server.
我当然可以在登台服务器上配置环境,在capistrano配置中似乎更容易做到.
Of course I could have configured the environment on the staging server, it just seems easier to do it in my capistrano config.
这篇关于用于生产和登台/开发的不同composer.json文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!