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!

Git, staging vs production, and YML

Discussion in 'General Discussion' started by tailored, Feb 20, 2019.

  1. tailored

    tailored Registered

    Sep 22, 2010
    Likes Received:
    Trophy Points:
    I've been trying a new workflow for deploying sites that has been working pretty well for me so far.
    1. Create
    2. Create git repo in cPanel account
    3. Add as "staging" remote from my workstation
    4. Add a .cpanel.yml file to my project for deployment
    And .cpanel.yml looks like:

    - export DEPLOYPATH=/home/user/
    - /bin/cp r * $DEPLOYPATH​

    Now I can run "git push staging", and my work will be pushed up to the repo, where the .cpanel.yml file copies files over to staging folder. Quick & easy - so far, so good.

    However, I'm still deploying to production manually.

    What I'd like to do is create a second "production" repo in the cPanel account, and then "git push production" from my workstation.

    But that would mean I need a different .cpanel.yml file to copy everything to the public_html folder instead. (or I'd have to keep editing the .cpanel.yml file DEPLOYPATH every time I want to switch between staging/production, which seems like a disaster waiting to happen when I forgot to change it back one time.)

    Is there some way of doing this, or can this be scripted in the YML somehow? (Is it possible to do a conditional statement, like if repo=staging then X)

    Alternative approaches would be something like:
    a) Build a script, then run on the server when we want to deploy.
    b) Add the copy commands to the post-receive hook file in the repo.

    Or is there a better workflow to manage this?
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager Staff Member

    Apr 11, 2011
    Likes Received:
    Trophy Points:
    cPanel Access Level:
    Root Administrator
    Hello @tailored,

    Have you considered using multiple branches (e.g. staging, production) in the same repo instead? If you did that, then you should be able to make implement an if/then condition that runs different commands depending on the branch name like the example here:

    post-receive hook for multiple branches

    Thank you.
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...

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