tailored

Registered
Sep 22, 2010
1
0
51
I've been trying a new workflow for deploying sites that has been working pretty well for me so far.
  1. Create staging.website.com
  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:

---
deployment:
tasks:
- export DEPLOYPATH=/home/user/staging.website.com/
- /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 deploy-production.sh 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?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,228
463
b) Add the copy commands to the post-receive hook file in the repo.
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.
 

Steveboj

Registered
May 20, 2020
1
0
1
UK
cPanel Access Level
Reseller Owner
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.
Using this method is it possible to store 'DEPLOYPATH' variables for the different branches in the post-receive hook which could then be used by the .cpanel.yml file? Or would we have to move the copy commands into the post-receive hook as suggested by the original poster?