Skip to main content

UAPI Clone Remote Git Repository

Comments

6 comments

  • akreu
    Just adding to this, my end goal really is just be able to automatically clone a remote repo as soon as their account is created. Willing to do this via a hook or in any other manner if there's a way. Figured UAPI was the way to go but can't see to get it to work other than just creating a git repo.
    0
  • akreu
    Thanks @cPSamuel I'll take a look at those links. In my API call, it's a public repo and I'm using HTTPS link instead of SSH to avoid having to do any extra steps / create keys each time. (maybe there's a way to generate a single key that will work for all of my clients? Then I could use a private repo) But yeah, I need this to run seamlessly / automatically when a new customer signs up. Basically they're ordering a template and hosting from us, and I'm wanting the template to be auto deployed via git. But yea, the caveat here is I need it to run automatically once their cpanel account is created. So I'm not sure I could have that work if needing to generate a new SSH key each time and manually add it to my bitbucket account. I have everything pushed to master branch in our public repo
    0
  • SamuelM
    Hello again @akreu Thanks for the update. Now that you mention it, I do see that you provided an https:// URL for the repository in your API call. But then I noticed that in the API output, there is only an SSH URL in the clone_urls section: "clone_urls":{"read_write":["ssh://test@test.com:7822/home/test/public_html">,"read_only":[]}
    I'm curious about whether this is because the API is not properly recognizing a read_only https:// URL, or if maybe Bitbucket is not configured to make it visible. I understand that ultimately you would like to use the API to automatically clone the repo upon creating a cPanel account, and therefore using SSH keys may not be ideal. As a preliminary troubleshooting step can you let us know if you can successfully clone the repo via the command line with the https:// URL? I'm not sure if this will be possible with cPanel's implementation of Git Version Control, as our documentation says SSH access is required:
    0
  • akreu
    Hey @cPSamuel So I tried cloning via command line with the https:// url and it actually didn't work because the directory was not empty. It looks like cpanel automatically adds a cig-bin and .well-known folder to the public_html directory. Although I'm not sure if those folders are added before or after the API runs. If I run git clone from the command line on an empty directory under public_html, it works just fine. Trying to think of any other ways to achieve this workflow.. guess it might be back to the drawing board lol Thanks!
    0
  • akreu
    Just thought of something, not sure if this would be possible -- but maybe an idea. I could add my repos '.git' folder to the cpanel3-skel/public_html folder so it's automatically included on each account. If I have that already in there and then run the following via command line: git fetch origin master git reset --hard origin/master
    it then pulls my repo into public_html without any issues. So now my next question would be, is it possible to fire off these 2 shell commands via the UAPI? EDIT So I actually got this to work using a php library that allows me to ssh into the server remotely, so I'm able to clone my repository that way. Now I'm running into a separate issue. In doing this, I'm also creating a cron job that will automatically run git pull so I can have each server check for code updates. I'm doing the following to achieve this which actually does create a new cron job visible from cpanel: https://www.domain.com:2083/cpsess3276056603/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=Cron&cpanel_jsonapi_func=add_line&command=cd%20/home/myuser/public_html%20%26%26%20git%20pull&day=*&hour=*&minute=*&month=*&weekday=*
    However, it doesn't seem like the cron job ever actually runs. Any ideas on how to troubleshoot that aspect? Thanks!
    0

Please sign in to leave a comment.