[v1.7-dev] Attach Git to your CyberPanel sites!

Hello all!

This article is about the GIT (version control system) and CyberPanel websites. People who use CyberPanel for development will be happy to know that they can attach Git repositories (GitHub and Gitlab) to CyberPanel websites, CyberPanel will use Git webhooks to deploy your apps directly from your repositories.

GIT Deployment

GIT is a modern version control system, we are not going to get into what GIT is and what it does, because if you are here I assume you are already using GIT in your development environments.

Today we will see how we can attach a remote GIT repo to your CyberPanel website.

Step 1: Create Github Repository!

With CyberPanel you can either attach repo from Github or Gitlab, but we are going to use GitHub in this article. If you already have a GitHub repo, you can skip this step.

Go to: Sign in to GitHub · GitHub

Simply fill in all the details and click Create Repository. This will create an empty repository and initialize it with README file.

Step 2: Deploy keys to your Repo!

Before moving any further, you need to deploy your server keys to your GitHub repository (GitLab have account level keys, whereas in GitHub you can add keys at repo level).

I assume you have already installed CyberPanel and created your first website.

After doing that navigate to:

https://IP Address:8090/websites/domain.com/setupGit

Replace domain.com with your website you want to attach repo to.

Click on Deployment Key and copy the key from the box. Now go to your repo to deploy this key.

Step 3: Attach repo to your CyberPanel website!

Once your keys are deployed, its time we attach the website to our repository. Again navigate to:

https://IP Address:8090/websites/domain.com/setupGit

By default Github is selected, however, the procedure is almost similar for GitLab, on this page just click GitLab to attach repo from GitLab service.

Fill in your username followed by repository name and click Attach Now. If your repo URL looks like:

https://github.com/usmannasir/cyberpanel

Here username is usmannasr and repo name is cyberpanel, you can adjust accordingly.

This will take some time and after few seconds your CyberPanel website is now attached to GitHub repository, there is one last step to perform so that any commits to your repository should initiate a git pull in your server so that you are always in sync with the repo.

Step 4: Setup Git Webhook!

Once the website is successfully attached to a repo, the page will refresh and you will see:

You can copy this URL (you will need to paste in Git webhooks section). Please note that you can replace IP in this URL with your hostname if you have used hostname SSL and have a valid Let’s Encrypt SSL. Otherwise, in Git webhook section, you will have to disable SSL check.

Please note here that I’ve disabled SSL check since by default CyberPanel uses self-signed SSL. Self-sign SSL will fail with SSL verification from GitHub, either disable SSL verification or setup CyberPanel on SSL and replace IP with that hostname (domain name).

This will make sure that whenever you push new code to your repo it is automatically pulled to your website.

If you have any questions, feel free to ask them below.

Installation

This branch is not pushed into production yet, so you can install via:

sh <(curl https://mirror.cyberpanel.net/install-test.sh || wget -O - https://mirror.cyberpanel.net/install-test.sh)

→ Processing Dependency: kernel-headers for package: glibc-headers-2.17-222.el7.x86_64
→ Finished Dependency Resolution
Error: Package: glibc-headers-2.17-222.el7.x86_64 (base)
Requires: kernel-headers >= 2.2.1
Error: Package: glibc-headers-2.17-222.el7.x86_64 (base)
Requires: kernel-headers
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest

[07-30-00-Sun-Aug-2018] #########################################################################

[07-30-00-Sun-Aug-2018] Unable to install GCC, trying again, try number: 2

[07-30-00-Sun-Aug-2018] #########################################################################

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile

  • epel: mirror.kinamo.be
    Resolving Dependencies
    → Running transaction check
    —> Package gcc.x86_64 0:4.8.5-28.el7_5.1 will be installed
    → Processing Dependency: cpp = 4.8.5-28.el7_5.1 for package: gcc-4.8.5-28.el7_5.1.x86_64
    → Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.8.5-28.el7_5.1.x86_64
    → Processing Dependency: libmpfr.so.4()(64bit) for package: gcc-4.8.5-28.el7_5.1.x86_64
    → Processing Dependency: libmpc.so.3()(64bit) for package: gcc-4.8.5-28.el7_5.1.x86_64
    → Running transaction check
    —> Package cpp.x86_64 0:4.8.5-28.el7_5.1 will be installed
    —> Package glibc-devel.x86_64 0:2.17-222.el7 will be installed
    → Processing Dependency: glibc-headers = 2.17-222.el7 for package: glibc-devel-2.17-222.el7.x86_64
    → Processing Dependency: glibc-headers for package: glibc-devel-2.17-222.el7.x86_64
    —> Package libmpc.x86_64 0:1.0.1-3.el7 will be installed
    —> Package mpfr.x86_64 0:3.1.1-4.el7 will be installed
    → Running transaction check
    —> Package glibc-headers.x86_64 0:2.17-222.el7 will be installed
    → Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.17-222.el7.x86_64
    → Processing Dependency: kernel-headers for package: glibc-headers-2.17-222.el7.x86_64
    → Finished Dependency Resolution
    Error: Package: glibc-headers-2.17-222.el7.x86_64 (base)
    Requires: kernel-headers >= 2.2.1
    Error: Package: glibc-headers-2.17-222.el7.x86_64 (base)
    Requires: kernel-headers
    You could try using --skip-broken to work around the problem
    You could try running: rpm -Va --nofiles --nodigest

[07-30-03-Sun-Aug-2018] #########################################################################

[07-30-03-Sun-Aug-2018] Unable to install GCC, trying again, try number: 3

[07-30-03-Sun-Aug-2018] #########################################################################

[07-30-03-Sun-Aug-2018] #########################################################################

[07-30-03-Sun-Aug-2018] Installation failed, consult: /var/log/installLogs.txt

[07-30-03-Sun-Aug-2018] #########################################################################

CyberPanel installation failed.
[root@word ~]#

Thats a great feature! Very nice panel!

Thank you!

i’m gettin Error message: Target directory should be empty before attaching GIT, otherwise data loss could occur. [404]

even it’s a newly created an empty repo

i'm gettin Error message: Target directory should be empty before attaching GIT, otherwise data loss could occur. [404]

even it’s a newly created an empty repo

You need to empty the directory you are attaching your git repo too, by default it contains index.html

i'm gettin Error message: Target directory should be empty before attaching GIT, otherwise data loss could occur. [404]

even it’s a newly created an empty repo

You need to empty the directory you are attaching your git repo too, by default it contains index.html

thanks! but it gives the error of:
Error message: Failed to clone repository, make sure you deployed your key to repository. [404]
now. I’ve deployed my keys and tried both GitHub and gitlab

im getting this same error, did you get it fixed
Error message: Failed to clone repository, make sure you deployed your key to repository. [404]

im getting this same error, did you get it fixed Error message: Failed to clone repository, make sure you deployed your key to repository. [404]

Find out the error and paste your logs here Troubleshooting CyberPanel - 14 - Logging & Troubleshooting - CyberPanel Community

Oct 30 14:18:57 trg gunicorn[23921]: mkdir: cannot create directory ‘/home/cyberpanel’: File exists
Oct 30 14:18:57 trg gunicorn[23921]: usage: git [–version] [–help] [-c name=value]
Oct 30 14:18:57 trg gunicorn[23921]: [–exec-path[=]] [–html-path] [–man-path] [–info-path]
Oct 30 14:18:57 trg gunicorn[23921]: [-p|–paginate|–no-pager] [–no-replace-objects] [–bare]
Oct 30 14:18:57 trg gunicorn[23921]: [–git-dir=] [–work-tree=] [–namespace=]
Oct 30 14:18:57 trg gunicorn[23921]: []
Oct 30 14:18:57 trg gunicorn[23921]: The most commonly used git commands are:
Oct 30 14:18:57 trg gunicorn[23921]: add Add file contents to the index
Oct 30 14:18:57 trg gunicorn[23921]: bisect Find by binary search the change that introduced a bug
Oct 30 14:18:57 trg gunicorn[23921]: branch List, create, or delete branches
Oct 30 14:18:57 trg gunicorn[23921]: checkout Checkout a branch or paths to the working tree
Oct 30 14:18:57 trg gunicorn[23921]: clone Clone a repository into a new directory
Oct 30 14:18:57 trg gunicorn[23921]: commit Record changes to the repository
Oct 30 14:18:57 trg gunicorn[23921]: diff Show changes between commits, commit and working tree, etc
Oct 30 14:18:57 trg gunicorn[23921]: fetch Download objects and refs from another repository
Oct 30 14:18:57 trg gunicorn[23921]: grep Print lines matching a pattern
Oct 30 14:18:57 trg gunicorn[23921]: init Create an empty Git repository or reinitialize an existing one
Oct 30 14:18:57 trg gunicorn[23921]: log Show commit logs
Oct 30 14:18:57 trg gunicorn[23921]: merge Join two or more development histories together
Oct 30 14:18:57 trg gunicorn[23921]: mv Move or rename a file, a directory, or a symlink
Oct 30 14:18:57 trg gunicorn[23921]: pull Fetch from and merge with another repository or a local branch
Oct 30 14:18:57 trg gunicorn[23921]: push Update remote refs along with associated objects
Oct 30 14:18:57 trg gunicorn[23921]: rebase Forward-port local commits to the updated upstream head
Oct 30 14:18:57 trg gunicorn[23921]: reset Reset current HEAD to the specified state
Oct 30 14:18:57 trg gunicorn[23921]: rm Remove files from the working tree and from the index
Oct 30 14:18:57 trg gunicorn[23921]: show Show various types of objects
Oct 30 14:18:57 trg gunicorn[23921]: status Show the working tree status
Oct 30 14:18:57 trg gunicorn[23921]: tag Create, list, delete or verify a tag object signed with GPG
Oct 30 14:18:57 trg gunicorn[23921]: ‘git help -a’ and ‘git help -g’ lists available subcommands and some
Oct 30 14:18:57 trg gunicorn[23921]: concept guides. See 'git help ’ or 'git help ’
Oct 30 14:18:57 trg gunicorn[23921]: to read about a specific subcommand or concept.
Oct 30 14:18:57 trg gunicorn[23921]: Host key verification failed.
Oct 30 14:18:57 trg gunicorn[23921]: fatal: Could not read from remote repository.
Oct 30 14:18:57 trg gunicorn[23921]: Please make sure you have the correct access rights
Oct 30 14:18:57 trg gunicorn[23921]: and the repository exists.

it’s great for dev, but, can we change default dir of git?
example i’m create sub-domain : dev.myproject.com with path /home/myproject.com/public_html/dev.myproject.com

then i’m create new folder outsite : /home/myproject.com/dev.myproject.com

but when using this feature, it’s always save all file into : /home/myproject.com/public_html/dev.myproject.com

can we set to this dir?
/home/myproject.com/dev.myproject.com

been trying to get this working, but can’t seem to find any error code, I have tried on both GitHub and Gitlab, with webhooks and deploy keys setup, etc. does it work on the free version? or just the paid version? any ideas on how best to troubleshoot?

Did you setup key at account level? Such as here → Sign in to GitHub · GitHub

And make sure directory is completely empty where you are trying to attach the repo if possible upgrade git from the command line.

when you say set the keys, that is to put the deploy key from the cyberpanel page to the github/gitlab settings? I have done that.

for the empty folder. after I have attached the git repo, the folder disappeared, can’t see it on the server again.

been trying to get this working, but can't seem to find any error code, I have tried on both GitHub and Gitlab, with webhooks and deploy keys setup, etc. does it work on the free version? or just the paid version? any ideas on how best to troubleshoot?
when you say set the keys, that is to put the deploy key from the cyberpanel page to the github/gitlab settings? I have done that.

for the empty folder. after I have attached the git repo, the folder disappeared, can’t see it on the server again.

i also have the same problem.

I have been doing more testing. using keys at both account and repo level. both not working. I am getting no errors with the 200 response code saying that it has been pulled. but no files was pulled to the empty directory. any hints on how best to troubleshoot this?

from GitHub webhook log

Headers
Connection: Keep-Alive
Content-Language: en
Content-Length: 38
Content-Type: text/html; charset=utf-8
Date: Mon, 29 Apr 2019 05:59:17 GMT
Server: LiteSpeed
Vary: Accept-Language, Cookie
X-Frame-Options: SAMEORIGIN

Body
{“error_message”: “None”, “pulled”: 1}

Did you successfully attached the repo, and having issues with setting up webhook? Or the repo is not attached at all?

Is this a private or public repo? Make sure the attaching directory does not even have a single file such as index.html

when I click on attach, it says successful. and I see the webhook url which I copied & pasted into the GitHub repo settings. and in the after commit, that’s the log entries above, saying that {“error_message”: “None”, “pulled”: 1}.

it is a private repo.
about the directory. should I manually remove all files from the folder and repo and try again?

does the webhook trigger a git command on the server? if so, where can I find the log or get it to output the log? so I can see if I can troubleshoot it better.

Just to confirm again, your repo is attached successfully and you are only having issues with webhook?

I tried with private repo, git pull and webhooks seems to work fine on my end.