This is more of a general question regarding Git, but I'm applying it towards SS so thought I'd ask here. I'm a designer learning Git.
I'm looking for best way to work dev environment and live server. My setup now is to use composer and GitHub for Mac locally to work on projects on my Mac. I then use Beam to deploy to live server.
The issue I'm having is I can't commit SS modules to my repo for the project. Using GitHub for Mac, and it says 'failed to add module-name to index'. I'm still not clear on why this is happening. Because they're submodules with git?
So what I do is use Beam to deploy things like theme, custom code to live server, then from live server I login and run composer to install and update modules. It would be ideal if I could just push everything from my dev server live, and not have to login and run composer commands on live server. This would also help for client sites that don't have composer installed on crappy shared hosting.
So is there a workaround or better method for deploying to live servers I am unaware of?
I manage modules with composer and add the composer.json and composer.lock to your git repo and all module directories to .gitignore. With composer you can easily update the framework and modules later on.
You can automate some deployment, either using something like capistrano or using git hooks.
Capistrano works from your side, it logs in on the live server, pulls, and does some jobs for you. There are some capistrano receipes for SilverStripe out in the wild. It has some advantages (e.g. on dir for each release, easy rollback, backup of DB for each release etc...), but for me it felt a bit overkill for very simple websites i want to deploy real a hotfix real quickly.
With git hooks you still have to login on the live server, go to your webroot and run git pull. Then git will pull your lastest changes from the repo and do some jobs for you. I have this git post-merge hook for SilverStripe running (just copy the script to .git/hooks/post-merge on the live server):
#!/bin/bash
echo "running git post receive hook..."
DIR=$(git rev-parse --show-toplevel)
if [ -e "$DIR/composer.json" ]; then
if [ -d "$DIR/vendor" ]; then
composer.phar install
else
composer.phar update
fi
fi
echo "running dev/build"
sudo -u www-data php $DIR/framework/cli-script.php dev/build flush=1
It runs a composer install or composer update and a dev/build for me automatically.
One more tip: Don't put your database credentials or dev/test/live mode in your git repo. Use _ss_environment.php instead. One for each machine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With