markomarkovic / simple-php-git-deploy Goto Github PK
View Code? Open in Web Editor NEWAutomatically deploy the code using PHP and Git
License: MIT License
Automatically deploy the code using PHP and Git
License: MIT License
I'm sure this is completely my fault, but I haven't had any luck resolving the issue, and didn't know where else to turn.
I've used deploy.php successfully on a public repo (it works great, thanks!), and now I'm trying to get it going on a private repo. The deploy.php chugs along fine, and then produces this error:
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
I have followed the steps here ( https://help.github.com/articles/generating-ssh-keys ) successfully. (I do have a passphrase, could that be causing problems?)
Thank you so much!
When trying to run the deploy.php script, I get this:
Checking the environment ...
Running as .
git not available. It needs to be installed on the server for this script to work.
When I type git into ssh prompt on the server, it shows the git commands, so git is installed. Any idea what might have gone wrong?
Because the script assumes all commands must return 0. It early exits on git 1.7.1 if submodules are not present, even though there is no issue
Hello, I've found link on codecanyon, is this same?
http://codecanyon.net/item/easy-git-code-deploy/8586366
After some hassle I finally managed to use this library on a windows server 2008 R2. I eventually gave up using rsync due to file permission issues in NTFS, and I am now using a simpler robocopy snip instead. I also changed from tar to 7z as 7z has better support in windows.
I can put my changes in a commit and make a pull request if there's any chance of it being merged.
I am getting below error when i am running /deploy.php from browser or if i push anything in repository.
$ git clone --depth=1 --branch master [email protected]:myrepository.git /tmp/spgd-8fbc87725193f8667aff13a1372edd28/
Cloning into '/tmp/spgd-8fbc87725193f8667aff13a1372edd28'...
Host key verification failed.
fatal: Could not read from remote repository.
When i run $ git clone --depth=1 --branch master [email protected]:myrepository.git /tmp/spgd-8fbc87725193f8667aff13a1372edd28/ directly in terminal its cloning repository without any error.
I have also referred #9 but didn't help.
To separate concerns, configuration options would be better located in a separate file. Separation would facilitate version updates because deploy.php could be updated without having to reconfigure it. It could be like:
require __DIR__ . '/config.php';
Or maybe with the option to be up one:
array_reduce(array(__DIR__, dirname(__DIR__)), function($name, $dir) {
if ($name && is_file("$dir/$name")) require "$dir/$name";
else return $name;
}, 'deploy-config.php') and require __DIR__ . '/config.php';
I want to automatically update a live site whenever I push changes to my repository and everything that should go live is inside a "dist" folder on github. Is there any way to specify only content of this folder to be pushed to live site (preferably via a setting in deploy-config.php)? I see an option for excluding files/folders in config file, but not for including.
Hi,
I'm relatively new to this, so I think I'm making an obvious mistake.
When I run deploy.php, I get:
fatal: could not read Username for 'https://github.com': No such device or address
Above that it says 'Environment OK', so I think that everything is OK serverwise. I've also created an SSH key (without a passphrase) on the server and added it to the repo settings.
Running CentOS7, simple-php-git-deploy 1.3.1
# git --version
git version 1.8.3.1
However, github webhook log shows
Checking the environment ...
Running as <b>nginx</b>.
<div class="error"><b>git</b> not available. It needs to be installed on the server for this script to work.</div>
When the deploy file runs I keep getting this error and now sure what I'm missing. Any suggestions? Which ssh key do I use?
Cloning into '/tmp/spgd-cbe1b60d9cb7e29bad7bf0ccc4c51853'...
Host key verification failed.
fatal: The remote end hung up unexpectedly
When I run the script, (some of the time) it shows
" Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request."
After taking an extremely long time to load, I'm not sure if this is simple-php-git-deploy's problem but its halting all my developing. If it is, I would be grateful if you could fix it. Thanks.
EDIT: When it happens to load, it shows
" Error encountered!
Stopping the script to prevent possible data loss.
CHECK THE DATA IN YOUR TARGET DIR!"
but when I check the target dir, it is completely intact compared to the github repo.
Currently, the script returns 200 OK
when the access is denied. A proper response of 403 Forbidden
should be returned.
Everything works fine, just when I delete a directory or a file in the local repo and push the commit on the remote server nothing is changed, I can see from 'top' git and rsync are called and executed just like when I edit or add a file/directory
Works brilliantly and easily with HTTPS for a public repo. I can get it to work with very little effort.
However I've been trying to get it to work with SSH and Dreamhost and getting blocked at every turn. Is there any possibility of getting the script to work with HTTPS for a private repo?
Hi,
Your script changes the permissions. E.g. when a file has a permission 644, your script makes it 600.
I use SUPHP and therefore 600 files can't be executed.
Thanks for a great script. I have a great deploy workflow up and running. My only question is how do I give PHP the right SSH key? When I make the repo private the script hangs.
$commands[] = sprintf(
'git --git-dir="%s.git" --work-tree="%s" fetch origin'
, TMP_DIR
, TMP_DIR
);
Warning: chdir(): No such file or directory (errno 2) in /var/www/deploy.php on line 184
I don't think you need this chdir, as all command have their path arguements.
Hi there !
I found this script is useful for me.
Is there a way to put any php function somewhere in the deploy.php ?
I would like to perform backup previous code files into zip file before updating the working directory and it should be able to call some function after updating the files as well.
is it possible ?
Regards,
Hi Marko, thanks for your great code, it really help me : )
There is a problem when I try to deploy with Git 1.8.2, I got error message
pathspec 'develop' did not match any file(s) known to git
, and I find the document says
When creating a shallow clone with the --depth option, this is the default, unless --no-single-branch is given to fetch the histories near the tips of all branches
I'm not sure whitch is better, to use option --no-single-branch
or just clone the specified branch for deployment?
Hope to help you
wake
now: ssh:[email protected]:xxx/xxx.git
before ssh:[email protected]/xxx/xxx.git
error info ssh: Could not resolve hostname bitbucket.org:xxx: Name or service not known
I've had some issues with git. I believe you could better call a PHP git library that handles all the git actions. This fixes not only the ssh key problems but gives more controll to the deployment script. There are some pretty good git php libraries available.
I keep getting the error 500 when the webhook is run. I've tried chmod 777 deploy.php on the remote server, but this does not seem to work. I've tried chmod 777 deploy.php while logged in as root and as the account owner user. I'm not sure what to try.
With no SSL encryption sending the secret is highly insecure, any sniffer on http traffic will read the sat parameter in plain text. The script should instead use, for example, the github payload hash.
I'm working on a Symfony application that needs some additional steps to be taken after pulling git changes (clear the cache, run migrations, etc).
Just wondering if there's an undocumented way to set this script up to run my custom post-deploy script, or if it's a feature that could be added.
It would basically be a config parameter that points to any executable file, and runs it after running everything else.
Rookie mistake, I'm sure, but where should I be looking to fix this? I am working with a private GitHub repo, and have added my server's SSH key to GitHub. Any ideas?
...
fatal: could not read Username for 'https://github.com': No such device or address
...
Error encountered!
Stopping the script to prevent possible data loss.
CHECK THE DATA IN YOUR TARGET DIR!
Most frequently used git workflows heavily uses "branching" and especially feature-branches.
Most sites won't use very many branches, but e.g. a stable and development branch aren't out of the question.
It would be a good idea to add support for this workflow.
I have tried to deploy my staging branch, added it to the line
define('BRANCH', 'Staging');
But no matter what I add it always clones master?
It would be nice to see composer support.
Pagoda box uses this deploy hook to install composer packages:
if [ ! -f composer.phar ]; then curl -s http://getcomposer.org/installer | php; fi; php composer.phar install
I got this error, please help!
Error encountered!
Stopping the script to prevent possible data loss.
CHECK THE DATA IN YOUR TARGET DIR!
I have set timeout for set_time_limit(30); OR set_time_limit(300000);
But It always 504 Gateway Time-out.
I'm using a private repository. I've already added my SSH keys and am able to do run git pull/push commands on my server (Amazon Linux) as the root user but looking to integrate with Github's webhooks using this plugin.
I've confirmed that my SECRET_ACCESS_TOKEN
, REMOTE_REPOSITORY
, BRANCH
, and TARGET_DIR
variables in my deploy-config.php are correct.
Checking the environment ...
Running as apache.
/usr/bin/git: git version 2.1.0
/usr/bin/rsync: rsync version 3.0.6 protocol version 30
Environment OK.
Deploying [email protected]:<username>/<project-name>.git branch
to /var/www/html/<project-name>/ ...
$ git clone --depth=1 --branch <branch> [email protected]:<username>/<project-name>.git /tmp/spgd-2cf28dc8d59c3eb61947660c8a9d13c5/
Cloning into '/tmp/spgd-2cf28dc8d59c3eb61947660c8a9d13c5'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Error encountered!
Stopping the script to prevent possible data loss.
CHECK THE DATA IN YOUR TARGET DIR!
Again, I'm able to run all git commands as the root user without problem. I'm also able to run this similar script without issue, but noticed that yours seemed more secure and wanted to give that a try.
Any help here would be appreciated.
Hi - we have this script running and it works great for both our Dev and Prod environments. A strange thing happened today - I deployed a couple of changes to our Dev and it worked fine. Then I merged those changes with our Master branch and deployed to Prod. This time it deployed the changed files, but the whole folder of one of our plugins that was not touched. Any ideas?
Update: on closer inspection it looks like folders were updated, but not files themselves. Strange.
I'm trying to deploy app on AWS under nginx
user. Line
$path = trim(shell_exec('which '.$command));
return empty result. After some debug I catch the problem. The PATH
variable is not exported. So the line:
$path = trim(shell_exec('export PATH=$PATH; which '.$command));
is working for. How about fix it?
I can't get deployment working from a public test repository on bitbucket, even though I use the same server that github deployment works on. Any idea what can be the reason? I know that bitbucket hook post gets triggered, but my server doesn't get updated.
Should the application type of the webhook be set to json or urlencoded? (Does it matter?)
I'm receiving the following:
Checking the environment ...
Running as {my username}.
/usr/bin/git : git version 1.7.9.5
/usr/bin/rsync : rsync version 3.0.9 protocol version 30
Environment OK.
Deploying https://github.com/{my username}/{my repo name}.git master
to /{my domain name}/ ...
$ git clone --depth=1 --branch master https://github.com/{my username}/{my repo name}.git /tmp/spgd-4bec90563b66bae9a40edcb0b612c31b/
Cloning into '/tmp/spgd-4bec90563b66bae9a40edcb0b612c31b'...
fatal: could not read Username for 'https://github.com': No such device or address
Error encountered!
Stopping the script to prevent possible data loss.
CHECK THE DATA IN YOUR TARGET DIR!
Two questions, I guess:
Just wondering if you have ever considered making an option for maintaining a repo on the server ...so that the entire repo need not be cloned before the rysnc operation takes place.
In other words, instead of cloning into tmp, you update a repo inside of tmp only pulling in changes. For large repos, this could speed things up significantly. Just an idea, thoughts?
Hi
Might be worth adding a comment about private repos.
You need to create an OAuth token in profile/applications and prepend before the github repo address:
https://[email protected]/username/yourrepo.git
If I've missed where it is mentioned my apologies.
Thanks
Rob
Because in most configurations www-data has no homedir, activating composer will end up in an exception called :
The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly
To prevent this Error I defined antoher const in the deploy-config called COMPOSER_HOME. The folder that's set here must be accessible for the poor homeless user ;-)
Now I could use
putenv('COMPOSER_HOME=/path/to/home');
Maybe this tip will be considered in the next version
So long
Christian
Hi, can you please add support for auto deploy multiple repo's?
For example, adding an array into the config file.
And provide a additional GET parameter for selecting the target repo like the array index (reduce traffic).
I think it's a bad practise for placing in every repo the 2 files (deploy.php
and deploy-config.php
)
is this script can be able to grab payload data as describe here https://help.github.com/articles/post-receive-hooks ?
Thanks
ssh: connect to host xx.xxx.xx.xxx port xx: Operation timed out
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
Looks like the response_code is not coming as 0 in the above case.
Thanks,
Manish
I have a client that has a hosting server and by security we can't allow "exec" or "shell_exec" to be executed on this server. So we can't configure and use the simple-php-git-deploy. A Workaround for this issue is to get the code from bitbucket's/github's using https. I could explain better my idea but I don't have enough technical knowledge for this, but I think some good programmer could do it.
This issue has been popping up randomly and I am not sure why it is happening. Script can sit and run for weeks and then suddenly dies.
$ git --git-dir="/tmp/spgd-development-49a97353830b85b9781e00f5c99a05da/.git" --work-tree="/tmp/spgd-development-49a97353830b85b9781e00f5c99a05da/" fetch origin development
fatal: Not a git repository: '/tmp/spgd-development-49a97353830b85b9781e00f5c99a05da/.git'
My current only solution is to ssh in and delete the /tmp/spgd-development-49a97353830b85b9781e00f5c99a05da/ folder
Does anybody know what could cause depolyment to fail from a private bitbucket repo? If I make the repo public it works, but as soon as I change it to private it fails. I have added my server's public ssh key (no pass phrase) as deployment key to the private bitbucket repo and a manual git pull works on my server. When I execute the deploy.php from shell I see no output.
Hi, I'm using your script for a private github project.
My deploy server is on google cloud compute engine (cloud VM).
After some days of working it fails with this error:
error: refs/remotes/origin/HEAD does not point to a valid object!
Why?
To resolve the problem I'm currently deleting the repository on the deploy server every time this happens and I'm cloning it again from github.
Thx
I have been trying to get the scriupt to work and found that it was trying to create a folder that wasnt where I intended to
Cloning into '/tmp/spgd-d9297d72e9817373d835e0eabb71b514-1364292767'...
Could not create directory '/var/www/.ssh'.
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
I added a whoami
to be echo and it is returning www-data
I would like to run it by my user. IS this possible?
The operation is successful in that all of the files transfer over successfully to the proper directory, but this error is causing the rest of the app to fail with
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.