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:
    140
    Likes Received:
    6
    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:
    6,456
    Likes Received:
    503
    Trophy Points:
    263
    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:
    140
    Likes Received:
    6
    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:
    140
    Likes Received:
    6
    Trophy Points:
    68
    So I'm trying things and this works using rsync:

    Code:
    Moderator Note: Removed the rsync example command because it can lead to unexpected file removal.
    
    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.
     
    #4 kabatak, Dec 29, 2018
    Last edited by a moderator: Jun 18, 2019
  5. kabatak

    kabatak Well-Known Member

    Joined:
    Jun 10, 2009
    Messages:
    140
    Likes Received:
    6
    Trophy Points:
    68
    Update:

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

    Code:
    Removed the rsync example command because it can lead to unexpected file removal.
    
    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.
     
    #5 kabatak, Dec 29, 2018
    Last edited by a moderator: Jun 18, 2019
  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.
    
     
  7. mariavilaro

    mariavilaro Registered

    Joined:
    Jun 18, 2019
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Barcelona
    cPanel Access Level:
    Website Owner
    WARNING with this command! rsync --delete will delete also ignored files in the repo. So if you use for example a laravel application, the .env file will be deleted, and also all storage files created from the app... Ask me how I know.

    The only real solution, IMHO, is that cpanel did the checkout -f the branch to the destination folder.
     
    #7 mariavilaro, Jun 18, 2019
    Last edited by a moderator: Jun 18, 2019
  8. cPanelMichael

    cPanelMichael Technical Support Community Manager Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    47,525
    Likes Received:
    2,180
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello @mariavilaro,

    I edited the previous posts to remove references to that rsync command in an effort to prevent others from unintentionally removing files or directories under their accounts.

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
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