Skip to main content

.cpanel.yml and Staging/Production environments

Comments

7 comments

  • cPanelLauren
    Hi @jjstruck I'm wondering if you've read the documentation here: This is specifically about checkout: And some information on hooks here:
    0
  • jjstruck
    I'm familiar with git and git checkout. And yes, I've read the documentation. The problem is that the .cpanel.yml HAS to be checked in. Simply being at the root of the directory isn't enough. Because of this, I can't have 2 separate .cpanel.yml's. One for my staging environment which I like to push from my local staging branch to the remote cPanel repo, and one for my production environment which I push from my local master branch to another remote cPanel repo.
    0
  • jjstruck
    I'm also confused on what githooks would do. The .cpanel.yml file needs to be checked into the repo. Can you explain more how I'd use githooks to help out here?
    0
  • jjstruck
    So I finally figured this out. I'm writing this out here for anyone who might be having the same issue. The secret to this is... you don't need the .cpanel.yml. 1. Create an empty repo in your cPanel portal. 2. Add that repo as a remote from your local/product repo (git add remote production/staging {repo clone url}). 3. Might need a force to push your local to the remote repo as there could be some errors thrown for different git histories. Once they're in sync, what you want to do is to look at the .git folder on your cPanel's repo folder. Inside you'll find a hooks folder. (.git/hooks). From here what you'll want to do is to create or edit a post-receive file. Inside you'll want to add this: #!/bin/bash while read oldrev newrev ref do branch=`echo $ref | cut -d/ -f3` if [ "master" == "$branch" ]; then git --work-tree=PATH_FROM_REPO_LOCATION_TO_PRODUCTION_FOLDER checkout -f $branch fi if [ "staging" == "$branch" ]; then git --work-tree=PATH_FROM_REPO_LOCATION_TO_STAGING_FOLDER checkout -f $branch fi done
    You'll probably need to tweak it/play with it to get it working for your side of things. Once you push to remote either yourself or using a build server, it should copy the files to the destination directory for your staging/production sites. I wish this was better documented rather than just pasting links and having people just figure things out. I hope this helps anyone else out there. I got so hung up on trying to find a workaround for the .cpanel.yml file. Hopefully this saves people time. I wish I had this when I started.
    0
  • cPanelLauren
    This is what I was actually leaning towards but I was waiting on one of our product owners who is currently traveling more familiar with this feature to provide more information. I did have a conversation with him briefly about this and he noted there was a specific security concern for why they were forcing you to checkin the .cpanel.yml file. I'd hoped the githooks documentation/information might provide a reliable path for you but I do also want to point out that this is a customization and we don't typically provide much documentation on customizations outside of the way the product is intended for use. I will also say that pending the method you're using doesn't have a security concern, I think we could use some resources/kb articles on the subject which I will look into further. Thanks!
    0
  • jjstruck
    If I could suggest that the .cpanel.yml need not be checked into the repo. That way people could just place the .cpanel.yml at the root of each remote repo directory and it would build against that rather than it needing to be checked in. Having it checked in works great if you don't use multiple environments, but as soon as you need to do that, the .cpanel.yml becomes just a hinderance.
    0
  • cPanelAdamF
    Originally the .cpanel.yml
    file mechanism was intended to be a very simple way of exposing a git-hook without needing to write a bash shell script or understand how git's hooking mechanism works. An option you could consider...if you'd rather not get into the .git/hooks
    dir to do it the more canonical way...would be to simply use the .cpanel.yml
    file as a dispatcher to a custom deploy script where your environment awareness lies. Something like... [CODE=yaml] # pseudo-code ahead --- deployment: tasks: - source ./deployment/environment.rc # created by hand during initial deployment environment setup, fills $PROJECT_ENV - ./deployment/deploy.sh $PROJECT_ENV
    ...where environment.rc
    is NOT checked in. deploy.sh
    could be written in your preferred programming language (rather than bash) as well.
    0

Please sign in to leave a comment.