Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different composer.json files for production and staging/development

Scenario:

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).

I usually deploy stuff via capistrano (not that it makes any difference I guess).

I can't use require-dev for the new code as it's likely an existing plugin that needs to be refactored.

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.

How can I accomplish this?

like image 249
Richard Sweeney Avatar asked Jan 15 '16 08:01

Richard Sweeney


People also ask

What is a Composer json file?

composer. json is a JSON file placed in the root folder of PHP project. Its purpose is to specify a common project properties, meta data and dependencies, and it is a part of vast array of existing projects. In most ways, it is a counterpart to . NET project file.

How do I get the Composer json file?

To configure Composer for your PHP app json file specifies required packages. Verify that a composer. json file is present in the root of your git repository. Run composer install (on your local machine) to install the required packages and generate a composer.

What is Classmap in Composer json?

Classmap# The classmap references are all combined, during install/update, into a single key => value array which may be found in the generated file vendor/composer/autoload_classmap. php . This map is built by scanning for classes in all .

Where is Composer json file in laravel?

go to every package folder inside vendor folder and find the package's composer. json file. from that file find the "name" of that package from that composer.


1 Answers

The solution is to use environmental variables.

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).

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

which generates the composer-dev.lock file I can then deploy to the staging server.

Of course I could have configured the environment on the staging server, it just seems easier to do it in my capistrano config.

like image 132
Richard Sweeney Avatar answered Sep 18 '22 09:09

Richard Sweeney