Awesome
⚠️ Deprecated Project ⚠️
Please note, the current implementation is not suitable anymore and does not work anymore with composer if you are using an ext3
partition. Also, the mirroring solution requires a dedicated git host to server repository which is not an easy and simple task on the long run.
You should now use: https://github.com/rande/pkgmirror
Packagist and Github mirroring
Experiencing Github issues ? You want a local cache to speed up tests and deployment ?
Mirroring Packagist
-
Set up a new host on your webserver : packagist.mycompany.com
-
Go to the document root for the new host
-
run
git clone git://github.com/ekino/php-mirroring.git .
-
run
cp config.php.sample config.php
-
edit rules:
vim config.php
-
run
php mirror.php
- this can take a while for the first one -
add a new cron job
sudo crontab -u www-data -e
:0 */1 * * * cd /PATH_TO_DOCUMENT_ROOT && php mirror.php
Mirroring Github
-
Create a new mirror directory
mkdir mirrors/github.com
-
Add new mirror
cd mirrors/github.com git clone --mirror git://github.com/ekino/php-mirroring.git ekino/php-mirroring.git
Of course you need to repeat this operation for each mirror.
-
Setup a cron to update the mirror:
0 */1 * * * /git/repositories/mirrors/update-mirrors.sh
-
Add the file :
vim /git/repositories/mirrors/update-mirrors.sh
#!/bin/sh cd /git/repositories/mirrors/github.com for i in */*.git; do cd $i url=`echo $i | sed "s/.git//"` echo " > check 404 on https://github.com/${url}" curl -ILs https://github.com/${url} | head -n 1 | grep "HTTP/1.1 200 OK" > /dev/null if [ $? -eq 0 ] ; then echo " > fetching git changes" git fetch fi #echo "end ..." cd ../.. done
Usages
Using source mode with gitolite
-
Setup a Gitolite
-
Add a new entry
repo mirrors/..* R = @team
-
set the source mode to true
function include_source() { return true; }
Using dist mode with a http server
-
setup a new php instance with a dedicated vhost
-
make sure the
replace_dist_host
function point to the correct vhostfunction replace_dist_host(array $metadata) { list($vendor, $name) = explode("/", $metadata['name']); if (!preg_match('@(https://api.github.com/repos/|https://github.com/|https://bitbucket.org)([a-zA-Z0-9_\-\.]*)/([a-zA-Z0-9_\-\.]*)/(zipball|archive|get)/([a-zA-Z0-9\.\-]*)(|.zip)@', $metadata['dist']['url'], $matches)) { return ''; } $host = sprintf('http://packagist.mycompany.com/cache.php/github.com/%s/%s/%s.zip', $matches[2], $matches[3], $metadata['dist']['reference'] ); return $host; } function include_dist() { return true; } function include_source() { return true; // set to false if you only want to expose distribution }
Composer.json
-
Make sure you have a clean project
rm -rf composer.lock vendor
-
update the
composer.json
file to disable packagist and add the new one{ "repositories":[ { "packagist": false }, { "type": "composer", "url": "http://packagist.mycompany.com"} ], // ... }
If you are using non-composer packages, use the correct source url when adding them.
{
"repositories":[
{
"type": "package",
"package": {
"name": "documentcloud/underscore",
"version": "dev-master",
"source": {
"url": "git@git.mycompany.com:/mirrors/github.com/documentcloud/underscore.git",
"type": "git",
"reference": "master"
}
}
}
// ...
],
// ...
}
3. Install the dependencies
php composer.phar install