Here is the git hook that will redeploy the application.
#!/usr/bin/env bash
SSH_USER="ondrej"
SERVER_IP="192.168.1.199"
REPO_NAME="mobydock"
# Check out the newest version of the code.
export GIT_WORK_TREE="/var/git/${REPO_NAME}"
git checkout -f
TAG="$(git log --pretty=format:'%h' -n 1)"
FULL_COMMIT_TAG="${REPO_NAME}:${TAG}"
FULL_LATEST_TAG="${REPO_NAME}:latest"
# Build the image with the proper commit tag.
docker build -t "${FULL_LATEST_TAG}" "${GIT_WORK_TREE}"
# Get the Docker ID of the last built image.
DOCKER_ID="$(docker images -q ${REPO_NAME} | head -1)"
# Tag a latest version based off a commit tag.
#docker tag -f "${DOCKER_ID}" "${FULL_LATEST_TAG}"
echo "Restarting ${REPO_NAME}"
docker stop "${REPO_NAME}"
echo "Removing untagged Docker images (may take a while)"
docker rmi $(docker images --quiet --filter "dangling=true")