Issues with the format of .cpanel.yml file when trying to deploy cpanel git repository to directory.
Asked Answered
C

1

10
  • I am using a cpanel web administration system.
  • With it i create a git repository.
  • I am able to push my local code to that git repository.

The problem arises when i attempt to deploy the code in the repository to a production directory on my server.

According to cpanel documentation about deployment, in order to deploy, a git repository must contain a .cpanel.yml file which is committed with the following example data:

---
deployment:
  tasks:
    - export DEPLOYPATH=/home/user/public_html/
    - /bin/cp index.html $DEPLOYPATH
    - /bin/cp style.css $DEPLOYPATH

I have tried various different configurations of this file in order to be able to deploy but couldn't get it to work. I cannot find any more documentation or any further develop examples or sample files.

The relevant structure of my linux server is thus:

home/<username>/
    - git/gitrepo/
        - all of the git files and folders
    - public_html/<app_folder>/

I would like to deploy all of the files and folders in the git repository into the public_html/<app_folder>/ directory.

I have tried the following different configurations:

---
deployment:
      tasks:
        - export DEPLOYPATH=/home/<username>/public_html/<app_folder>
        - / $DEPLOYPATH

---
deployment:
  tasks:
    - export DEPLOYPATH=/home/user/public_html/
    - /bin/cp  $DEPLOYPATH

---
deployment:
  tasks:
    - export DEPLOYPATH=/home/user/public_html/
    - / index.html $DEPLOYPATH // Tried just one file to see if would work but it didn't.
---
deployment:
  tasks:
    - export DEPLOYPATH=/home/user/public_html/
    - /bin/cp index.html $DEPLOYPATH // Tried just one file to see if would work but it didn't.
Caelian answered 7/10, 2018 at 13:31 Comment(2)
Hey Aviya, is your issue resolved?? if fixed can you please tell me which one it worked??Stephanstephana
@AmanJham The accepted answer worked well for me and solved my issue. Did it not work for you?Caelian
B
18

So this is basically a bash script that CPanel runs when you update your repo stored on the server. the layout in your case should be:

Please remove all "# comments" if you are copying the example or it might not work

---
deployment:
      tasks:
        - export DEPLOYPATH=/home/<username>/public_html/<app_folder>
        - /bin/cp <file_name> $DEPLOYPATH #Copy specific file to destination from root
        - /bin/cp /<sub_folder>/<file_name> $DEPLOYPATH #copy specific file from source sub folder
        - /bin cp * $DEPLOYPATH #copy all from root 
        - /bin cp /<sub_folder>/* $DEPLOYPATH #copy all from sub folder root

So the above should work for you.....but.....

If you are doing the whole root to destination then here is the one I use to just copy all.

---
deployment:
  tasks:
    - export DEPLOYPATH=/home/<user_name>/public_html #Add /<sub_folder> if required
    - /bin/cp -r * $DEPLOYPATH
  • /bin/cp "copy command"
  • -r "recursive include sub folder / files"
  • '*' "all"

Remember to add /<sub_folder> if you need an app folder other than public_html

You can get the file from my repo:

https://github.com/FrancoisGeyser/cPanel-yml.git

Hope that helps.

Bashaw answered 23/11, 2018 at 5:35 Comment(5)
Hey Francois, thank you very much for this thorough answer. I just wanted to say that I'm super busy and will only have time to go through this later on. But i will definitely do so and if it work i will be sure to mark it as the answer. For now i upvoted you. (It can just be quite annoying when you give a good answer and go on ignored so I wanted to let you know that this isn't the case! and welcome to stack-overflow!)Caelian
WORKS! Of course Friday night presented the best opportunity to finally check it haha. Thanks a lot man!Caelian
The One thing confuse me a bit @Bashaw should we have to add it to our code folder top directory or Cpanel top-level directory. Thanks in advanceBoehmite
Hi Hamad. It needs to be in your code folder top directory / root.Bashaw
/bin/cp -r * $DEPLOYPATH will put your .git folder online, usually that's not wantedDiarrhoea

© 2022 - 2024 — McMap. All rights reserved.