A
A
Andrey Khokhlov2014-10-31 08:53:34
PHP
Andrey Khokhlov, 2014-10-31 08:53:34

Why doesn't deploy from bitbucket work?

Followed the instructions: jonathannicol.com/blog/2013/11/19/automated-git-de...
VPS server, Ubuntu 14.04
I did it on a test subdomain - everything works.
To celebrate, I immediately deleted everything and decided to do the same on the main one, with improvements.
Did not work out.
Now back to a simple version with a test subdomain.
And so, there is a private repository on bitbucket, 2 Deployment keys have been added:
1. For the username user (located in /home/username/.ssh)
2. For the www-data user (Apache runs under it, lies in /var/www)
There is only 1 file in the repository - index.php
Then I follow strictly according to the instructions, changing only the paths in bitbucket-hook.php (I also tried to change for git). Well, I only have a branch master
After executing the commands

git clone --mirror [email protected]:username/deploy.git
cd deploy.git
GIT_WORK_TREE=/var/www/deploy.example.com git checkout -f master

Index.php appeared in the /var/www/deploy.example.com folder
, and rights were also given (already tried this way and that) to the folder with the site and to the repository:
sudo chown -R username:www-data /var/www
sudo chown -R username:www-data deploy.git

Thus, for all the necessary folders, the owner is specified as:
Owner/group
username/www-data
I clone the repository on the computer, make changes, send a commit to the server...
Everything reaches bitbucket-hook.php, the log is written.
Then I noticed the following happens:
1. In the folder deploy.git, the owner of the index file changes to www-data/www-data
2. In the folder /var/www/deploy.example.com, the owner of the index.php file changes to www- data/www-data
And that's it, no changes.
If you now execute the commands that are written in bitbucket-hook.php
cd ~/deploy.git
git fetch
GIT_WORK_TREE=/var/www/deploy.example.com git checkout -f

The files will be updated.
At the same time,
/var/www/deploy.example.com/index.php
~/deploy.git/head
~/deploy.git/index
will become owner username/username
After that, if you send the commit again, nothing will happen except for logging with bitbucket...
What to do?
UPD:
I still suspect that www-data has a rights problem, but how to solve it ... I
manually execute the command from the script from www-data
9b7d1cea8afe48ae806b802a3bbdcd5c.PNG
The same command from my user
9d4c7f1c69f346bc80c85821a1eead99.PNG

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Khokhlov, 2014-11-03
@andrhohlov

Thanks to @DancingOnWater for the idea about the broken chown, helped me come up with a solution.
I came to the conclusion that you need to do all the actions from the www-data user, that is: -
generate an ssh key and config for it
- create a folder for the repository and clone the repository the folder with the git repository, and www-data should belong to /var/www (and I specified username/www-data). I checked the solution on a clean installation of the server, everything works. Maybe I'll make a manual if anyone needs it.

D
DancingOnWater, 2014-10-31
@DancingOnWater

I suspect that the repository from which the commit comes and the repository where the bitbuket should be merged is the same

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question