Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Recommended .cpanel.yml settings for Git Deployment?

Discussion in 'General Discussion' started by kabatak, Dec 28, 2018.

  1. kabatak

    kabatak Well-Known Member

    Joined:
    Jun 10, 2009
    Messages:
    135
    Likes Received:
    5
    Trophy Points:
    68
    I'm using the following settings in my .cpanel.yml file
    Code:
    ---
    deployment:
      tasks:
        - export DEPLOYPATH=/home/example/public_html/
        - /bin/cp -a * $DEPLOYPATH
    
    This works fine for copying but not when a file was deleted in the repository.

    What's the recommended setting for "syncing" (add/update/delete) files when deploying?
     
  2. cPanelLauren

    cPanelLauren Forums Analyst II Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    5,815
    Likes Received:
    444
    Trophy Points:
    233
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. kabatak

    kabatak Well-Known Member

    Joined:
    Jun 10, 2009
    Messages:
    135
    Likes Received:
    5
    Trophy Points:
    68
    @cPanelLauren

    Yup! There's not much info regarding recommended .yml settings. It only suggests enumerating individual files to copy which is not really ideal.
     
  4. kabatak

    kabatak Well-Known Member

    Joined:
    Jun 10, 2009
    Messages:
    135
    Likes Received:
    5
    Trophy Points:
    68
    So I'm trying things and this works using rsync:

    Code:
    ---
    deployment:
      tasks:
       - export DEPLOYPATH=/home/example/public_html/
       - /usr/bin/rsync -a --delete * $DEPLOYPATH
    
    I'm still open to suggestions but it would also be nice if Cpanel have a built-in implementation of deploying code from Git rather than relying on custom user commands. E.g., What if the server doesn't have rsync?

    I think Cpanel's "Deploy" button should do this task by default without the need for a .cpanel.yml file. Only additional commands or special use case should be put under the .cpanel.yml file, because I think 99% of use cases will only want an "rsync" deployment.

    Edit: With the exception of indicating the deploy location (which requires an .cpanel.yml file), an "rysnc" functionality should be available to all users upon hitting deploy.
     
  5. kabatak

    kabatak Well-Known Member

    Joined:
    Jun 10, 2009
    Messages:
    135
    Likes Received:
    5
    Trophy Points:
    68
    Update:

    The previous script I posted does not actually work but this one now does:

    Code:
    ---
    deployment:
      tasks:
        - export DEPLOYPATH=/home/example/public_html/
        - /usr/bin/rsync -a --delete --exclude=".git" --exclude=".cpanel.yml" /home/example/repositories/testonly/ $DEPLOYPATH    
    Apparently, relative path from the repository dir does not work when using rsync, so we must use absolute path.

    Again, I wish this comes as default in the Cpanel "Deploy" button.
     
  6. johnwp

    johnwp Registered

    Joined:
    May 19, 2019
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    USA
    cPanel Access Level:
    Website Owner
    Thanks kabatak for the rsync suggestion. It works great compared to cp.

    I was expecting my original deployment config (below) to copy the contents of src/, but instead copied the src/ directory itself.

    $ cp -R src/ destination/
    works as expected in my local environment.

    Seems like a bug that
    /bin/cp -R src/ $DEPLOYPATH is ignoring the trailing slash in src/


    $ cat .cpanel.yml
    Code:
    ---
    deployment:
     tasks:
      - export DEPLOYPATH=/home/example/public_html/
      - /bin/rm -Rf $DEPLOYPATH
      - /bin/mkdir $DEPLOYPATH
      - /bin/cp -R src/ $DEPLOYPATH
    

    $ man cp
    Code:
         -R    If source_file designates a directory, cp copies the directory and the entire subtree connected at that point.  If the source_file ends in a /, the contents of the directory
               are copied rather than the directory itself.  This option also causes symbolic links to be copied, rather than indirected through, and for cp to create special files rather
               than copying them as normal files.  Created directories have the same mode as the corresponding source directory, unmodified by the process' umask.
    
     
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice