UAPI Clone Remote Git Repository
I'm looking to automatically clone a public git repo using the UAPI. The following code is working as far as creating a git repository into the public_html, however it's not actually cloning the remote repo. Am I missing something that would make it clone the remote repo?
Example:
And that returns the following: [CODE=json]{"status":1,"messages":null,"warnings":null,"metadata":{},"errors":null,"data":{"name":"test","tasks":[],"last_update":null,"available_branches":[],"deployable":0,"repository_root":"/home/test/public_html","last_deployment":null,"clone_urls":{"read_write":["ssh://test@test.com:7822/home/test/public_html">,"read_only":[]},"type":"git","branch":null}}
So now I have a .git folder in my public_html but it didn't clone any files from the remote repository. My end goal is to push to my remote repo and then pull those changes into public_html. Any ideas what I'm missing? Thanks!
https://www.domain.com:2083/cpsess3276056603/execute/VersionControl/create?type=git&name=test&repository_root=%2Fhome%2Ftest%2Fpublic_html&branch=master&source_repository%3D%27%7B%22remote_name%22%3A%22origin%22%2C%22url%22%3A%22https%3A%2F%2Fmycompany%40bitbucket.org%2Fmycompany%2Ftest.git%22%7D%27And that returns the following: [CODE=json]{"status":1,"messages":null,"warnings":null,"metadata":{},"errors":null,"data":{"name":"test","tasks":[],"last_update":null,"available_branches":[],"deployable":0,"repository_root":"/home/test/public_html","last_deployment":null,"clone_urls":{"read_write":["ssh://test@test.com:7822/home/test/public_html">,"read_only":[]},"type":"git","branch":null}}
So now I have a .git folder in my public_html but it didn't clone any files from the remote repository. My end goal is to push to my remote repo and then pull those changes into public_html. Any ideas what I'm missing? Thanks!
-
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 -
Hello @akreu Thank you for contacting cPanel! The Reviewing the output you received when you executed the API call, I did notice the following: "available_branches":[]
Are you certain the branch is published and you set up SSH key authentication? The following pages should help you validate that: Please let us know if you have any questions.0 -
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 -
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 -
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 -
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.
Comments
6 comments