Git Automatic Deployment Not Working (but Manual Deployment Is)

FourthFloor

Member
Oct 7, 2020
12
0
1
Ohio
cPanel Access Level
Reseller Owner
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:


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:

Bash:
#!/bin/sh

# post-receive                                       Copyright 2018 cPanel, Inc.
#                                                           All rights reserved.
# [email protected]                                         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]
 

Attachments

Last edited by a moderator:

cPanelJamesW

Linux Technical Analyst I
Staff member
Mar 13, 2018
24
1
78
Houston
cPanel Access Level
Root Administrator
Greetings,

Please try adding the following file - /home/<$USER>/<$ProjectRoot>/.git/hooks/post-commit - with the following contents:
Code:
#!/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:
Code:
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!
 

FourthFloor

Member
Oct 7, 2020
12
0
1
Ohio
cPanel Access Level
Reseller Owner
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.
 

FourthFloor

Member
Oct 7, 2020
12
0
1
Ohio
cPanel Access Level
Reseller Owner
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?
 

SamuelM

Technical Analyst Team Lead
Nov 20, 2019
196
41
103
USA
cPanel Access Level
Root Administrator
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.
 
  • Like
Reactions: FourthFloor

FourthFloor

Member
Oct 7, 2020
12
0
1
Ohio
cPanel Access Level
Reseller Owner
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.
 

cPanelChris

Moderator
Staff member
Feb 16, 2020
38
6
8
Houston, TX
cPanel Access Level
Root Administrator
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.

https://docs.cpanel.net/knowledge-base/web-services/guide-to-git-how-to-set-up-deployment/

Regarding it retaining the old Git files/branch, I would recommend opening a ticket regarding this so we can look into it more in-depth. This can be done using the link in my signature.
 
  • Like
Reactions: FourthFloor

FourthFloor

Member
Oct 7, 2020
12
0
1
Ohio
cPanel Access Level
Reseller Owner
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):
YAML:
deployment:
  tasks:
    - export DEPLOYPATH=/home/fourthfolio/subdomains/none
    - /bin/cp -R * $DEPLOYPATH
Contents of post-receive (CHMOD 700)
Bash:
#!/bin/sh

# post-receive                                       Copyright 2018 cPanel, Inc.
#                                                           All rights reserved.
# [email protected]                                         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
 

Attachments

FourthFloor

Member
Oct 7, 2020
12
0
1
Ohio
cPanel Access Level
Reseller Owner
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.
 

Attachments

Last edited:

FourthFloor

Member
Oct 7, 2020
12
0
1
Ohio
cPanel Access Level
Reseller Owner
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.
 

FourthFloor

Member
Oct 7, 2020
12
0
1
Ohio
cPanel Access Level
Reseller Owner
Note: The same is true for deleted files.

  1. They are removed from my local repository.
  2. Changes are pushed to the remote repository correctly.
  3. It is deployed to my public location and the deleted file persists.