Created
January 14, 2015 12:14
-
-
Save Gargron/c971d4a9522e11ee842f to your computer and use it in GitHub Desktop.
Git hook (post-update) for gitolite
This file contains hidden or 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
#!/bin/bash | |
echo "Going to handle Docker image now..." | |
HOME="/home/dkr" | |
REPO=$GL_REPO | |
BARE_PATH="$HOME/repositories/$REPO.git" | |
WORK_PATH="$HOME/$REPO" | |
USER=$GL_USER | |
unset GIT_DIR | |
if [ ! -d "$WORK_PATH" ]; then | |
echo "Setting up working tree repository for the first time" | |
cd ~ | |
git clone $BARE_PATH | |
else | |
echo "Updating working tree" | |
cd $WORK_PATH | |
git pull origin master | |
fi | |
if docker ps | grep "$USER/$REPO"; then | |
echo "Running version of container detected, shutting down" | |
CONT_ID=$(docker ps | grep "$USER/$REPO" | tr -s " " "\012" | head -n 1) | |
docker stop $CONT_ID | |
fi | |
echo "Building container" | |
docker build -t "$USER/$REPO" $WORK_PATH | |
if [ ! -z "$GL_OPTION_VOL" ]; then | |
echo "Running container with mounted volume on $GL_OPTION_DOMAIN ($GL_OPTION_PORT)" | |
docker run \ | |
-v "$WORK_PATH/$GL_OPTION_VOL" \ | |
-e VIRTUAL_HOST=$GL_OPTION_DOMAIN \ | |
-p $GL_OPTION_PORT \ | |
--restart=always \ | |
-d "$USER/$REPO" | |
else | |
echo "Running container on $GL_OPTION_DOMAIN ($GL_OPTION_PORT)" | |
docker run \ | |
-e VIRTUAL_HOST=$GL_OPTION_DOMAIN \ | |
-p $GL_OPTION_PORT \ | |
--restart=always \ | |
-d "$USER/$REPO" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment