Skip to main content

Git Automatic Deployment Not Working (but Manual Deployment Is)

Comments

12 comments

  • cPanelJamesW
    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
  • FourthFloor
    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
  • FourthFloor
    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
  • SamuelM
    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
  • FourthFloor
    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
  • cPanelChris
    Hello @FourthFloor , In order to deploy changes from a cPanel-managed repository, you must check a .cpanel.yml file into the top-level directory of your repository. I would recommend ensuring this has been done. Documentation regarding this can be found at the following link.
    0
  • FourthFloor
    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/stdin
    0
  • FourthFloor
    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
  • FourthFloor
    ...
    0
  • FourthFloor
    ...
    0
  • FourthFloor
    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
  • FourthFloor
    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.