I am trying to run composer install in the command shell section of jenkins, but when I build the job, its failing because composer.json contains a repository section.
"repositories": [
{
"type": "vcs",
"url": "git#gitlab*****"
}
],
in jenkin's Source Code Management I did added the git credentials plus the repository URL (this is working fine and building fine) this is a different repo than the one in the composer.json.
The only problem is that I cant pull the git repo inside the composer.json file (giving permission denied), my thinking is that jenkins doesnt store the ssh keys, it only execute when its building and then remove, am i right to think this? and if so how can I overcome this? And if not what am I doing wrong, how can i avoid having permission denied when pulling git repos inside a composer.json?
Related
I've got a local PHP project (a website), and I want to use another project I've made (a tiny web framework) as a Composer package for the website project. I'm developing them in tandem, but want to keep them as separate projects; when I deploy the website, I want to use Composer to install the framework project as a package, just like I would with Guzzle or any other common Composer package.
The website project has the following composer.json:
{
"repositories": [
{
"type": "path",
"url": "/local/path/to/framework/package"
"options": {
"symlink": true
}
}
],
"require": {
"my/framework": "dev-master",
"guzzlehttp/guzzle": "6.3.3"
}
}
In /local/path/to/framework/package/composer.json I have:
{
"name": "my/framework",
"description": "A tiny framework.",
"autoload": {
"psr-4": {
"MyFramework\\": "src"
}
}
}
I run php composer.phar update and it sets up a symlink to the framework package in my website project. If I update code in the framework, it's immediately available to the website code. This is great.
However, later on I want to deploy the website project to my web server. For a clean deployment, I have a deploy script that exports an archive copy of the appropriate branch of the website git repo, and then runs php composer.phar install to make sure all the proper packages are installed. With the above config, the deploy script creates a symlink to the framework package, which is obviously no good when the deployment artifact is zipped up and scp'd out to the web server.
If I remove the symlink option above, then I have to run php composer.phar update every time I make any changes in the framework package, which is irritating since I'm developing the packages in tandem. But then on deploy, the package is copied in, rather than being symlinked in; this is good for deploy, except it always copies in the master branch (because I specified dev-master in composer.json).
Is there a way to set up Composer so that I can have the convenience of a local symlinked package for development, but to let the deployment script get a clean copy of the framework package, without having to change composer.json every time I want to deploy?
I also tried changing the repository type to vcs instead of path, but then Composer clones the framework package repository, and I really don't need a clone of the repo in my local vendor/ tree, either during development or deployment. I just want to be able to have a symlinked tree (which gets me instant updates) during development, and have a clean package installed for deplotment.
I may have to resign myself to developing the framework project "properly," that is, as a Composer package that I tag with actual release version numbers, and then update my website project to use a specific version of when it comes time for a deployment. I still haven't figured out the easiest way to do that, though.
You can use Composer Studio plugin.
It uses a separate file for configuration and allows you to have symlinks in development and a regular Composer install for prod deploy, without touching composer.json.
With it, your website composer.json will look like a regular file:
{
"require": {
"my/framework": "dev-master",
"guzzlehttp/guzzle": "6.3.3"
}
}
And with studio.json in the root of the project, with the following content:
{
"version": 2,
"paths": [
"/local/path/to/framework/package"
]
}
you can tell the plugin where to locate my/framework. Studio will then symlink the packages from the provided paths.
To have a regular install, just remove or rename studio.json, remove the vendor folder and composer.lock file and run the install again when deploying.
I made a composer plugin to make it more easy to test packages.
It doesn't require a configuration file, changing your composer.json and doesn't change the upgrade behavior of composer update
https://github.com/SanderSander/composer-link
It works as simple as calling composer link ../path-to-package to link the local package into your project.
Background
We have a PHP project that was working fine with Travis CI until a certain point and since then has totally stopped working. The project is simply failing to build with Composer.
Details
The last successful build was:
this one
The most recent failed build was:
this one, in the branch Naming Collisions which is this commit
The error that keeps coming up is:
Failed to execute git clone --mirror 'git#github.com:edmondscommerce/Faker.git' '/home/travis/.composer/cache/vcs/git-github.com-edmondscommerce-Faker.git/'
latest branch is NamingCollisions, this is the latest commit
Notice in the composer.json we are using a fork for the Faker library:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/edmondscommerce/Faker.git"
}
],
This all works fine for our local tests, it only fails in Travis.
Things we have tried:
flushing Travis caches
clearing composer caches before doing the install - .travis.bash
adding:
"github-protocols": ["https"]
to the composer.json
Hoping it will just go away...
No luck so far.
Unfortunately we're now just testing locally and ignoring Travis because it is consistently failing now even though the code is working fine.
Hopefully one of you readers can help figure this one out!
What we went with
In the end we decided to add "no-api": true to the repositories config as suggested by Everon.
This forces composer to no longer make use the github API (docs):
If you set the no-api key to true on a github repository it will clone the repository as it would with any other git repository instead of using the GitHub API.
I had a look in to this and it isn't an issue with Travis itself.
After looking in to Travis and running the Travis environment locally in a Docker instance I was able to reproduce the issue.
Travis is complaining that it can not authenticate through at Github.
You need to use a Travis environment variable that can then be used to set the access token so that Composer can do what is required to install the VCS repository fork of Faker.
You can define the variable in the settings for your repository in Travis, it is then available as a standard Bash variable to be used in your travis before_script array or in your shell scripts.
Token from the build log:
Setting environment variables from repository settings
$ export GITHUB_TOKEN=[secure]
You define the required access token here:
https://github.com/settings/tokens/new?scopes=repo
And can then set it in the before script like so:
before_script:
- composer config github-oauth.github.com ${GITHUB_TOKEN};
- bash -x .travis.bash
Another option is to add "no-api" to your Faker fork - See below.
...
"repositories": [
{
"type": "vcs",
"url": "https://github.com/edmondscommerce/Faker.git",
"no-api": true
}
]
...
Build (failed but has past the point you were having issues with)
https://travis-ci.org/everon/doctrine-static-meta/jobs/352620456
I know that I can use composer update vendor/package but here's my case.
Composer is very slow when updating, I have around 6 packages installed and one local vcs package being loaded from a local folder. When I run composer update even for that specific local package, composer connects to Packagist to look for other updates and this process is very slow, I don't know if it's my computer or my internet. Is there a way I can tell composer to just update the package from local folder when I run composer update local/package without contacting Packagist and running through all the heavy json files it downloads?
Note:
I know how to load a local composer package. It's loading perfectly, it's just that I'm looking for a way to tell composer just to load the local package without contacting Packagist.
"repositories": [
{
"type": "vcs",
"url": "../local/package"
}
],
My problem is that it's slow to contact Packagist. Running composer update local/package -vvv Shows that it still downloads json files from packagist even if it's told to update just local/package.
There are multiple ways of speeding the Composer fetch up:
define a custom repo, which points to a local path and install with --prefer-source
"repositories": [
{
"type":"vcs",
"url":"/path/to/your/local/package/packageA"
}
],
"require":{
"package/packageA" : "dev-master"
}
Follow-up trick: if you exactly know the type of the repo, then specify it!
In other words: do not use "type":"vcs" if you can specify "type":"git" or "type":"svn". Composer will skip running through all the repo adapters to figure the correct one out.
you could setup Satis and define only the required packages for your project and their dependencies ("require-dependencies": "true"). This acts as a package proxy in front of packagist. You would simply fetch from the local Satis mirror/proxy.
Give this a try, to disable the default Packagist repository:
{
"repositories": [
{
"packagist": false
}
]
}
I've got a PHP project that uses Capistrano 3 to deploy to staging/testing/live and everything works fine.
Now we've encountered a bug in one of our dependencies that are included through PHPComposer, it's really an easy fix (change one line) which we do manually in the vendor directory on our development boxes, just until the bug is fixed through our pull request. But every time we deploy all dependencies are installed again on the deployment target server including the bugged dependency. After we manually ssh into the server and change that one line in the particular file the deploy is successful.
How would I go about automating this with capistrano? Are there proven ways of doing this?
I suspect the 'official' solution to this is to fork the repo with your fix in place, and then alias the new repo, setting your composer.json to use that in preference to the original while you wait for the fix to be merged upstream.
There are some details on the Composer site - require-inline-alias
The composer.json configuration to be able to do the inline-aliasing is:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/you/monolog"
}
],
"require": {
"symfony/monolog-bundle": "2.0",
"monolog/monolog": "dev-bugfix as 1.0.x-dev"
}
That will fetch the dev-bugfix version of monolog/monolog from your GitHub and alias it to 1.0.x-dev.
I'm getting an error when I try to run composer. I have the following in my composer.json:
{
"require": {
"my/private-repo": "dev-development"
},
"repositories": [
{
"type": "git",
"url": "git#bitbucket.org:my/private-repo.git"
}
],
}
In that private bitbucket repo, there's a composer.json with a name of "my/private-repo", and there's a branch called development.
When I try to run composer, I get this error: "Failed to update git#bitbucket.org:my/private-repo.git, package information from this repository may be outdated (fatal: No such remote or remote group: origin". I have no idea why it's mentioning origin at all; I've got that private repo in a totally separate folder on this composer, so it shouldn't be looking in there. I can git clone my/private-repo just fine, so it's not an SSH issue. Any ideas?
So it turns out this was just an issue with Composer caching. I ran rm -rf ~/.composer/cache/ and tried updating again, and everything works.
I also had this problem but it was caused because of something I did. I have two projects setup. One was a dependency on the other. I used composer to manage this dependency. For testing purposes, I deleted the dependency from vendor/namespace/my-lib and created a symlink to the other project. Then I could update code on the fly and commit when I was done. When I later tried to do a composer update I received the error above.
To resolve the problem I deleted my symlink and then ran composer update. It properly downloaded the dependency and everything was fine.