Composer, Git, and deployment workflow
This is a more general question regarding Git, but I'm applying it to SS, so I thought I'd ask here. I am a developer learning Git.
I am looking for the best way to work with development environment and live server. Now my setup is to use composer and GitHub for Mac to work on projects on my Mac. Then I use Beam to deploy to a live server.
The problem I am running into is that I cannot transfer SS modules to my repo for the project. Using GitHub for Mac, it says, "Failed to add module name to index." I still don't understand why this is happening. Since they are submodules with git?
So, I use Beam to deploy things like theme, custom code to live server and 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 live dev server and you don't have to login and execute composer commands on the live server. It will also help client sites that don't have composer installed on clean shared hosting.
So, is there a workaround or better way to deploy to live servers that I am not aware of?
source to share
I drive modules with composer and add composer.json
and composer.lock
to your git repository and all modules .gitignore
. With composer, you can easily update the structure and modules later.
You can automate some deployment using something like capistrano or using git hooks .
Capistrano works from its side, it logs in on a real server, pulls in and does some tasks for you. Wildstripe has several capistral receivers. It has some advantages (for example per release, easy rollback, DB backup for every version, etc.), but for me it went a little bit for very simple sites, I want to install a real fix quickly.
With git hooks, you still have to log into the server in real time, go to your website and run git pull
. Then git will pull your latest changes from the repo and do some tasks for you. I have this git post-merge hook for SilverStripe (just copy the script in .git/hooks/post-merge
on the real 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 automatically starts composer install
or composer update
and a dev/build
for me automatically.
Another tip: do not put your database or dev / test / live credentials in the git repository. Use _ss_environment.php instead . One for each car.
source to share
You don't need anything other than Git. They have this software and tools to make things easier, but it's too convoluted, confusing and too much.
Layout: on dev server install git and run the project
on dev server, edit, add, delete and commit files to repo
on prod install git pull
from git repo
when you develop, git commit
for a repo from dev
when you want to publish go to live server and issue gut pull
this is how i did it with cvs and svn. its the same idea with git. Works great.
make sure you follow the better. ssh over http
This is just my opinion from personal experience; don't take this word for word. I'm sure others have done it differently.
source to share