[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: https://github.com/new



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)
Tagged:
Tagged:

Comments

  • --> 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.
    [[email protected] ~]#
  • edited August 31
    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
  • fahriuzun said:

    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
  • fahriuzun said:

    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
  • edited October 3
    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]
  • cole said:

    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 https://cyberpanel.net/docs/troubleshooting-cyberpanel/
  • 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
Sign In or Register to comment.
Support CyberPanel CyberPanel Discord

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!