Last active
August 29, 2015 14:05
-
-
Save joantune/7523c5989cfdd93d3fac to your computer and use it in GitHub Desktop.
Git post-update hook to deploy Play application on a Docker container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
. /home/deploy/.profile | |
set -e | |
workspace="/home/deploy/sandbox" | |
conf_files="/home/deploy/fb/conf" | |
repo_location="/home/deploy/feedburner" | |
project_name="feedburner" | |
#read oldrev newrev refname | |
last_commit=`git log -n 1 --pretty=format:%H` | |
echo "Got a commit. Building. LastCommit: $last_commit" | |
( | |
flock -x 200 || exit 1 | |
tmp_path="$workspace/$project_name-$last_commit" | |
echo "Checkout $last_commit --> $workspace" | |
git clone $repo_location $tmp_path | |
cd $tmp_path | |
echo "** Copying files from $conf_files to $tmp_path/conf **" | |
cp -v $conf_files/* $tmp_path/conf/ | |
echo "** Staging FeedBurner **" | |
JAVA_OPTS="-Xms256m -Xmx512m" play stage -feature -JXmx=512m -Xmx=512m | |
echo "** Building new container **" | |
#sudo docker build --tag="joantune/feedburner-prod:$last_commit" ./docker/joantune-feedburnerprod/Dockerfile | |
sudo docker build --tag="joantune/feedburner-prod:$last_commit" . | |
echo "** Stopping old container (if it exists)**" | |
sudo docker stop morningreader-web || true | |
sudo docker rm morningreader-web || true | |
echo "** Starting new container **" | |
sudo docker run -p 80:9000 -d --link morningreader-postgres:morningreader-postgres --name morningreader-web joantune/feedburner-prod:$last_commit | |
) 200>/var/lock/post-recive-hook.lock |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment