From a695ff704d90f98a21e2bdd40323e348d253a6ae Mon Sep 17 00:00:00 2001 From: Maarten de Boer Date: Wed, 1 Feb 2017 04:51:29 +0100 Subject: [PATCH] Initial commit with support for docker-compose and vagrant. --- plugins/appup/README.md | 13 +++++++ plugins/appup/appup.plugin.zsh | 70 ++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 plugins/appup/README.md create mode 100644 plugins/appup/appup.plugin.zsh diff --git a/plugins/appup/README.md b/plugins/appup/README.md new file mode 100644 index 00000000..ca610714 --- /dev/null +++ b/plugins/appup/README.md @@ -0,0 +1,13 @@ +## AppUp + +**Maintainers:** [mdeboer](https://github.com/mdeboer) + +This plugins adds `start`, `stop`, `up` and `down` commands when it detects a docker-compose or Vagrant file in the current directory (e.g. your application). Just run `up` and get coding! + +### Docker + +Aside from simply running `up`, you can also extend your configuration by running `up `, which will run `docker-compose` with both `docker-compose.yml` and extend it with `docker-compose..yml`. For more on extending please see the official docker documentation: https://docs.docker.com/compose/extends. Additional arguments will be directly supplied to the docker-compose. + +### Vagrant + +Vagrant doesn't have a `down`, `start` or `stop` commands natively but don't worry, that's been taken care of and running those commands will actually run vagrant's equivalent commands. Additional arguments will be directly supplied to vagrant. \ No newline at end of file diff --git a/plugins/appup/appup.plugin.zsh b/plugins/appup/appup.plugin.zsh new file mode 100644 index 00000000..215bbd99 --- /dev/null +++ b/plugins/appup/appup.plugin.zsh @@ -0,0 +1,70 @@ +# Docker +_appup_docker () { + if type docker-compose >/dev/null 2>&1; then + # will look for docker-compose..yml + if [ -n "$2" -a -e "docker-compose.$2.yml" ]; then + project=$(source ".env.$2"; echo $COMPOSE_PROJECT_NAME) + + if [ -n $project ]; then + docker-compose -p "${project}" -f docker-compose.yml -f "docker-compose.${2}.yml" $1 "${@:3}" + return + fi + + docker-compose -f docker-compose.yml -f "docker-compose.${2}.yml" $1 "${@:3}" + return + fi + + docker-compose $1 "${@:2}" + else + echo >&2 "Docker compose file found but docker-compose is not installed." + fi +} + +# Vagrant +_appup_vagrant () { + if type vagrant >/dev/null 2>&1; then + vagrant $1 "${@:2}" + else + echo >&2 "Vagrant file found but vagrant is not installed." + fi +} + +up () { + if [ -e "docker-compose.yml" ]; then + _appup_docker up "$@" + elif [ -e "Vagrantfile" ]; then + _appup_vagrant up "$@" + elif hash up >/dev/null 2>&1; then + env up "$@" + fi +} + +down () { + if [ -e "docker-compose.yml" ]; then + _appup_docker down "$@" + elif [ -e "Vagrantfile" ]; then + _appup_vagrant destroy "$@" + elif hash down >/dev/null 2>&1; then + env down "$@" + fi +} + +start () { + if [ -e "docker-compose.yml" ]; then + _appup_docker start "$@" + elif [ -e "Vagrantfile" ]; then + _appup_vagrant resume "$@" + elif hash start >/dev/null 2>&1; then + env start "$@" + fi +} + +stop () { + if [ -e "docker-compose.yml" ]; then + _appup_docker stop "$@" + elif [ -e "Vagrantfile" ]; then + _appup_vagrant suspend "$@" + elif hash stop >/dev/null 2>&1; then + env stop "$@" + fi +}