Git Automatic Deployment Not Working (but Manual Deployment Is)
I've managed to get Git setup properly and have been able to successfully pull down from my Cpanel repository, commit changes and push back up to my Cpanel repository. I currently have my Cpanel.yml file setup like such:
[CODE=yaml]---
deployment:
tasks:
- export DEPLOYPATH=/home/$cpuser/subdomains/staging.$domain.com/
- /bin/cp -R * $DEPLOYPATH
I am able to log into Cpanel and see that my push was successful and that I have new files to deploy (see the attached screenshot). I am able to deploy manually, with my files accurately updating staging.$domain.com. I am unable to deploy automatically upon push to my Cpanel repository though. I have verified that I have a post-receive file, located in my Git repository, under the file path /.git/hooks/post-receive This is the contents of that file: [CODE=bash]#!/bin/sh # post-receive Copyright 2018 cPanel, Inc. # All rights reserved. # copyright@cpanel.net http://cpanel.net # This code is subject to the cPanel license. Unauthorized copying is prohibited branch=$(/usr/local/cpanel/3rdparty/bin/git branch | awk '$1 == "*"{print $2}') while read oldrev newrev ref do if [ "x$ref" == "xrefs/heads/$branch" ] then echo "Received update on checked-out branch, queueing deployment." (cd .. ; /usr/bin/uapi VersionControlDeployment create repository_root=$PWD) fi done < /dev/stdin
I can verify that there is a file called uapi in the path /usr/bin but I cannot access /usr/local/cpanel/ to verify any files or folders there. I cannot see anything in my .git logs that would indicate that there was a problem. It just doesn't seem to activate the post-receive. I did change permissions on the file to 777, just to ensure it wasn't an issue with permissions. Am I missing something? Help? [Moderator note: removed identifying information]
I am able to log into Cpanel and see that my push was successful and that I have new files to deploy (see the attached screenshot). I am able to deploy manually, with my files accurately updating staging.$domain.com. I am unable to deploy automatically upon push to my Cpanel repository though. I have verified that I have a post-receive file, located in my Git repository, under the file path /.git/hooks/post-receive This is the contents of that file: [CODE=bash]#!/bin/sh # post-receive Copyright 2018 cPanel, Inc. # All rights reserved. # copyright@cpanel.net http://cpanel.net # This code is subject to the cPanel license. Unauthorized copying is prohibited branch=$(/usr/local/cpanel/3rdparty/bin/git branch | awk '$1 == "*"{print $2}') while read oldrev newrev ref do if [ "x$ref" == "xrefs/heads/$branch" ] then echo "Received update on checked-out branch, queueing deployment." (cd .. ; /usr/bin/uapi VersionControlDeployment create repository_root=$PWD) fi done < /dev/stdin
I can verify that there is a file called uapi in the path /usr/bin but I cannot access /usr/local/cpanel/ to verify any files or folders there. I cannot see anything in my .git logs that would indicate that there was a problem. It just doesn't seem to activate the post-receive. I did change permissions on the file to 777, just to ensure it wasn't an issue with permissions. Am I missing something? Help? [Moderator note: removed identifying information]
-
Greetings, Please try adding the following file - /home/<$USER>/<$ProjectRoot>/.git/hooks/post-commit - with the following contents: #!/bin/bash unset GIT_INDEX_FILE git --work-tree=/home/<$USER>/<$DocumentRoot> --git-dir=/home/<$USER>/<$ProjectRoot>/.git checkout -f
Where 'ProjectRoot' is the path to your repo, 'USER' is the cPanel username and 'DocumentRoot' is the path to the document root of the site you wish to deploy. Then ensure that the post-commit hook is executable:chmod +x /home/<$USER>/<$ProjectRoot>/.git/hooks/post-commit
Now whenever a change is committed, it should also be deployed. Additionally, the git deploy logs can be found at - /home/$cPuser/cpanel/logs - where "cPuser" represents your cPanel username if you would like to review those for any possible issues that may be occurring. Thanks!0 -
Unfortunately that did not work. I reviewed my /home/$cPuser/cpanel/logs as you mentioned, and it only had deployment logs for when I manually deployed, as automatical deployment seems not to be firing at all. 0 -
So I have isolated the issue. When I make direct updates, on the server, to my git repository, it works. I added a new file "file.txt" and committed it (via Terminal). It was committed and deployed to the correct location. Zero problems. My issue seems to be, when pushing from my local computer. I push to my server, I see the connection happening, and Cpanel sees that I have received a new push, but it does not automatically deploy the changes. It does allow me to click the button for manual deployment. I am using the program Nova to do this. Would this have to do with my Git repository? Should I clone my repository from my server again to see if that helps with any of the issues? Does any of this make sense? 0 -
Hello @FourthFloor I suspect the issue might be due to the trailing slash in the repository root path. Issues with trailing slashes were recorded in our internal case CPANEL-28248. Can you please try re-creating the repository and ensure the repository path has no slash (/) at the end of its file path. Additionally, I would recommend you ensure the same change is reflected in the .cpanel.yml
file. Please let us know if the problem persists after making these changes.0 -
Well now it's rather royally screwed up. I deleted the remote file directory, the remote Git repository, my local file directory and my local Git repository and yet every time I recreate it all, it is retaining the old Git files/branch. As a side note, it's now not even allowing me to deploy it manually, where it was before. 0 -
Alright, I waited a few days, scrubbed everything and started over. There are no "ghost files" showing up that should not be there as there were. Now I have two repositories. One without the trailing slash in the repository path and one with the trailing slash, I have provided files for the one without the trailing slash. Both act the same and are fine to manually deploy, but will not automatically deploy. Let me include all the corresponding code: Test Repository Contents of .cpanel.yml, located in the root Git repository (in the correct spot, as is evident by the ability to manually deploy): [CODE=yaml]deployment: tasks: - export DEPLOYPATH=/home/fourthfolio/subdomains/none - /bin/cp -R * $DEPLOYPATH
Contents of post-receive (CHMOD 700) [CODE=bash]#!/bin/sh # post-receive Copyright 2018 cPanel, Inc. # All rights reserved. # copyright@cpanel.net http://cpanel.net # This code is subject to the cPanel license. Unauthorized copying is prohibited branch=$(/usr/local/cpanel/3rdparty/bin/git branch | awk '$1 == "*"{print $2}') while read oldrev newrev ref do if [ "x$ref" == "xrefs/heads/$branch" ] then echo "Recieved update on checked-out branch, queueing deployment." (cd .. ; /usr/bin/uapi VersionControlDeployment create repository_root=$PWD) fi done < /dev/stdin0 -
Again, I think the issue is from my local computer. I push to my server, I see the connection happening, and Cpanel sees that I have received a new push, but it does not automatically deploy the changes. It does allow me to click the button for manual deployment. Should I clone my repository from my server again to see if that helps with any of the issues? My local .git folder does not mirror that of the one on the server. Should it? Also, I made a direct update, on the server, to my git repository by adding a new file "file.txt" and committed it (via Terminal). It was committed and automatically deployed to the correct location. Zero problems. So again, it seems that something is getting hung up when I'm publishing remotely. As you can see though, my local .git directory has none of the hooks that my Cpanel remote directory has. 0 -
... 0 -
... 0 -
So I figured out a little more about the actual issue. I ended up copying the .git directory from the remote repository into my local directory and ensured that the post-receive file was executable. That seemed to resolve my issues with automatically deploying when I pushed NEW FILES from my local computer. I am still having this same issue when I am trying to push EDITED FILES from my local computer. When I have EDITED FILES that have been committed and then pushed, the commit changes are shown in my Deployment tab within Cpanel's Git interface, but they are not automatically pushed like when I have committed adding a NEW FILE. 0 -
Note: The same is true for deleted files. - They are removed from my local repository.
- Changes are pushed to the remote repository correctly.
- It is deployed to my public location and the deleted file persists.
0
Please sign in to leave a comment.
Comments
12 comments