Skip to main content

Git Deployment: Automatic for Staging, Manual for Prod

Comments

6 comments

  • cPRex Jurassic Moderator
    Hey there! I don't see why this wouldn't work well on a cPanel system, but you just would be using these tools outside of cPanel itself. As long as the permissions and ownership on the files getting pulled from the Git repo are correct, I'd expect it to work.
    0
  • fs_cl
    Can you elaborate? I created a .cpanel.yml file with a condition that checks for the current git branch and deploys to a folder based on the branch. That's good. But it always deploys automatically. I would like it to deploy automatically if the branch is "staging" but not if "master." I want "master" to only deploy when the deployment is started manually. Are they are any environment variables that I can read in the .cpanel.yml file that will tell me if the deployment was started manually vs automatically? If so, I should be able to use that variable. My current .cpanel.yml file. [CODE=yaml]--- deployment: tasks: - export current_branch=$(git rev-parse --abbrev-ref HEAD) - echo $current_branch - if [ $current_branch == "master" ]; then export DEPLOYPATH=/home/my_username/site_prod/; fi; - if [ $current_branch == "staging" ]; then export DEPLOYPATH=/home/my_username/site_staging/; fi; - echo $DEPLOYPATH - /bin/cp -R ./Code/. $DEPLOYPATH
    Thanks
    0
  • cPRex Jurassic Moderator
    I'm not sure I really have much to elaborate on, honestly. I think it would be easier to have two deployments, and just push to the one you want to update. My original recommendation was just not using the cPanel Git tools at all, and strictly using Git from the command line interface, as that would eliminate any restrictions or limitations from our implementation.
    0
  • fs_cl
    Unfortunately, that doesn't help me much. 2 Deployments? I already have 2 folders and corresponding git branches. Are you suggesting a second cPanel, or, in our case, a second hosting account? And I use the git command line interface but that is on my local machine. That doesn't have anything to do with what the server does once the changes have been pushed. That is controlled by .cpanel.yml (correct?). Unless I can view a variable/parameter within the .cpanel.yml script, that specifies how the deployment was started, I don't see this working on a single cPanel. The only way I can see "2 Deployments" working would be: - 2 separate hosting accounts/cpanels - Staging cPanel uses its own cPanel git repo (with 2 branches - master and staging) - When "staging" pushes are made, since the Staging server hosts the git repo, the changes will be automatically deployed (with "staging" logic in the .cpanel.yml). - The Prod/master cPanel uses the repo on the Staging cpanel/server (essentially a remote repo). - Since the Prod cpanel is not hosting the repo, changes need to be deployed manually (going into cPanel and click "Deploy HEAD Commit" - with "master" logic in the .cpanel.yml). Thoughts? Thanks
    0
  • DroneSpec
    I had this question too, but maybe the OP should have said "How do you" instead of "Can you"? Fortunately I was able to figure it out from other sources. Here is example of what I did to only deploy when the master branch is pushed: [code=yaml] --- deployment: tasks: - export DEPLOYPATH=/home/public_html/ - export SRCPATH=/home/repositories/ - /bin/cp $SRCPATH/file $DEPLOYPATH ... when: condition: all: executeForMasterBranch: "'${{CF_BRANCH}}' == 'master'"
    Hope this is helpful Thanks
    0
  • saronlujan
    Hello! I had trouble understanding your file. Is it possible to show it completely? (Hidden sensitive and clear information). Thanks.
    0

Please sign in to leave a comment.