KenSander
KenSander

Reputation: 113

Composer, Git And Deployment Workflow

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?

Upvotes: 3

Views: 1098

Answers (2)

wmk
wmk

Reputation: 4626

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.

Upvotes: 2

unixmiah
unixmiah

Reputation: 3143

You don't need anything else but Git. They have these software and tools to make things easier but it gets too cluttered, confusing and too many things.

Layout: on a dev server install git and start the project

on a dev server, edit, add, delete and commit files to the repo

on the prod install git pull from git repo

when you develop, git commit to the repo from dev

when you want to publish, go to the live server and issue gut pull

this is how i've done it with cvs and svn. its the same idea with git. it works like a charm.

make sure you do ssh over http, its better.

this is just my opinion from personal experience; don't take it word for word. i'm sure others have done it differently.

Upvotes: 0

Related Questions