Skip to content

Instantly share code, notes, and snippets.

@thauanz
Created December 5, 2016 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thauanz/96bf679a28b3e7011ca733bfe7e7e453 to your computer and use it in GitHub Desktop.
Save thauanz/96bf679a28b3e7011ca733bfe7e7e453 to your computer and use it in GitHub Desktop.
Deployment for Marathon/Mesos
#!/bin/bash
ENVIRONMENT=$1
if [[ $ENVIRONMENT == '' ]]; then
echo "Specific ENVIRONMENT name like => ./deploy.sh production"
exit 0
fi
if [[ $IS_BUILD == '' ]]; then
IS_BUILD="no"
fi
if [[ $IS_DEPLOY == '' ]]; then
IS_DEPLOY="no"
fi
__last_commit(){
git log -1 --pretty=format:%h
}
__file(){
# Added the last commit for id APP. File format like this https://mesosphere.github.io/marathon/docs/rest-api.html#post-v2-apps
echo -e $(sed -E "s/(\"id\":) (\"\/[a-zA-Z0-9]*)/&-$(__last_commit)/" $1)
}
__build_and_push_docker_hub() {
docker build --no-cache -t container_name:$ENVIRONMENT ../.
docker push container_name:$ENVIRONMENT
}
__deploy() {
if [ "$ENVIRONMENT" == "staging" ]; then
__file "staging-lb.json" | curl -X POST http://localhost:8180/marathon/v2/apps -d @- -H "Content-type: application/json"
fi
if [ "$ENVIRONMENT" == "production" ]; then
__file "production-lb.json" | curl -X POST http://localhost:8080/marathon/v2/apps -d @- -H "Content-type: application/json"
fi
}
while true;
do
case $IS_BUILD in
yes ) __build_and_push_docker_hub ; break;;
no ) break;;
esac
done
while true;
do
case $IS_DEPLOY in
yes ) __deploy ; break;;
no ) break;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment