PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 24, 2022

[FIXED] Different composer.json files for production and staging/development

 January 24, 2022     composer-php, git     No comments   

Issue

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?


Solution

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.



Answered By - Richard Sweeney
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing