Recommended .cpanel.yml settings for Git Deployment?

kabatak

Well-Known Member
Jun 10, 2009
140
6
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?
 

kabatak

Well-Known Member
Jun 10, 2009
140
6
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.
 

kabatak

Well-Known Member
Jun 10, 2009
140
6
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.
 
Last edited by a moderator:

kabatak

Well-Known Member
Jun 10, 2009
140
6
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.
 
Last edited by a moderator:

johnwp

Registered
May 19, 2019
1
0
1
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.
 

mariavilaro

Registered
Jun 18, 2019
1
0
1
Barcelona
cPanel Access Level
Website Owner
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.
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.
 
Last edited by a moderator: