From c88d55b25d250a846b776c094865e15c848384ed Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Mon, 4 Jan 2016 19:13:11 +0000 Subject: [PATCH 01/44] Experiment with refactoring to Python --- .gitignore | 1 + dock => dock-old | 0 src/formula/__init__.py | 0 src/formula/mongodb.py | 2 + src/main.py | 94 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+) create mode 100644 .gitignore rename dock => dock-old (100%) create mode 100644 src/formula/__init__.py create mode 100644 src/formula/mongodb.py create mode 100644 src/main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/dock b/dock-old similarity index 100% rename from dock rename to dock-old diff --git a/src/formula/__init__.py b/src/formula/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/formula/mongodb.py b/src/formula/mongodb.py new file mode 100644 index 0000000..10a913f --- /dev/null +++ b/src/formula/mongodb.py @@ -0,0 +1,2 @@ +def run(): + print 'starting mongo' diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..e6a97f2 --- /dev/null +++ b/src/main.py @@ -0,0 +1,94 @@ +from os import chdir, listdir +from os.path import expanduser, exists, join +from argparse import ArgumentParser +from subprocess import call +import importlib + + +VERSION = '1.4.0' +REMOTE_REPO='https://github.com/bripkens/dock.git' +LOCAL_REPO = expanduser('~/.dock-formulas') +FORMULA_DIR = join(LOCAL_REPO, 'src', 'formula') + +def print_version(): + print 'dock {} by Ben Ripkens and contributors'.format(VERSION) + print 'https://github.com/bripkens/dock' + print 'local formula location: {}'.format(LOCAL_REPO) + + +def clone(): + call(['git', 'clone', REMOTE_REPO, LOCAL_REPO]) + + +def ensure_local_repo_exists(): + if (not exists(LOCAL_REPO)): + clone() + + +def upgrade(): + if (exists(LOCAL_REPO)): + chdir(LOCAL_REPO) + call(['git', 'pull', REMOTE_REPO, 'master']) + else: + clone() + + +def execute_formulas(formulas): + ensure_local_repo_exists() + for formula in formulas: + print '' + try: + mod = importlib.import_module('formula.' + formula) + path_to_module = join(FORMULA_DIR, formula + '.py') + print 'Starting {} (using {})'.format(formula, path_to_module) + mod.run() + except ImportError: + print_unknown_formula_contribution_hint(formula) + + +def print_unknown_formula_contribution_hint(formula): + print 'Unknown formula: {}'.format(formula) + print '' + print 'If you feel like {} should be supported by dock, please'.format(formula) + print 'consider opening an issue or sending a pull request to' + print '' + print ' https://github.com/bripkens/dock' + print '' + print 'Thanks!' + + + +def list_available_formulas(): + ensure_local_repo_exists() + + print ':: Built-In Formulas' + for formula in sorted(listdir(FORMULA_DIR)): + print formula + + +if __name__ == '__main__': + parser = ArgumentParser() + parser.add_argument('formulas', + help='Execute the given formulas in the order in which they are defined on the command line.', + nargs='*') + parser.add_argument('-v', '--version', + action='store_true', + help='Display current script version') + parser.add_argument('-u', '--upgrade', + action='store_true', + help='Upgrade list of available formulas') + parser.add_argument('-l', '--list', + action='store_true', + help='List available formulas') + args = parser.parse_args() + + if (args.version): + print_version() + elif (args.upgrade): + upgrade() + elif (args.list): + list_available_formulas() + elif (len(args.formulas)) == 0: + parser.print_help() + else: + execute_formulas(args.formulas) From 9a9bd0e686b945ad3f642ebdff302ccb7d2239ec Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Wed, 6 Jan 2016 19:29:20 +0000 Subject: [PATCH 02/44] Translate identification of working Docker setup --- src/main.py | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/src/main.py b/src/main.py index e6a97f2..70d1643 100644 --- a/src/main.py +++ b/src/main.py @@ -1,8 +1,10 @@ -from os import chdir, listdir +import sys + +from os import chdir, listdir, devnull from os.path import expanduser, exists, join from argparse import ArgumentParser from subprocess import call -import importlib +from importlib import import_module VERSION = '1.4.0' @@ -10,6 +12,7 @@ LOCAL_REPO = expanduser('~/.dock-formulas') FORMULA_DIR = join(LOCAL_REPO, 'src', 'formula') + def print_version(): print 'dock {} by Ben Ripkens and contributors'.format(VERSION) print 'https://github.com/bripkens/dock' @@ -27,25 +30,11 @@ def ensure_local_repo_exists(): def upgrade(): if (exists(LOCAL_REPO)): - chdir(LOCAL_REPO) - call(['git', 'pull', REMOTE_REPO, 'master']) + call(['git', 'pull', REMOTE_REPO, 'master'], cwd=LOCAL_REPO) else: clone() -def execute_formulas(formulas): - ensure_local_repo_exists() - for formula in formulas: - print '' - try: - mod = importlib.import_module('formula.' + formula) - path_to_module = join(FORMULA_DIR, formula + '.py') - print 'Starting {} (using {})'.format(formula, path_to_module) - mod.run() - except ImportError: - print_unknown_formula_contribution_hint(formula) - - def print_unknown_formula_contribution_hint(formula): print 'Unknown formula: {}'.format(formula) print '' @@ -66,6 +55,28 @@ def list_available_formulas(): print formula +def ensure_docker_usage_is_possible(): + returnCode = call(['docker', 'ps'], stdout=open(devnull, 'w')) + if (not returnCode == 0): + print 'It seems like there are issues with your' + print 'Docker setup. Please see the error above.' + sys.exit(1) + + +def execute_formulas(formulas): + ensure_local_repo_exists() + ensure_docker_usage_is_possible() + for formula in formulas: + print '' + try: + mod = import_module('formula.' + formula) + path_to_module = join(FORMULA_DIR, formula + '.py') + print 'Starting {} (using {})'.format(formula, path_to_module) + mod.run() + except ImportError: + print_unknown_formula_contribution_hint(formula) + + if __name__ == '__main__': parser = ArgumentParser() parser.add_argument('formulas', From 4caf73fcfcf75ddcb4eb47d975e5167efbde1c02 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sat, 9 Jan 2016 14:15:40 +0100 Subject: [PATCH 03/44] Adapt structure to Python conventions --- VERSION | 1 + src/main.py => dock/__init__.py | 76 ++++++++++++------------------- {src => dock}/formula/__init__.py | 0 {src => dock}/formula/mongodb.py | 0 4 files changed, 30 insertions(+), 47 deletions(-) create mode 100644 VERSION rename src/main.py => dock/__init__.py (55%) rename {src => dock}/formula/__init__.py (100%) rename {src => dock}/formula/mongodb.py (100%) diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..227cea2 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +2.0.0 diff --git a/src/main.py b/dock/__init__.py similarity index 55% rename from src/main.py rename to dock/__init__.py index 70d1643..3934540 100644 --- a/src/main.py +++ b/dock/__init__.py @@ -1,38 +1,30 @@ -import sys +#!/usr/local/opt/python/bin/python2.7 -from os import chdir, listdir, devnull -from os.path import expanduser, exists, join -from argparse import ArgumentParser -from subprocess import call -from importlib import import_module +import argparse +import importlib +import os +import os.path +import re +import subprocess +HERE = os.path.abspath(os.path.dirname(__file__)) +FORMULA_DIR = os.path.join(HERE, 'formula') -VERSION = '1.4.0' -REMOTE_REPO='https://github.com/bripkens/dock.git' -LOCAL_REPO = expanduser('~/.dock-formulas') -FORMULA_DIR = join(LOCAL_REPO, 'src', 'formula') +with open(os.path.join(HERE, '..', 'VERSION')) as f: + VERSION = f.read().strip() def print_version(): print 'dock {} by Ben Ripkens and contributors'.format(VERSION) print 'https://github.com/bripkens/dock' - print 'local formula location: {}'.format(LOCAL_REPO) -def clone(): - call(['git', 'clone', REMOTE_REPO, LOCAL_REPO]) - - -def ensure_local_repo_exists(): - if (not exists(LOCAL_REPO)): - clone() - - -def upgrade(): - if (exists(LOCAL_REPO)): - call(['git', 'pull', REMOTE_REPO, 'master'], cwd=LOCAL_REPO) - else: - clone() +def list_available_formulas(): + print ':: Built-In Formulas' + for formula in sorted(os.listdir(FORMULA_DIR)): + if (formula.endswith('.py') and not formula == '__init__.py'): + match = re.search('([^.]+)\\.', formula) + print match.group(1) def print_unknown_formula_contribution_hint(formula): @@ -46,48 +38,36 @@ def print_unknown_formula_contribution_hint(formula): print 'Thanks!' - -def list_available_formulas(): - ensure_local_repo_exists() - - print ':: Built-In Formulas' - for formula in sorted(listdir(FORMULA_DIR)): - print formula - - def ensure_docker_usage_is_possible(): - returnCode = call(['docker', 'ps'], stdout=open(devnull, 'w')) + returnCode = subprocess.call(['docker', 'ps'], stdout=open(os.devnull, 'w')) if (not returnCode == 0): - print 'It seems like there are issues with your' - print 'Docker setup. Please see the error above.' + print 'It seems like there are issues with your Docker setup.' sys.exit(1) def execute_formulas(formulas): - ensure_local_repo_exists() ensure_docker_usage_is_possible() for formula in formulas: print '' try: - mod = import_module('formula.' + formula) - path_to_module = join(FORMULA_DIR, formula + '.py') + mod = importlib.import_module('formula.' + formula) + path_to_module = os.path.join(FORMULA_DIR, formula + '.py') print 'Starting {} (using {})'.format(formula, path_to_module) mod.run() except ImportError: print_unknown_formula_contribution_hint(formula) -if __name__ == '__main__': - parser = ArgumentParser() +def main(): + parser = argparse.ArgumentParser(prog='dock', + usage='%(prog)s [options] [formulas...]', + description='easily bootstrap development tools with Docker') parser.add_argument('formulas', help='Execute the given formulas in the order in which they are defined on the command line.', nargs='*') parser.add_argument('-v', '--version', action='store_true', help='Display current script version') - parser.add_argument('-u', '--upgrade', - action='store_true', - help='Upgrade list of available formulas') parser.add_argument('-l', '--list', action='store_true', help='List available formulas') @@ -95,11 +75,13 @@ def execute_formulas(formulas): if (args.version): print_version() - elif (args.upgrade): - upgrade() elif (args.list): list_available_formulas() elif (len(args.formulas)) == 0: parser.print_help() else: execute_formulas(args.formulas) + + +if __name__ == '__main__': + main() diff --git a/src/formula/__init__.py b/dock/formula/__init__.py similarity index 100% rename from src/formula/__init__.py rename to dock/formula/__init__.py diff --git a/src/formula/mongodb.py b/dock/formula/mongodb.py similarity index 100% rename from src/formula/mongodb.py rename to dock/formula/mongodb.py From 6546d159d010b20adb19e61009c6d6312b1f5ba4 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sat, 9 Jan 2016 19:08:35 +0100 Subject: [PATCH 04/44] Start with actual formula development --- dock/__init__.py | 21 +++++++++++--------- dock/docker.py | 43 +++++++++++++++++++++++++++++++++++++++++ dock/formula/mongodb.py | 9 ++++++++- 3 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 dock/docker.py diff --git a/dock/__init__.py b/dock/__init__.py index 3934540..31934c7 100644 --- a/dock/__init__.py +++ b/dock/__init__.py @@ -22,7 +22,7 @@ def print_version(): def list_available_formulas(): print ':: Built-In Formulas' for formula in sorted(os.listdir(FORMULA_DIR)): - if (formula.endswith('.py') and not formula == '__init__.py'): + if formula.endswith('.py') and not formula == '__init__.py': match = re.search('([^.]+)\\.', formula) print match.group(1) @@ -40,7 +40,7 @@ def print_unknown_formula_contribution_hint(formula): def ensure_docker_usage_is_possible(): returnCode = subprocess.call(['docker', 'ps'], stdout=open(os.devnull, 'w')) - if (not returnCode == 0): + if not returnCode == 0: print 'It seems like there are issues with your Docker setup.' sys.exit(1) @@ -49,13 +49,16 @@ def execute_formulas(formulas): ensure_docker_usage_is_possible() for formula in formulas: print '' + module_name = 'formula.' + formula try: - mod = importlib.import_module('formula.' + formula) + mod = importlib.import_module(module_name) path_to_module = os.path.join(FORMULA_DIR, formula + '.py') - print 'Starting {} (using {})'.format(formula, path_to_module) mod.run() - except ImportError: - print_unknown_formula_contribution_hint(formula) + except ImportError as e: + if e.message.endswith(module_name): + print_unknown_formula_contribution_hint(formula) + else: + raise def main(): @@ -73,11 +76,11 @@ def main(): help='List available formulas') args = parser.parse_args() - if (args.version): + if args.version: print_version() - elif (args.list): + elif args.list: list_available_formulas() - elif (len(args.formulas)) == 0: + elif len(args.formulas) == 0: parser.print_help() else: execute_formulas(args.formulas) diff --git a/dock/docker.py b/dock/docker.py new file mode 100644 index 0000000..a1443e1 --- /dev/null +++ b/dock/docker.py @@ -0,0 +1,43 @@ +import json +import os +import subprocess + +devnull = open(os.devnull, 'w') + + +def add_name_prefix(container_name): + return 'dock-' + container_name + + +def force_stop(name): + name = add_name_prefix(name) + subprocess.call(['docker', 'stop', name], + stdout=devnull, + stderr=devnull) + subprocess.call(['docker', 'rm', name], + stdout=devnull, + stderr=devnull) + + +def run(image, name=None, publish=[]): + if (name == None): + name = image + + name = add_name_prefix(name) + + # combine args to Docker run CLI args + args = ['docker', 'run', '--detach', '--name', name] + for publishedPort in publish: + args.extend(['--publish', '{}:{}'.format(publishedPort, publishedPort)]) + args.append(image) + print 'Starting image {} as container {}'.format(image, name) + subprocess.call(args) + + print_run_data(name) + + +def print_run_data(name): + output = subprocess.check_output(['docker', 'inspect', name]) + data = json.loads(output)[0] + print data['NetworkSettings']['Ports'] + # print data diff --git a/dock/formula/mongodb.py b/dock/formula/mongodb.py index 10a913f..c257f1e 100644 --- a/dock/formula/mongodb.py +++ b/dock/formula/mongodb.py @@ -1,2 +1,9 @@ +import docker + +container_name = 'mongodb' + def run(): - print 'starting mongo' + docker.force_stop(container_name) + docker.run(image='mongo:3.2.0', + name=container_name, + publish=[27017, 27018]) From 93859752cd24905db4d75d500ef6f8fb2a7bb9e6 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 07:13:41 +0100 Subject: [PATCH 05/44] Get IPs and allow cleanup process --- dock/__init__.py | 7 +++- dock/docker.py | 79 ++++++++++++++++++++++++++++++++++----- dock/formula/docker-gc.py | 9 +++++ 3 files changed, 84 insertions(+), 11 deletions(-) create mode 100644 dock/formula/docker-gc.py diff --git a/dock/__init__.py b/dock/__init__.py index 31934c7..6156b34 100644 --- a/dock/__init__.py +++ b/dock/__init__.py @@ -55,7 +55,7 @@ def execute_formulas(formulas): path_to_module = os.path.join(FORMULA_DIR, formula + '.py') mod.run() except ImportError as e: - if e.message.endswith(module_name): + if e.message.endswith(formula): print_unknown_formula_contribution_hint(formula) else: raise @@ -74,10 +74,15 @@ def main(): parser.add_argument('-l', '--list', action='store_true', help='List available formulas') + parser.add_argument('--cleanup', + action='store_true', + help='Remove unused containers and images via docker-gc') args = parser.parse_args() if args.version: print_version() + if args.cleanup: + execute_formulas(['docker-gc']) elif args.list: list_available_formulas() elif len(args.formulas) == 0: diff --git a/dock/docker.py b/dock/docker.py index a1443e1..fb6e8cf 100644 --- a/dock/docker.py +++ b/dock/docker.py @@ -1,5 +1,6 @@ import json import os +import re import subprocess devnull = open(os.devnull, 'w') @@ -9,6 +10,11 @@ def add_name_prefix(container_name): return 'dock-' + container_name +def generate_name_from_image(image): + # Docker container names cannot contain slashes + return image.replace('/', '_') + + def force_stop(name): name = add_name_prefix(name) subprocess.call(['docker', 'stop', name], @@ -19,25 +25,78 @@ def force_stop(name): stderr=devnull) -def run(image, name=None, publish=[]): - if (name == None): - name = image +def run(image, + name=None, + publish=[], + auto_remove=False, + detach=True, + mount_docker_socket=False, + silent=False): + if name == None: + name = generate_name_from_image(image) name = add_name_prefix(name) - # combine args to Docker run CLI args - args = ['docker', 'run', '--detach', '--name', name] + args = ['docker', 'run', '--name', name] + + if detach: + args.append('--detach') + + if auto_remove: + args.append('--rm') + + if mount_docker_socket: + args.extend(['--volume', '/var/run/docker.sock:/var/run/docker.sock']) + for publishedPort in publish: args.extend(['--publish', '{}:{}'.format(publishedPort, publishedPort)]) + args.append(image) - print 'Starting image {} as container {}'.format(image, name) + if not silent: + print 'Starting image {} as container {}'.format(image, name) subprocess.call(args) - print_run_data(name) + if not silent: + print_run_data(name) + + +def strip_protocol_from_port(port): + return re.search('^(\d+)', port).group(1) + + +def get_ip(): + try: + docker_machine_name = os.environ['DOCKER_MACHINE_NAME'] + return subprocess.check_output(['docker-machine', + 'ip', + docker_machine_name], + stderr=devnull).strip() + except KeyError: + pass + + try: + return subprocess.check_output(['boot2docker', 'ip'], + stderr=devnull) + except subprocess.CalledProcessError: + pass + + return '127.0.0.1' def print_run_data(name): output = subprocess.check_output(['docker', 'inspect', name]) - data = json.loads(output)[0] - print data['NetworkSettings']['Ports'] - # print data + port_mappings = json.loads(output)[0]['NetworkSettings']['Ports'] + ports = port_mappings.keys() + ports.sort() + + print 'Container Name: {}'.format(name) + print 'IP: {}'.format(get_ip()) + + if len(ports) > 0: + print 'Ports: Host -> Container' + + for port in ports: + stripped_port = strip_protocol_from_port(port) + for host_port in port_mappings[port]: + print ' {} -> {}'.format(host_port['HostPort'].ljust(5, ' '), + stripped_port) diff --git a/dock/formula/docker-gc.py b/dock/formula/docker-gc.py new file mode 100644 index 0000000..8ec4e5b --- /dev/null +++ b/dock/formula/docker-gc.py @@ -0,0 +1,9 @@ +import docker + +def run(): + print 'Starting cleanup process via docker-gc...' + docker.run(image='spotify/docker-gc', + auto_remove=True, + detach=False, + mount_docker_socket=True, + silent=True) From bc6eee47c399b924a51cb3c6c77f79cef2883884 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 07:51:18 +0100 Subject: [PATCH 06/44] Remove bash based scripts --- common | 61 ------------ dock-old | 196 --------------------------------------- formulas/activemq | 16 ---- formulas/apacheds | 13 --- formulas/artifactory | 10 -- formulas/cachet | 43 --------- formulas/cassandra | 16 ---- formulas/cassandra-cqlsh | 8 -- formulas/couchdb | 10 -- formulas/couchdb-ssl | 15 --- formulas/docker-gc | 5 - formulas/elasticsearch | 11 --- formulas/jenkins | 10 -- formulas/kafka | 28 ------ formulas/kafka-cli | 15 --- formulas/memcached | 10 -- formulas/mongodb | 11 --- formulas/mysql | 25 ----- formulas/mysql-cli | 8 -- formulas/neo4j | 10 -- formulas/nexus | 19 ---- formulas/node | 7 -- formulas/orientdb | 14 --- formulas/php5-apache | 13 --- formulas/php5-fpm | 13 --- formulas/php7-apache | 13 --- formulas/php7-fpm | 13 --- formulas/postgres | 13 --- formulas/postgres-cli | 8 -- formulas/rabbitmq | 14 --- formulas/redis | 10 -- formulas/redis-cli | 8 -- formulas/rethinkdb | 12 --- formulas/sonar | 21 ----- formulas/ubuntu | 7 -- formulas/wordpress | 19 ---- formulas/zookeeper | 12 --- 37 files changed, 737 deletions(-) delete mode 100644 common delete mode 100755 dock-old delete mode 100644 formulas/activemq delete mode 100644 formulas/apacheds delete mode 100644 formulas/artifactory delete mode 100644 formulas/cachet delete mode 100644 formulas/cassandra delete mode 100644 formulas/cassandra-cqlsh delete mode 100644 formulas/couchdb delete mode 100644 formulas/couchdb-ssl delete mode 100644 formulas/docker-gc delete mode 100644 formulas/elasticsearch delete mode 100644 formulas/jenkins delete mode 100644 formulas/kafka delete mode 100644 formulas/kafka-cli delete mode 100644 formulas/memcached delete mode 100644 formulas/mongodb delete mode 100644 formulas/mysql delete mode 100644 formulas/mysql-cli delete mode 100644 formulas/neo4j delete mode 100644 formulas/nexus delete mode 100644 formulas/node delete mode 100644 formulas/orientdb delete mode 100644 formulas/php5-apache delete mode 100644 formulas/php5-fpm delete mode 100644 formulas/php7-apache delete mode 100644 formulas/php7-fpm delete mode 100644 formulas/postgres delete mode 100644 formulas/postgres-cli delete mode 100644 formulas/rabbitmq delete mode 100644 formulas/redis delete mode 100644 formulas/redis-cli delete mode 100644 formulas/rethinkdb delete mode 100644 formulas/sonar delete mode 100644 formulas/ubuntu delete mode 100644 formulas/wordpress delete mode 100644 formulas/zookeeper diff --git a/common b/common deleted file mode 100644 index 5962f98..0000000 --- a/common +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash - -force_stop() { - docker stop $1 &> /dev/null - docker rm $1 &> /dev/null -} - - -inspect() { - if hash docker-machine 2>/dev/null; then - docker-machine ssh $DOCKER_MACHINE_NAME docker inspect --format=$2 $1 - elif hash boot2docker 2>/dev/null; then - boot2docker ssh docker inspect --format=$2 $1 - else - docker inspect --format=$2 $1 - fi -} - - -get_ip() { - if hash docker-machine 2>/dev/null; then - docker-machine ip $DOCKER_MACHINE_NAME 2>/dev/null - elif hash boot2docker 2>/dev/null; then - boot2docker ip 2>/dev/null - else - # The following gives the ip address of the container. We - # don't need this information though. On Linux systems the - # systems can be accessed via 127.0.0.1 - # docker inspect --format={{.NetworkSettings.IPAddress}} $1 - - echo "127.0.0.1" - fi -} - - -run() { - docker run "$@" - local status=$? - if [ $status -ne 0 ]; then - echo >&2 - echo "Failed to start the Docker container." >&2 - exit 1 - fi - - local container_id="$(docker ps -n=1 | tail -n 1 | awk '{print $1}')" - local container_name=$(inspect $container_id '{{.Name}}') - # strip the leading / character - container_name=${container_name#?} - - local container_ip=$(get_ip $container_id) - - local host_ports=$(inspect $container_id '' | \ - grep HostPort | \ - sed 's/[^0-9]*//g' | \ - sort -nu) - - echo "Container started" - echo "Name: $container_name" - echo "IP: $container_ip" - echo "Ports: $(echo $host_ports | tr '\\n' ',')" -} diff --git a/dock-old b/dock-old deleted file mode 100755 index d0263d3..0000000 --- a/dock-old +++ /dev/null @@ -1,196 +0,0 @@ -#!/bin/bash -# -# Script for easily running development systems in docker containers -# https://github.com/bripkens/dock -# - -remote_repo=https://github.com/bripkens/dock.git -local_repo=$HOME/.dock-formulas -working_dir=`pwd` - - -version() { - echo "$(basename $0) 1.3.0 by Ben Ripkens and contributors" - echo "https://github.com/bripkens/dock" -} - - -usage() { - version -cat << EOF >&2 - -easily bootstrap development tools with Docker - -Usage: - $(basename $0) [options] - $(basename $0) [formula...] - -Example: - $(basename $0) redis - -Options: - -l, --list List available formulas - -c, --cat [formula] Display formula details - -u, --upgrade Upgrade list of available formulas - -d, --rm Stop and remove all containers - -h, --help Display this help text - -v, --version Display current script version -EOF -} - - -clone() { - if [ $1 -a $1 = '--silently' ]; then - git clone -q "$remote_repo" "$local_repo" - else - echo "Cloning $remote_repo to $local_repo" - git clone "$remote_repo" "$local_repo" - fi -} - - -upgrade() { - if [ ! -e "$local_repo/.git" ]; then - clone - else - cd "$local_repo" - git pull origin master - fi -} - - -init() { - if [ ! -e "$local_repo/.git" ]; then - clone $1 - fi -} - - -list() { - init --silently - - echo ":: Build-in Formulas" - listFormulas "$local_repo"/formulas - if [ -d "$working_dir"/.dock-formulas ]; then - echo ":: Project Formulas" - listFormulas "$working_dir"/.dock-formulas - fi -} - -listFormulas() { - for path in $(ls "$1" | sort -f); do - filename=$(basename $path) - echo "${filename%.*}" - done -} - - -unknown_formula() { - echo "Unknown formula: $1" >&2 - echo >&2 - echo "If you feel like $1 should be supported by dock, please" >&2 - echo "consider opening an issue or sending a pull request to" >&2 - echo >&2 - echo " https://github.com/bripkens/dock" >&2 - echo >&2 - echo "Thanks!" >&2 -} - - -dump() { - init --silently - - formula="$local_repo/formulas/$1" - - if [ -e "$formula" ]; then - cat $formula - else - unknown_formula $1 - fi -} - - -check_docker_usage_possible() { - docker ps > /dev/null - local status=$? - if [ $status -ne 0 ]; then - echo >&2 - echo "It seems like there are issues with your" >&2 - echo "Docker setup. Please see the error above." >&2 - exit 1 - fi -} - - -start() { - init --silently - check_docker_usage_possible - - project_formula="$working_dir/.dock-formulas/$1" - builtin_formula="$local_repo/formulas/$1" - - if [ -e "$project_formula" ]; then - startFormula $1 $project_formula - elif [ -e "$builtin_formula" ]; then - startFormula $1 $builtin_formula - else - unknown_formula $1 - fi -} - -startFormula() { - echo - echo "Starting $1 (using $2)..." - bash $2 -} - -stop_and_remove() { - check_docker_usage_possible - - container=$(docker ps -a | grep dock- | awk '{print $1}') - if [ -n "$container" ]; then - docker stop $container - docker rm $container - fi -} - - -# --- Main entry point ---------------------- -if [ $# -eq 0 ]; then - usage - exit 0 -fi - -# Parse comand-line options -while [ $# -gt 0 ]; do - case $1 in - -v | --version ) - version - exit 1 - ;; - -l | --list ) - list - exit - ;; - -u | --upgrade ) - upgrade - exit - ;; - -h | --help ) - usage - exit 1 - ;; - -c | --cat ) - dump $2 - exit - ;; - -d | --rm ) - stop_and_remove - exit - ;; - * ) # default case - start $1 - ;; - esac - shift -done diff --git a/formulas/activemq b/formulas/activemq deleted file mode 100644 index 7afb913..0000000 --- a/formulas/activemq +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-activemq - -run --detach \ - --publish 8161:8161 \ - --publish 61612:61612 \ - --publish 61613:61613 \ - --publish 61616:61616 \ - --name dock-activemq \ - aterreno/activemq-dockerfile - -echo "Admin user: admin" -echo "Admin pw: admin" diff --git a/formulas/apacheds b/formulas/apacheds deleted file mode 100644 index 1728f34..0000000 --- a/formulas/apacheds +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-apacheds - -run --detach \ - --publish 10389:10389 \ - --name dock-apacheds \ - jjhughes57/apacheds-docker - -echo "Admin user: uid=admin,ou=system" -echo "Admin pw: secret" diff --git a/formulas/artifactory b/formulas/artifactory deleted file mode 100644 index c967e05..0000000 --- a/formulas/artifactory +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-artifactory - -run --detach \ - --publish 8473:8081 \ - --name dock-artifactory \ - jfrog-docker-registry.bintray.io/jfrog/artifactory-oss diff --git a/formulas/cachet b/formulas/cachet deleted file mode 100644 index 2816052..0000000 --- a/formulas/cachet +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-cachet-mysql -force_stop dock-cachet - -root_pw="root" -db="dockDatabase" -user="dockUser" -user_pw="dockPassword" - -run --detach \ - --env MYSQL_ROOT_PASSWORD=$root_pw \ - --env MYSQL_USER=$user \ - --env MYSQL_PASSWORD=$user_pw \ - --env MYSQL_DATABASE=$db \ - --name dock-cachet-mysql \ - mysql - -echo "Root password: $root_pw" -echo -echo "Database: $db" -echo "User: $user" -echo "User password: $user_pw" - -run --detach \ - --link dock-cachet-mysql:mysql \ - --env DB_HOST=mysql \ - --env DB_DATABASE=$db \ - --env DB_USERNAME=$user \ - --env DB_PASSWORD=$user_pw \ - --publish 8585:8000 \ - --name dock-cachet \ - cachethq/docker:latest - -sleep 5 -docker exec dock-cachet php artisan migrate --force -docker exec dock-cachet php artisan key:generate -docker exec dock-cachet php artisan config:cache - -echo "Cache started. You can now access it via:" -echo " http://192.168.59.103:8585/setup" diff --git a/formulas/cassandra b/formulas/cassandra deleted file mode 100644 index 950616f..0000000 --- a/formulas/cassandra +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-cassandra - -run --detach \ - --publish 7000:7000 \ - --publish 7001:7001 \ - --publish 7199:7199 \ - --publish 9042:9042 \ - --publish 9160:9160 \ - --name dock-cassandra \ - abh1nav/cassandra - -echo "Pro Tip: You can use Cassandra's CQLSH via 'dock cassandra-cqlsh'." diff --git a/formulas/cassandra-cqlsh b/formulas/cassandra-cqlsh deleted file mode 100644 index 0e5f557..0000000 --- a/formulas/cassandra-cqlsh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -docker run --interactive \ - --tty \ - --rm \ - --link dock-cassandra:cassandra \ - relateiq/cassandra \ - bash -c 'exec /opt/cassandra/bin/cqlsh "$CASSANDRA_PORT_9160_TCP_ADDR" "$CASSANDRA_PORT_9160_TCP_PORT"' diff --git a/formulas/couchdb b/formulas/couchdb deleted file mode 100644 index ca117b0..0000000 --- a/formulas/couchdb +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-couchdb - -run --detach \ - --publish 5984:5984 \ - --name dock-couchdb \ - klaemo/couchdb:latest diff --git a/formulas/couchdb-ssl b/formulas/couchdb-ssl deleted file mode 100644 index 9f8cada..0000000 --- a/formulas/couchdb-ssl +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-couchdb-ssl - -run --detach \ - --publish 6984:6984 \ - --name dock-couchdb-ssl \ - klaemo/couchdb-ssl:latest - -echo 'Note: CouchDB is only accepting https connections on port 6984.' -echo ' Make sure to accept self-signed and unverified, i.e.' -echo ' insecure, connections.' -echo ' Example: curl -k https://$DOCKER_IP:6984' diff --git a/formulas/docker-gc b/formulas/docker-gc deleted file mode 100644 index 0a72903..0000000 --- a/formulas/docker-gc +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -docker run --rm \ - --volume /var/run/docker.sock:/var/run/docker.sock \ - spotify/docker-gc diff --git a/formulas/elasticsearch b/formulas/elasticsearch deleted file mode 100644 index bafc77a..0000000 --- a/formulas/elasticsearch +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-elasticsearch - -run --detach \ - --publish 9200:9200 \ - --publish 9300:9300 \ - --name dock-elasticsearch \ - elasticsearch diff --git a/formulas/jenkins b/formulas/jenkins deleted file mode 100644 index 34bc06c..0000000 --- a/formulas/jenkins +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-jenkins - -run --detach \ - --publish 8472:8080 \ - --name dock-jenkins \ - jenkins diff --git a/formulas/kafka b/formulas/kafka deleted file mode 100644 index a29d2bd..0000000 --- a/formulas/kafka +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -# This setup is based on the following GitHub repository and fig file -# https://github.com/wurstmeister/kafka-docker - -source "${BASH_SOURCE%/*}/../common" - -if [ -z "$(docker ps | grep dock-zookeeper)" ]; then - echo "Zookeeper hasn't beed started, but is required by Kafka." - dock zookeeper -fi - -echo -echo "Starting three Kafka instances..." - -for i in {1..3}; do - echo - - force_stop "dock-kafka-$i" - - run --detach \ - --publish "909$(($i + 1)):9092" \ - --env "KAFKA_ADVERTISED_HOST_NAME=192.168.59.103" \ - --volume "/var/run/docker.sock:/var/run/docker.sock" \ - --link dock-zookeeper:zk \ - --name "dock-kafka-$i" \ - wurstmeister/kafka:0.8.1.1-1 -done diff --git a/formulas/kafka-cli b/formulas/kafka-cli deleted file mode 100644 index 7e42d1d..0000000 --- a/formulas/kafka-cli +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -echo ' -# Starting an interactive Docker container which contains the -# CLI tools. Inspect the env to learn about IPs and ports. -# Kafka is located at $KAFKA_HOME.' - -docker run --interactive \ - --tty \ - --link dock-zookeeper:zk \ - --link dock-kafka-1:kafka-1 \ - --link dock-kafka-2:kafka-2 \ - --link dock-kafka-3:kafka-3 \ - wurstmeister/kafka:0.8.1.1-1 \ - bash diff --git a/formulas/memcached b/formulas/memcached deleted file mode 100644 index 16c98dd..0000000 --- a/formulas/memcached +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-memcached - -run --detach \ - --publish 11211:11211 \ - --name dock-memcached \ - memcached diff --git a/formulas/mongodb b/formulas/mongodb deleted file mode 100644 index 3b754a9..0000000 --- a/formulas/mongodb +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-mongodb - -run --detach \ - --publish 27017:27017 \ - --publish 27018:27018 \ - --name dock-mongodb \ - mongo diff --git a/formulas/mysql b/formulas/mysql deleted file mode 100644 index 6014a92..0000000 --- a/formulas/mysql +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-mysql - -root_pw="root" -db="dockDatabase" -user="dockUser" -user_pw="dockPassword" - -run --detach \ - --env MYSQL_ROOT_PASSWORD=$root_pw \ - --env MYSQL_USER=$user \ - --env MYSQL_PASSWORD=$user_pw \ - --env MYSQL_DATABASE=$db \ - --publish 3306:3306 \ - --name dock-mysql \ - mysql - -echo "Root password: $root_pw" -echo -echo "Database: $db" -echo "User: $user" -echo "User password: $user_pw" diff --git a/formulas/mysql-cli b/formulas/mysql-cli deleted file mode 100644 index 96f81ef..0000000 --- a/formulas/mysql-cli +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -docker run --interactive \ - --tty \ - --rm \ - --link dock-mysql:mysql \ - mysql \ - sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"' diff --git a/formulas/neo4j b/formulas/neo4j deleted file mode 100644 index ce0ee00..0000000 --- a/formulas/neo4j +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-neo4j - -run --detach \ - --publish 7474:7474 \ - --name dock-neo4j \ - neo4j/neo4j diff --git a/formulas/nexus b/formulas/nexus deleted file mode 100644 index 3924d04..0000000 --- a/formulas/nexus +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -# more about configuring nexus -# http://books.sonatype.com/nexus-book/2.10/reference/npm-configuring.html -# -# original cudos to Marcello de Sales: -# https://registry.hub.docker.com/u/marcellodesales/nexus-npm-registry/ - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-nexus - -run --detach \ - --publish 8081:8081 \ - --name dock-nexus \ - marcellodesales/nexus-npm-registry - -echo "Admin user: admin" -echo "Admin pw: admin123" diff --git a/formulas/node b/formulas/node deleted file mode 100644 index c335838..0000000 --- a/formulas/node +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -docker run --interactive \ - --tty \ - --rm \ - node \ - node diff --git a/formulas/orientdb b/formulas/orientdb deleted file mode 100644 index 914c0cd..0000000 --- a/formulas/orientdb +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-orientdb - -run --detach \ - --publish 2424:2424 \ - --publish 2480:2480 \ - --name dock-orientdb \ - joaodubas/orientdb - -echo "Admin user: admin" -echo "Admin pw: admin" diff --git a/formulas/php5-apache b/formulas/php5-apache deleted file mode 100644 index 8a8778e..0000000 --- a/formulas/php5-apache +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-php5-apache - -run --detach \ - --publish 80 \ - --name dock-php5-apache \ - --volume $(pwd):/var/www/html \ - php:5-apache - -echo "Mounted $(pwd) into /var/www/html" diff --git a/formulas/php5-fpm b/formulas/php5-fpm deleted file mode 100644 index 90d58c2..0000000 --- a/formulas/php5-fpm +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-php5-fpm - -run --detach \ - --publish 9000 \ - --name dock-php5-fpm \ - --volume $(pwd):/var/www/html \ - php:5-fpm - -echo "Mounted $(pwd) into /var/www/html" diff --git a/formulas/php7-apache b/formulas/php7-apache deleted file mode 100644 index ea410a5..0000000 --- a/formulas/php7-apache +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-php7-apache - -run --detach \ - --publish 80 \ - --name dock-php7-apache \ - --volume $(pwd):/var/www/html \ - php:7-apache - -echo "Mounted $(pwd) into /var/www/html" diff --git a/formulas/php7-fpm b/formulas/php7-fpm deleted file mode 100644 index 94ac56b..0000000 --- a/formulas/php7-fpm +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-php7-fpm - -run --detach \ - --publish 9000 \ - --name dock-php7-fpm \ - --volume $(pwd):/var/www/html \ - php:7-fpm - -echo "Mounted $(pwd) into /var/www/html" diff --git a/formulas/postgres b/formulas/postgres deleted file mode 100644 index 92410cf..0000000 --- a/formulas/postgres +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-postgres - -run --detach \ - --name dock-postgres \ - --publish 5432:5432 \ - postgres - -echo "Default User: postgres" -echo "Pro Tip: You can use the postgres CLI via 'dock postgres-cli'." diff --git a/formulas/postgres-cli b/formulas/postgres-cli deleted file mode 100644 index 5413e2f..0000000 --- a/formulas/postgres-cli +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -docker run --interactive \ - --tty \ - --rm \ - --link dock-postgres:postgres \ - postgres \ - bash -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres' diff --git a/formulas/rabbitmq b/formulas/rabbitmq deleted file mode 100644 index b5474b3..0000000 --- a/formulas/rabbitmq +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-rabbitmq - -run --detach \ - --name dock-rabbitmq \ - --publish 5672:5672 \ - --publish 15672:15672 \ - tutum/rabbitmq - -echo "Admin user: admin" -echo "Admin password: Inspect the password via 'docker logs dock-rabbitmq'" diff --git a/formulas/redis b/formulas/redis deleted file mode 100644 index 8742b92..0000000 --- a/formulas/redis +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-redis - -run --detach \ - --name dock-redis \ - --publish 6379:6379 \ - redis diff --git a/formulas/redis-cli b/formulas/redis-cli deleted file mode 100644 index c1bda02..0000000 --- a/formulas/redis-cli +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -docker run --interactive \ - --tty \ - --rm \ - --link dock-redis:redis \ - redis \ - bash -c 'redis-cli -h $REDIS_PORT_6379_TCP_ADDR' diff --git a/formulas/rethinkdb b/formulas/rethinkdb deleted file mode 100644 index bebb6fa..0000000 --- a/formulas/rethinkdb +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-rethinkdb - -run --detach \ - --publish 8080:8080 \ - --publish 28015:28015 \ - --publish 29015:29015 \ - --name dock-rethinkdb \ - shipyard/rethinkdb diff --git a/formulas/sonar b/formulas/sonar deleted file mode 100644 index 8caae5f..0000000 --- a/formulas/sonar +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-sonar-server -force_stop dock-sonar-mysql - -run --detach \ - --publish 3306:3306 \ - --name dock-sonar-mysql \ - tpires/sonar-mysql - -echo -run --detach \ - --publish 8474:9000 \ - --name dock-sonar-server \ - --link dock-sonar-mysql:db \ - tpires/sonar-server - -echo "Admin user: admin" -echo "Admin pw: admin" diff --git a/formulas/ubuntu b/formulas/ubuntu deleted file mode 100644 index 0e5a533..0000000 --- a/formulas/ubuntu +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -docker run --interactive \ - --tty \ - --rm \ - ubuntu \ - bash diff --git a/formulas/wordpress b/formulas/wordpress deleted file mode 100644 index 65ff238..0000000 --- a/formulas/wordpress +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -if [ -z "$(docker ps | grep dock-mysql)" ]; then - echo "MySQL hasn't beed started, but is required by Wordpress." - dock mysql -fi - -force_stop dock-wordpress - -run --detach \ - --publish 8686:80 \ - --name dock-wordpress \ - --link dock-mysql:mysql \ - wordpress:latest - -echo "Wordpress Database name: wordpress" -echo "Wordpress Database user: root" diff --git a/formulas/zookeeper b/formulas/zookeeper deleted file mode 100644 index 649fcfa..0000000 --- a/formulas/zookeeper +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -source "${BASH_SOURCE%/*}/../common" - -force_stop dock-zookeeper - -run --detach \ - --publish 2181:2181 \ - --publish 2888:2888 \ - --publish 3888:3888 \ - --name dock-zookeeper \ - jplock/zookeeper:3.4.6 From 7d31b4e341a1b06d5ed73453d0cf8953d7a17fc9 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 07:51:43 +0100 Subject: [PATCH 07/44] Add project metadata --- MANIFEST.in | 1 + setup.cfg | 2 ++ setup.py | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 MANIFEST.in create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..1aba38f --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include LICENSE diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..3c6e79c --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[bdist_wheel] +universal=1 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..a8d53bd --- /dev/null +++ b/setup.py @@ -0,0 +1,100 @@ +from setuptools import setup, find_packages +from codecs import open +from os import path + +HERE = path.abspath(path.dirname(__file__)) + +# Get the long description from the README file +with open(path.join(HERE, 'README.md'), encoding='utf-8') as f: + LONG_DESCRIPTION = f.read() + +with open(path.join(HERE, 'VERSION'), encoding='utf-8') as f: + VERSION = f.read().strip() + +setup( + name='dock-upload-test', + + version=VERSION, + + description='Bootstrap databases, MOMs and other tools that you need for development purposes', + long_description=LONG_DESCRIPTION, + + url='https://github.com/bripkens/dock', + + author='Ben Ripkens', + author_email='bripkens@gmail.com', + + license='MIT', + + # See https://pypi.python.org/pypi?%3Aaction=list_classifiers + classifiers=[ + # How mature is this project? Common values are + # 3 - Alpha + # 4 - Beta + # 5 - Production/Stable + 'Development Status :: 4 - Beta', + + # Indicate who your project is intended for + 'Intended Audience :: Developers', + 'Topic :: Software Development', + + # Pick your license as you wish (should match "license" above) + 'License :: OSI Approved :: MIT License', + + # Specify the Python versions you support here. In particular, ensure + # that you indicate whether you support Python 2, Python 3 or both. + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.6', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.2', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + ], + + keywords='development databases bootstrap setup messaging', + + # You can just specify the packages manually here if your project is + # simple. Or you can use find_packages(). + packages=find_packages(exclude=['contrib', 'docs', 'tests']), + + # Alternatively, if you want to distribute just a my_module.py, uncomment + # this: + # py_modules=["my_module"], + + # List run-time dependencies here. These will be installed by pip when + # your project is installed. For an analysis of "install_requires" vs pip's + # requirements files see: + # https://packaging.python.org/en/latest/requirements.html + install_requires=[], + + # List additional groups of dependencies here (e.g. development + # dependencies). You can install these using the following syntax, + # for example: + # $ pip install -e .[dev,test] + extras_require={ + 'dev': ['check-manifest'], + 'test': ['coverage'], + }, + + # If there are data files included in your packages that need to be + # installed, specify them here. If using Python 2.6 or less, then these + # have to be included in MANIFEST.in as well. + package_data={}, + + # Although 'package_data' is the preferred approach, in some case you may + # need to place data files outside of your packages. See: + # http://docs.python.org/3.4/distutils/setupscript.html#installing-additional-files # noqa + # In this case, 'data_file' will be installed into '/my_data' + data_files=[], + + # To provide executable scripts, use entry points in preference to the + # "scripts" keyword. Entry points provide cross-platform support and allow + # pip to create the appropriate form of executable for the target platform. + entry_points={ + 'console_scripts': [ + 'dock=dock:main', + ], + }, +) From 939399655fe5633a5229a4cd6a5dbd4eba5af720 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 07:52:00 +0100 Subject: [PATCH 08/44] Ignore files created during the build process --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 0d20b64..d7e5bfb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ *.pyc +/dist/ +/*.egg-info +/build From 8688b17608246d75a743814228a194ea4629be75 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 07:52:27 +0100 Subject: [PATCH 09/44] Support Python 2 and 3 --- dock/__init__.py | 28 ++++++++++++++-------------- dock/docker.py | 12 ++++++------ dock/formula/docker-gc.py | 2 +- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/dock/__init__.py b/dock/__init__.py index 6156b34..cd57ec2 100644 --- a/dock/__init__.py +++ b/dock/__init__.py @@ -15,40 +15,40 @@ def print_version(): - print 'dock {} by Ben Ripkens and contributors'.format(VERSION) - print 'https://github.com/bripkens/dock' + print('dock {} by Ben Ripkens and contributors'.format(VERSION)) + print('https://github.com/bripkens/dock') def list_available_formulas(): - print ':: Built-In Formulas' + print(':: Built-In Formulas') for formula in sorted(os.listdir(FORMULA_DIR)): if formula.endswith('.py') and not formula == '__init__.py': match = re.search('([^.]+)\\.', formula) - print match.group(1) + print(match.group(1)) def print_unknown_formula_contribution_hint(formula): - print 'Unknown formula: {}'.format(formula) - print '' - print 'If you feel like {} should be supported by dock, please'.format(formula) - print 'consider opening an issue or sending a pull request to' - print '' - print ' https://github.com/bripkens/dock' - print '' - print 'Thanks!' + print('Unknown formula: {}'.format(formula)) + print('') + print('If you feel like {} should be supported by dock, please'.format(formula)) + print('consider opening an issue or sending a pull request to') + print('') + print(' https://github.com/bripkens/dock') + print('') + print('Thanks!') def ensure_docker_usage_is_possible(): returnCode = subprocess.call(['docker', 'ps'], stdout=open(os.devnull, 'w')) if not returnCode == 0: - print 'It seems like there are issues with your Docker setup.' + print('It seems like there are issues with your Docker setup.') sys.exit(1) def execute_formulas(formulas): ensure_docker_usage_is_possible() for formula in formulas: - print '' + print('') module_name = 'formula.' + formula try: mod = importlib.import_module(module_name) diff --git a/dock/docker.py b/dock/docker.py index fb6e8cf..b0d5fc8 100644 --- a/dock/docker.py +++ b/dock/docker.py @@ -53,7 +53,7 @@ def run(image, args.append(image) if not silent: - print 'Starting image {} as container {}'.format(image, name) + print('Starting image {} as container {}'.format(image, name)) subprocess.call(args) if not silent: @@ -89,14 +89,14 @@ def print_run_data(name): ports = port_mappings.keys() ports.sort() - print 'Container Name: {}'.format(name) - print 'IP: {}'.format(get_ip()) + print('Container Name: {}'.format(name)) + print('IP: {}'.format(get_ip())) if len(ports) > 0: - print 'Ports: Host -> Container' + print('Ports: Host -> Container') for port in ports: stripped_port = strip_protocol_from_port(port) for host_port in port_mappings[port]: - print ' {} -> {}'.format(host_port['HostPort'].ljust(5, ' '), - stripped_port) + print(' {} -> {}'.format(host_port['HostPort'].ljust(5, ' '), + stripped_port)) diff --git a/dock/formula/docker-gc.py b/dock/formula/docker-gc.py index 8ec4e5b..033314a 100644 --- a/dock/formula/docker-gc.py +++ b/dock/formula/docker-gc.py @@ -1,7 +1,7 @@ import docker def run(): - print 'Starting cleanup process via docker-gc...' + print('Starting cleanup process via docker-gc...') docker.run(image='spotify/docker-gc', auto_remove=True, detach=False, From 6064bf4c3c582709eda33bd4b1dec738bbc9836d Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 08:18:15 +0100 Subject: [PATCH 10/44] Necessary changes for PyPi upload --- .bumpversion.cfg | 7 +++++++ CHANGELOG.md | 4 ++++ CONTRIBUTING.md | 22 ++++++++++++++++++++++ MANIFEST.in | 1 - VERSION | 1 - dock/__init__.py | 5 +---- setup.py | 4 ++-- 7 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 .bumpversion.cfg create mode 100644 CONTRIBUTING.md delete mode 100644 MANIFEST.in delete mode 100644 VERSION diff --git a/.bumpversion.cfg b/.bumpversion.cfg new file mode 100644 index 0000000..4cc4d68 --- /dev/null +++ b/.bumpversion.cfg @@ -0,0 +1,7 @@ +[bumpversion] +current_version = 2.0.1 +#commit = True +#tag = True + +[bumpversion:file:setup.py] +[bumpversion:file:dock/__init__.py] diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ba8535..ec33478 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # dock changelog +## 2.0.0 (unreleased) +TODO Ben: extend release notes + - Rewriting dock to Python for easier development. + ## 1.3.0 - dock is now compatible with docker-machine thanks to [@codingfabian](https://github.com/CodingFabian). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..24473bf --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,22 @@ +# Contributing + +## Releasing to PyPi +Follow the guide on https://packaging.python.org/en/latest/distributing/ + +```bash +# ensure twine is installed +$ pip install --upgrade twine bumpversion +# remove previous build +$ rm -rf build dist *.egg-info +# generate package info used for the upload to the PyPi registry +$ python setup.py egg_info +# build the project +$ python setup.py bdist_wheel --universal +# ensure that a ~/.pypirc file exists +$ cat ~/.pypirc +# upload +$ twine upload dist/* +``` + +## Symlinking cloned repository +pip install -e . diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 1aba38f..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1 +0,0 @@ -include LICENSE diff --git a/VERSION b/VERSION deleted file mode 100644 index 227cea2..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -2.0.0 diff --git a/dock/__init__.py b/dock/__init__.py index cd57ec2..00d68c7 100644 --- a/dock/__init__.py +++ b/dock/__init__.py @@ -10,12 +10,9 @@ HERE = os.path.abspath(os.path.dirname(__file__)) FORMULA_DIR = os.path.join(HERE, 'formula') -with open(os.path.join(HERE, '..', 'VERSION')) as f: - VERSION = f.read().strip() - def print_version(): - print('dock {} by Ben Ripkens and contributors'.format(VERSION)) + print('dock {} by Ben Ripkens and contributors'.format('2.0.1')) print('https://github.com/bripkens/dock') diff --git a/setup.py b/setup.py index a8d53bd..9efdc52 100644 --- a/setup.py +++ b/setup.py @@ -8,13 +8,13 @@ with open(path.join(HERE, 'README.md'), encoding='utf-8') as f: LONG_DESCRIPTION = f.read() -with open(path.join(HERE, 'VERSION'), encoding='utf-8') as f: +with open(path.join(HERE, 'dock', 'VERSION'), encoding='utf-8') as f: VERSION = f.read().strip() setup( name='dock-upload-test', - version=VERSION, + version='2.0.1', description='Bootstrap databases, MOMs and other tools that you need for development purposes', long_description=LONG_DESCRIPTION, From 6bb67288edfb4faa26b9b129f63528dbb3d5c6e7 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 08:19:48 +0100 Subject: [PATCH 11/44] Use bumpversion --- .bumpversion.cfg | 5 ++--- CONTRIBUTING.md | 2 ++ dock/__init__.py | 2 +- setup.py | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 4cc4d68..0f8f03e 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,7 +1,6 @@ [bumpversion] -current_version = 2.0.1 -#commit = True -#tag = True +current_version = 2.0.2 [bumpversion:file:setup.py] + [bumpversion:file:dock/__init__.py] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 24473bf..158e428 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,6 +8,8 @@ Follow the guide on https://packaging.python.org/en/latest/distributing/ $ pip install --upgrade twine bumpversion # remove previous build $ rm -rf build dist *.egg-info +# increase the version number +bumpversion --commit --tag (major|minor|patch) # generate package info used for the upload to the PyPi registry $ python setup.py egg_info # build the project diff --git a/dock/__init__.py b/dock/__init__.py index 00d68c7..27253c1 100644 --- a/dock/__init__.py +++ b/dock/__init__.py @@ -12,7 +12,7 @@ def print_version(): - print('dock {} by Ben Ripkens and contributors'.format('2.0.1')) + print('dock {} by Ben Ripkens and contributors'.format('2.0.2')) print('https://github.com/bripkens/dock') diff --git a/setup.py b/setup.py index 9efdc52..3c4f8c7 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ setup( name='dock-upload-test', - version='2.0.1', + version='2.0.2', description='Bootstrap databases, MOMs and other tools that you need for development purposes', long_description=LONG_DESCRIPTION, From e3c380927be818845301e6ea1a56b7ccaf3bb65f Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 08:47:42 +0100 Subject: [PATCH 12/44] Small improvements --- CONTRIBUTING.md | 9 ++++++++- setup.py | 13 +++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 158e428..49cd7ac 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,8 +8,11 @@ Follow the guide on https://packaging.python.org/en/latest/distributing/ $ pip install --upgrade twine bumpversion # remove previous build $ rm -rf build dist *.egg-info +# Update changelog +$ git add CHANGELOG.md +$ git commit -m "docs(changelog): Prepare changelog for upcoming release" # increase the version number -bumpversion --commit --tag (major|minor|patch) +$ bumpversion --commit --tag (major|minor|patch) # generate package info used for the upload to the PyPi registry $ python setup.py egg_info # build the project @@ -22,3 +25,7 @@ $ twine upload dist/* ## Symlinking cloned repository pip install -e . + + +## TODOs + - [ ] Handle Docker run errors (see screenshot from 2016-01-10 8:22) diff --git a/setup.py b/setup.py index 3c4f8c7..a888a88 100644 --- a/setup.py +++ b/setup.py @@ -8,9 +8,6 @@ with open(path.join(HERE, 'README.md'), encoding='utf-8') as f: LONG_DESCRIPTION = f.read() -with open(path.join(HERE, 'dock', 'VERSION'), encoding='utf-8') as f: - VERSION = f.read().strip() - setup( name='dock-upload-test', @@ -50,7 +47,7 @@ 'Programming Language :: Python :: 3.2', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.5' ], keywords='development databases bootstrap setup messaging', @@ -75,7 +72,7 @@ # $ pip install -e .[dev,test] extras_require={ 'dev': ['check-manifest'], - 'test': ['coverage'], + 'test': ['coverage'] }, # If there are data files included in your packages that need to be @@ -93,8 +90,8 @@ # "scripts" keyword. Entry points provide cross-platform support and allow # pip to create the appropriate form of executable for the target platform. entry_points={ - 'console_scripts': [ - 'dock=dock:main', - ], + 'console_scripts': [ + 'dock=dock:main' + ] }, ) From 0f6040c1154b12089d8cf1bffd0eb27df8bee2db Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 09:05:20 +0100 Subject: [PATCH 13/44] Add pointer to PyPi release gist with some nice ideas --- CONTRIBUTING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 49cd7ac..cd44a2f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,6 +2,7 @@ ## Releasing to PyPi Follow the guide on https://packaging.python.org/en/latest/distributing/ +release ideas: https://gist.github.com/audreyr/5990987 ```bash # ensure twine is installed From 67d88c50d0e8997486152c220912ff112a16064f Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 09:23:44 +0100 Subject: [PATCH 14/44] Only run a single formula per dock call --- dock/__init__.py | 58 +++---------------------- dock/docker.py | 4 ++ dock/formula.py | 46 ++++++++++++++++++++ dock/{formula => formulas}/__init__.py | 0 dock/{formula => formulas}/docker-gc.py | 2 +- dock/{formula => formulas}/mongodb.py | 2 +- 6 files changed, 57 insertions(+), 55 deletions(-) create mode 100644 dock/formula.py rename dock/{formula => formulas}/__init__.py (100%) rename dock/{formula => formulas}/docker-gc.py (93%) rename dock/{formula => formulas}/mongodb.py (92%) diff --git a/dock/__init__.py b/dock/__init__.py index 27253c1..0478a0f 100644 --- a/dock/__init__.py +++ b/dock/__init__.py @@ -1,14 +1,8 @@ #!/usr/local/opt/python/bin/python2.7 import argparse -import importlib -import os -import os.path -import re -import subprocess -HERE = os.path.abspath(os.path.dirname(__file__)) -FORMULA_DIR = os.path.join(HERE, 'formula') +import formula def print_version(): @@ -16,51 +10,9 @@ def print_version(): print('https://github.com/bripkens/dock') -def list_available_formulas(): - print(':: Built-In Formulas') - for formula in sorted(os.listdir(FORMULA_DIR)): - if formula.endswith('.py') and not formula == '__init__.py': - match = re.search('([^.]+)\\.', formula) - print(match.group(1)) - - -def print_unknown_formula_contribution_hint(formula): - print('Unknown formula: {}'.format(formula)) - print('') - print('If you feel like {} should be supported by dock, please'.format(formula)) - print('consider opening an issue or sending a pull request to') - print('') - print(' https://github.com/bripkens/dock') - print('') - print('Thanks!') - - -def ensure_docker_usage_is_possible(): - returnCode = subprocess.call(['docker', 'ps'], stdout=open(os.devnull, 'w')) - if not returnCode == 0: - print('It seems like there are issues with your Docker setup.') - sys.exit(1) - - -def execute_formulas(formulas): - ensure_docker_usage_is_possible() - for formula in formulas: - print('') - module_name = 'formula.' + formula - try: - mod = importlib.import_module(module_name) - path_to_module = os.path.join(FORMULA_DIR, formula + '.py') - mod.run() - except ImportError as e: - if e.message.endswith(formula): - print_unknown_formula_contribution_hint(formula) - else: - raise - - def main(): parser = argparse.ArgumentParser(prog='dock', - usage='%(prog)s [options] [formulas...]', + usage='%(prog)s [options] [formula] [formula arguments...]', description='easily bootstrap development tools with Docker') parser.add_argument('formulas', help='Execute the given formulas in the order in which they are defined on the command line.', @@ -79,13 +31,13 @@ def main(): if args.version: print_version() if args.cleanup: - execute_formulas(['docker-gc']) + formula.execute_formula('docker-gc', []) elif args.list: - list_available_formulas() + formula.list_available_formulas() elif len(args.formulas) == 0: parser.print_help() else: - execute_formulas(args.formulas) + formula.execute_formula(args.formulas[0], args.formulas[1:]) if __name__ == '__main__': diff --git a/dock/docker.py b/dock/docker.py index b0d5fc8..c20a339 100644 --- a/dock/docker.py +++ b/dock/docker.py @@ -25,6 +25,10 @@ def force_stop(name): stderr=devnull) +def requires(name): + name = add_name_prefix(name) + + def run(image, name=None, publish=[], diff --git a/dock/formula.py b/dock/formula.py new file mode 100644 index 0000000..5388d6a --- /dev/null +++ b/dock/formula.py @@ -0,0 +1,46 @@ +import importlib +import os.path +import re +import subprocess + +HERE = os.path.abspath(os.path.dirname(__file__)) +FORMULA_DIR = os.path.join(HERE, 'formulas') + +def list_available_formulas(): + print(':: Built-In Formulas') + for formula in sorted(os.listdir(FORMULA_DIR)): + if formula.endswith('.py') and not formula == '__init__.py': + match = re.search('([^.]+)\\.', formula) + print(match.group(1)) + + +def print_unknown_formula_contribution_hint(formula): + print('Unknown formula: {}'.format(formula)) + print('') + print('If you feel like {} should be supported by dock, please'.format(formula)) + print('consider opening an issue or sending a pull request to') + print('') + print(' https://github.com/bripkens/dock') + print('') + print('Thanks!') + + +def ensure_docker_usage_is_possible(): + returnCode = subprocess.call(['docker', 'ps'], stdout=open(os.devnull, 'w')) + if not returnCode == 0: + print('It seems like there are issues with your Docker setup.') + sys.exit(1) + + +def execute_formula(formula, formula_args): + ensure_docker_usage_is_possible() + module_name = 'formulas.' + formula + try: + mod = importlib.import_module(module_name) + path_to_module = os.path.join(FORMULA_DIR, formula + '.py') + mod.run(formula_args) + except ImportError as e: + if e.message.endswith(formula): + print_unknown_formula_contribution_hint(formula) + else: + raise diff --git a/dock/formula/__init__.py b/dock/formulas/__init__.py similarity index 100% rename from dock/formula/__init__.py rename to dock/formulas/__init__.py diff --git a/dock/formula/docker-gc.py b/dock/formulas/docker-gc.py similarity index 93% rename from dock/formula/docker-gc.py rename to dock/formulas/docker-gc.py index 033314a..f9cc744 100644 --- a/dock/formula/docker-gc.py +++ b/dock/formulas/docker-gc.py @@ -1,6 +1,6 @@ import docker -def run(): +def run(args): print('Starting cleanup process via docker-gc...') docker.run(image='spotify/docker-gc', auto_remove=True, diff --git a/dock/formula/mongodb.py b/dock/formulas/mongodb.py similarity index 92% rename from dock/formula/mongodb.py rename to dock/formulas/mongodb.py index c257f1e..4ad1a9b 100644 --- a/dock/formula/mongodb.py +++ b/dock/formulas/mongodb.py @@ -2,7 +2,7 @@ container_name = 'mongodb' -def run(): +def run(args): docker.force_stop(container_name) docker.run(image='mongo:3.2.0', name=container_name, From b3addd9ece5099126c89837cbff99e819de0f326 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 09:24:12 +0100 Subject: [PATCH 15/44] Either run options or formulas --- dock/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dock/__init__.py b/dock/__init__.py index 0478a0f..65e8e48 100644 --- a/dock/__init__.py +++ b/dock/__init__.py @@ -30,7 +30,7 @@ def main(): if args.version: print_version() - if args.cleanup: + elif args.cleanup: formula.execute_formula('docker-gc', []) elif args.list: formula.list_available_formulas() From fd0f17d75ae1e4d4bb26717456f4ad8339391265 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 14:13:57 +0100 Subject: [PATCH 16/44] Start with an FAQ --- FAQ.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 FAQ.md diff --git a/FAQ.md b/FAQ.md new file mode 100644 index 0000000..4db5e52 --- /dev/null +++ b/FAQ.md @@ -0,0 +1,4 @@ +# FAQ + +## No space left on device with docker-machine +See http://stackoverflow.com/questions/31909979/docker-machine-no-space-left-on-device From 4ce213b0022f1853bfd1406ba1b3912260e1530e Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 14:18:04 +0100 Subject: [PATCH 17/44] Add formula mongo-express --- dock/docker.py | 51 ++++++++++++++++++++++++---------- dock/formula.py | 3 ++ dock/formulas/docker-gc.py | 1 + dock/formulas/mongo-express.py | 11 ++++++++ 4 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 dock/formulas/mongo-express.py diff --git a/dock/docker.py b/dock/docker.py index c20a339..ecbb84f 100644 --- a/dock/docker.py +++ b/dock/docker.py @@ -2,6 +2,9 @@ import os import re import subprocess +import time + +import formula devnull = open(os.devnull, 'w') @@ -10,11 +13,6 @@ def add_name_prefix(container_name): return 'dock-' + container_name -def generate_name_from_image(image): - # Docker container names cannot contain slashes - return image.replace('/', '_') - - def force_stop(name): name = add_name_prefix(name) subprocess.call(['docker', 'stop', name], @@ -25,20 +23,33 @@ def force_stop(name): stderr=devnull) -def requires(name): - name = add_name_prefix(name) - +def is_container_running(name): + try: + output = subprocess.check_output(['docker', 'inspect', name], + stderr=devnull) + except Error: + return False + + return json.loads(output)[0]['State']['Running'] + + +def requires(dependent, dependency): + prefixed_dependency = add_name_prefix(dependency) + if not is_container_running(prefixed_dependency): + print('{} requires {} in order to run. Starting {}'.format(dependent, + dependency, + dependency)) + formula.execute_formula(dependency, []) + def run(image, - name=None, + name, publish=[], auto_remove=False, detach=True, mount_docker_socket=False, - silent=False): - if name == None: - name = generate_name_from_image(image) - + silent=False, + link=[]): name = add_name_prefix(name) args = ['docker', 'run', '--name', name] @@ -55,12 +66,24 @@ def run(image, for publishedPort in publish: args.extend(['--publish', '{}:{}'.format(publishedPort, publishedPort)]) + for each_link in link: + args.extend(['--link', '{}:{}'.format(each_link[0], each_link[1])]) + args.append(image) + if not silent: print('Starting image {} as container {}'.format(image, name)) - subprocess.call(args) + + result = subprocess.call(args) + if not result == 0: + print('Failed to start container.') + return if not silent: + # Docker cli can return before the new container can be inspected. This + # is very unfortunate. The following is a fragile solution which needs + # to be revisited in time. + time.sleep(0.5) print_run_data(name) diff --git a/dock/formula.py b/dock/formula.py index 5388d6a..2afc440 100644 --- a/dock/formula.py +++ b/dock/formula.py @@ -2,10 +2,13 @@ import os.path import re import subprocess +import sys + HERE = os.path.abspath(os.path.dirname(__file__)) FORMULA_DIR = os.path.join(HERE, 'formulas') + def list_available_formulas(): print(':: Built-In Formulas') for formula in sorted(os.listdir(FORMULA_DIR)): diff --git a/dock/formulas/docker-gc.py b/dock/formulas/docker-gc.py index f9cc744..7b73bf4 100644 --- a/dock/formulas/docker-gc.py +++ b/dock/formulas/docker-gc.py @@ -3,6 +3,7 @@ def run(args): print('Starting cleanup process via docker-gc...') docker.run(image='spotify/docker-gc', + name='docker-gc' auto_remove=True, detach=False, mount_docker_socket=True, diff --git a/dock/formulas/mongo-express.py b/dock/formulas/mongo-express.py new file mode 100644 index 0000000..6bfd9af --- /dev/null +++ b/dock/formulas/mongo-express.py @@ -0,0 +1,11 @@ +import docker + +container_name = 'mongo-express' + +def run(args): + docker.force_stop('mongo-express') + docker.requires(dependent='mongo-express', dependency='mongodb') + docker.run(image='knickers/mongo-express:latest', + name='mongo-express', + link=[['dock-mongodb', 'mongo']], + publish=[8081]) From 781868e0cedd52e602665ac20341abdfdadf7c57 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 14:56:23 +0100 Subject: [PATCH 18/44] Add redis and redis-cli formula --- dock/docker.py | 15 +++++++++++++-- dock/formulas/docker-gc.py | 2 +- dock/formulas/mongo-express.py | 2 +- dock/formulas/redis-cli.py | 11 +++++++++++ dock/formulas/redis.py | 9 +++++++++ 5 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 dock/formulas/redis-cli.py create mode 100644 dock/formulas/redis.py diff --git a/dock/docker.py b/dock/docker.py index ecbb84f..975465a 100644 --- a/dock/docker.py +++ b/dock/docker.py @@ -49,7 +49,9 @@ def run(image, detach=True, mount_docker_socket=False, silent=False, - link=[]): + interactive=False, + link=[], + command=None): name = add_name_prefix(name) args = ['docker', 'run', '--name', name] @@ -60,6 +62,9 @@ def run(image, if auto_remove: args.append('--rm') + if interactive: + args.extend(['--interactive', '--tty']) + if mount_docker_socket: args.extend(['--volume', '/var/run/docker.sock:/var/run/docker.sock']) @@ -67,10 +72,16 @@ def run(image, args.extend(['--publish', '{}:{}'.format(publishedPort, publishedPort)]) for each_link in link: - args.extend(['--link', '{}:{}'.format(each_link[0], each_link[1])]) + args.extend(['--link', '{}:{}'.format(add_name_prefix(each_link[0]), + each_link[1])]) args.append(image) + if not command == None: + args.extend(command) + + print('Executing {}'.format(args)) + if not silent: print('Starting image {} as container {}'.format(image, name)) diff --git a/dock/formulas/docker-gc.py b/dock/formulas/docker-gc.py index 7b73bf4..5458ed2 100644 --- a/dock/formulas/docker-gc.py +++ b/dock/formulas/docker-gc.py @@ -3,7 +3,7 @@ def run(args): print('Starting cleanup process via docker-gc...') docker.run(image='spotify/docker-gc', - name='docker-gc' + name='docker-gc', auto_remove=True, detach=False, mount_docker_socket=True, diff --git a/dock/formulas/mongo-express.py b/dock/formulas/mongo-express.py index 6bfd9af..5261578 100644 --- a/dock/formulas/mongo-express.py +++ b/dock/formulas/mongo-express.py @@ -7,5 +7,5 @@ def run(args): docker.requires(dependent='mongo-express', dependency='mongodb') docker.run(image='knickers/mongo-express:latest', name='mongo-express', - link=[['dock-mongodb', 'mongo']], + link=[['mongodb', 'mongo']], publish=[8081]) diff --git a/dock/formulas/redis-cli.py b/dock/formulas/redis-cli.py new file mode 100644 index 0000000..1835840 --- /dev/null +++ b/dock/formulas/redis-cli.py @@ -0,0 +1,11 @@ +import docker + +def run(args): + docker.run(image='redis:3.0.6', + name='redis-cli', + auto_remove=True, + detach=False, + interactive=True, + link=[['redis', 'redis']], + silent=True, + command=['sh', '-c', 'redis-cli -h "$REDIS_PORT_6379_TCP_ADDR" -p "$REDIS_PORT_6379_TCP_PORT"']) diff --git a/dock/formulas/redis.py b/dock/formulas/redis.py new file mode 100644 index 0000000..a0eb51e --- /dev/null +++ b/dock/formulas/redis.py @@ -0,0 +1,9 @@ +import docker + +container_name = 'redis' + +def run(args): + docker.force_stop(container_name) + docker.run(image='redis:3.0.6', + name=container_name, + publish=[6379]) From aecc5fd5f898bad4552ea1ab1471b3d11c75306a Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 15:09:47 +0100 Subject: [PATCH 19/44] Add Ubuntu formula --- dock/formulas/ubuntu.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 dock/formulas/ubuntu.py diff --git a/dock/formulas/ubuntu.py b/dock/formulas/ubuntu.py new file mode 100644 index 0000000..239d85b --- /dev/null +++ b/dock/formulas/ubuntu.py @@ -0,0 +1,10 @@ +import docker + +def run(args): + docker.run(image='ubuntu:14.04', + name='ubuntu', + auto_remove=True, + detach=False, + interactive=True, + silent=True, + command=['bash']) From 82d91988673b85d58fffdf56094d9ba54802eea8 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 15:19:56 +0100 Subject: [PATCH 20/44] Add Neo4j formula --- dock/docker.py | 30 +++++++++++++++++++++--------- dock/formulas/neo4j.py | 11 +++++++++++ 2 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 dock/formulas/neo4j.py diff --git a/dock/docker.py b/dock/docker.py index 975465a..1a8934f 100644 --- a/dock/docker.py +++ b/dock/docker.py @@ -8,6 +8,10 @@ devnull = open(os.devnull, 'w') +def msg(k, v): + label = k + ':' if len(k) > 0 else '' + print(label.ljust(20, ' ') + v) + def add_name_prefix(container_name): return 'dock-' + container_name @@ -51,7 +55,8 @@ def run(image, silent=False, interactive=False, link=[], - command=None): + command=None, + env={}): name = add_name_prefix(name) args = ['docker', 'run', '--name', name] @@ -75,13 +80,14 @@ def run(image, args.extend(['--link', '{}:{}'.format(add_name_prefix(each_link[0]), each_link[1])]) + for key in env: + args.extend(['--env', '{}={}'.format(key, env[key])]) + args.append(image) if not command == None: args.extend(command) - print('Executing {}'.format(args)) - if not silent: print('Starting image {} as container {}'.format(image, name)) @@ -127,14 +133,20 @@ def print_run_data(name): ports = port_mappings.keys() ports.sort() - print('Container Name: {}'.format(name)) - print('IP: {}'.format(get_ip())) + msg('Container Name', name) + msg('IP', get_ip()) if len(ports) > 0: - print('Ports: Host -> Container') + msg('Ports', 'Host -> Container') for port in ports: stripped_port = strip_protocol_from_port(port) - for host_port in port_mappings[port]: - print(' {} -> {}'.format(host_port['HostPort'].ljust(5, ' '), - stripped_port)) + + host_ports = port_mappings[port] + # host ports may be None when the ports are not published + if host_ports == None: + continue + + for host_port in host_ports: + msg('', '{} -> {}'.format(host_port['HostPort'].ljust(5, ' '), + stripped_port)) diff --git a/dock/formulas/neo4j.py b/dock/formulas/neo4j.py new file mode 100644 index 0000000..44dc11d --- /dev/null +++ b/dock/formulas/neo4j.py @@ -0,0 +1,11 @@ +import docker + +container_name = 'neo4j' + +def run(args): + docker.force_stop(container_name) + docker.run(image='neo4j:2.3.1', + name=container_name, + publish=[7474], + env={'NEO4J_AUTH': 'none'}) + docker.msg('Authentication', 'Disabled') From 34663c530ce463a9ef69b6bc462aa0170f81598e Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 15:23:17 +0100 Subject: [PATCH 21/44] Add Node.js formulas --- dock/formulas/node-4.py | 10 ++++++++++ dock/formulas/node-5.py | 10 ++++++++++ 2 files changed, 20 insertions(+) create mode 100644 dock/formulas/node-4.py create mode 100644 dock/formulas/node-5.py diff --git a/dock/formulas/node-4.py b/dock/formulas/node-4.py new file mode 100644 index 0000000..72189e5 --- /dev/null +++ b/dock/formulas/node-4.py @@ -0,0 +1,10 @@ +import docker + +def run(args): + docker.run(image='node:4', + name='node-4', + auto_remove=True, + detach=False, + interactive=True, + silent=True, + command=['bash']) diff --git a/dock/formulas/node-5.py b/dock/formulas/node-5.py new file mode 100644 index 0000000..dd10187 --- /dev/null +++ b/dock/formulas/node-5.py @@ -0,0 +1,10 @@ +import docker + +def run(args): + docker.run(image='node:5', + name='node-5', + auto_remove=True, + detach=False, + interactive=True, + silent=True, + command=['bash']) From 830bc59f3b711ebae40b291f8c7967d7f149e605 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 17:57:32 +0100 Subject: [PATCH 22/44] Add Elasticsearch formula --- dock/formulas/elasticsearch.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 dock/formulas/elasticsearch.py diff --git a/dock/formulas/elasticsearch.py b/dock/formulas/elasticsearch.py new file mode 100644 index 0000000..416d857 --- /dev/null +++ b/dock/formulas/elasticsearch.py @@ -0,0 +1,9 @@ +import docker + +container_name = 'elasticsearch' + +def run(args): + docker.force_stop(container_name) + docker.run(image='elasticsearch:2.1.1', + name=container_name, + publish=[9200, 9300]) From 34d9a9094d79b07a660440e17472d5acfc2cd2db Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 18:04:15 +0100 Subject: [PATCH 23/44] docker-gc should not add separate console output --- dock/formulas/docker-gc.py | 1 - 1 file changed, 1 deletion(-) diff --git a/dock/formulas/docker-gc.py b/dock/formulas/docker-gc.py index 5458ed2..d7ac09b 100644 --- a/dock/formulas/docker-gc.py +++ b/dock/formulas/docker-gc.py @@ -1,7 +1,6 @@ import docker def run(args): - print('Starting cleanup process via docker-gc...') docker.run(image='spotify/docker-gc', name='docker-gc', auto_remove=True, From 7d73f5b72f45bbcb58bafd1858956f4a03940003 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 18:04:25 +0100 Subject: [PATCH 24/44] add postgres formulas --- dock/formulas/postgres-cli.py | 11 +++++++++++ dock/formulas/postgres.py | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 dock/formulas/postgres-cli.py create mode 100644 dock/formulas/postgres.py diff --git a/dock/formulas/postgres-cli.py b/dock/formulas/postgres-cli.py new file mode 100644 index 0000000..26c6fb9 --- /dev/null +++ b/dock/formulas/postgres-cli.py @@ -0,0 +1,11 @@ +import docker + +def run(args): + docker.run(image='postgres:9.5.0', + name='postgres-cli', + auto_remove=True, + detach=False, + interactive=True, + link=[['postgres', 'postgres']], + silent=True, + command=['sh', '-c', 'psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U admin']) diff --git a/dock/formulas/postgres.py b/dock/formulas/postgres.py new file mode 100644 index 0000000..2261820 --- /dev/null +++ b/dock/formulas/postgres.py @@ -0,0 +1,19 @@ +import docker + +container_name = 'postgres' + +user = 'admin' +password = 'admin' + +def run(args): + docker.force_stop(container_name) + docker.run(image='postgres:9.5.0', + name=container_name, + publish=[5432], + env={ + 'POSTGRES_USER': user, + 'POSTGRES_PASSWORD': password + }) + + docker.msg('Admin user', user) + docker.msg('Admin password', password) From 68d10eb6e835ac4ba006c2b38db735837889ec03 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 18:13:37 +0100 Subject: [PATCH 25/44] Add MySQL formulas --- dock/formulas/mysql-cli.py | 11 +++++++++++ dock/formulas/mysql.py | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 dock/formulas/mysql-cli.py create mode 100644 dock/formulas/mysql.py diff --git a/dock/formulas/mysql-cli.py b/dock/formulas/mysql-cli.py new file mode 100644 index 0000000..30ba9eb --- /dev/null +++ b/dock/formulas/mysql-cli.py @@ -0,0 +1,11 @@ +import docker + +def run(args): + docker.run(image='mysql:5.7.10', + name='mysql-cli', + auto_remove=True, + detach=False, + interactive=True, + link=[['mysql', 'mysql']], + silent=True, + command=['sh', '-c', 'mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -proot']) diff --git a/dock/formulas/mysql.py b/dock/formulas/mysql.py new file mode 100644 index 0000000..98a0d49 --- /dev/null +++ b/dock/formulas/mysql.py @@ -0,0 +1,25 @@ +import docker + +container_name = 'mysql' + +root_password = 'root' +database = 'dock-db' +user = 'user' +password = 'user' + +def run(args): + docker.force_stop(container_name) + docker.run(image='mysql:5.7.10', + name=container_name, + publish=[3306], + env={ + 'MYSQL_ROOT_PASSWORD': root_password, + 'MYSQL_DATABASE': database, + 'MYSQL_USER': user, + 'MYSQL_PASSWORD': password + }) + + docker.msg('Root password', root_password) + docker.msg('Database', database) + docker.msg('User name', user) + docker.msg('User password', password) From 86c575cb1c0c28342fd1201222e624516e0fdfc4 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 18:39:35 +0100 Subject: [PATCH 26/44] Add Zookeeper formula --- dock/docker.py | 4 ++++ dock/formulas/zookeeper-cli.py | 12 ++++++++++++ dock/formulas/zookeeper.py | 9 +++++++++ 3 files changed, 25 insertions(+) create mode 100644 dock/formulas/zookeeper-cli.py create mode 100644 dock/formulas/zookeeper.py diff --git a/dock/docker.py b/dock/docker.py index 1a8934f..5e8a594 100644 --- a/dock/docker.py +++ b/dock/docker.py @@ -56,6 +56,7 @@ def run(image, interactive=False, link=[], command=None, + entrypoint=None, env={}): name = add_name_prefix(name) @@ -70,6 +71,9 @@ def run(image, if interactive: args.extend(['--interactive', '--tty']) + if not entrypoint == None: + args.extend(['--entrypoint', entrypoint]) + if mount_docker_socket: args.extend(['--volume', '/var/run/docker.sock:/var/run/docker.sock']) diff --git a/dock/formulas/zookeeper-cli.py b/dock/formulas/zookeeper-cli.py new file mode 100644 index 0000000..1dcb855 --- /dev/null +++ b/dock/formulas/zookeeper-cli.py @@ -0,0 +1,12 @@ +import docker + +def run(args): + docker.run(image='jplock/zookeeper:3.4.7', + name='zookeeper-cli', + auto_remove=True, + detach=False, + interactive=True, + link=[['zookeeper', 'zookeeper']], + silent=True, + entrypoint='sh', + command=['-c', './bin/zkCli.sh -server "$ZOOKEEPER_PORT_2181_TCP_ADDR":"$ZOOKEEPER_PORT_2181_TCP_PORT"']) diff --git a/dock/formulas/zookeeper.py b/dock/formulas/zookeeper.py new file mode 100644 index 0000000..03d1993 --- /dev/null +++ b/dock/formulas/zookeeper.py @@ -0,0 +1,9 @@ +import docker + +container_name = 'zookeeper' + +def run(args): + docker.force_stop(container_name) + docker.run(image='jplock/zookeeper:3.4.7', + name=container_name, + publish=[2181, 2888, 3888]) From 7c389fb235efe356f9d86afd881576c9669338d9 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 19:07:44 +0100 Subject: [PATCH 27/44] Add Cassandra formula --- dock/formulas/cassandra-cli.py | 11 +++++++++++ dock/formulas/cassandra.py | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 dock/formulas/cassandra-cli.py create mode 100644 dock/formulas/cassandra.py diff --git a/dock/formulas/cassandra-cli.py b/dock/formulas/cassandra-cli.py new file mode 100644 index 0000000..1ddaed0 --- /dev/null +++ b/dock/formulas/cassandra-cli.py @@ -0,0 +1,11 @@ +import docker + +def run(args): + docker.run(image='cassandra:3.1.1', + name='cassandra-cli', + auto_remove=True, + detach=False, + interactive=True, + link=[['cassandra', 'cassandra']], + silent=True, + command=['sh', '-c', 'cqlsh -u cassandra -p cassandra "$CASSANDRA_PORT_9042_TCP_ADDR" "$CASSANDRA_PORT_9042_TCP_PORT"']) diff --git a/dock/formulas/cassandra.py b/dock/formulas/cassandra.py new file mode 100644 index 0000000..594b8c1 --- /dev/null +++ b/dock/formulas/cassandra.py @@ -0,0 +1,11 @@ +import docker + +container_name = 'cassandra' + +def run(args): + docker.force_stop(container_name) + docker.run(image='cassandra:3.1.1', + name=container_name, + publish=[7000, 7001, 7199, 9042, 9160]) + docker.msg('Root user', 'cassandra') + docker.msg('Root password', 'cassandra') From e2e5d87b76d33feee9003ba11304bdb00213eec4 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 19:21:49 +0100 Subject: [PATCH 28/44] Reuse container name in mongo-express --- dock/formulas/mongo-express.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dock/formulas/mongo-express.py b/dock/formulas/mongo-express.py index 5261578..64ebac7 100644 --- a/dock/formulas/mongo-express.py +++ b/dock/formulas/mongo-express.py @@ -3,9 +3,9 @@ container_name = 'mongo-express' def run(args): - docker.force_stop('mongo-express') - docker.requires(dependent='mongo-express', dependency='mongodb') + docker.force_stop(container_name) + docker.requires(dependent=container_name, dependency='mongodb') docker.run(image='knickers/mongo-express:latest', - name='mongo-express', + name=container_name, link=[['mongodb', 'mongo']], publish=[8081]) From 7163c8c49e775d9a29781b9c3115d72ec92b74de Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 19:22:01 +0100 Subject: [PATCH 29/44] Add Kafka formula --- dock/formulas/kafka.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 dock/formulas/kafka.py diff --git a/dock/formulas/kafka.py b/dock/formulas/kafka.py new file mode 100644 index 0000000..f95c30d --- /dev/null +++ b/dock/formulas/kafka.py @@ -0,0 +1,14 @@ +import docker + +container_name = 'kafka' + +def run(args): + docker.force_stop(container_name) + docker.requires(dependent=container_name, dependency='zookeeper') + docker.run(image='ches/kafka:0.8.2.1', + name=container_name, + link=[['zookeeper', 'zookeeper']], + env={ + 'KAFKA_ADVERTISED_HOST_NAME': docker.get_ip() + }, + publish=[7203, 9092]) From 738c4d8beb2b53db80ce6afbe27e2bdcde165386 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 19:26:42 +0100 Subject: [PATCH 30/44] Add Kafka CLI --- dock/formulas/kafka-cli.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 dock/formulas/kafka-cli.py diff --git a/dock/formulas/kafka-cli.py b/dock/formulas/kafka-cli.py new file mode 100644 index 0000000..90644c0 --- /dev/null +++ b/dock/formulas/kafka-cli.py @@ -0,0 +1,15 @@ +import docker + +def run(args): + print('Starting an interactive Docker container which contains the') + print('Kafka CLI tools. Inspect the env to learn about IPs and ports.') + print('Kafka is located at $KAFKA_HOME.') + + docker.run(image='ches/kafka:0.8.2.1', + name='kafka-cli', + auto_remove=True, + detach=False, + interactive=True, + link=[['kafka', 'kafka']], + silent=True, + command=['bash']) From dcf8cb62847f3de5de97ab21c74d72afd1d273bd Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 20:10:12 +0100 Subject: [PATCH 31/44] Add artifactory formula --- dock/formulas/artifactory.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 dock/formulas/artifactory.py diff --git a/dock/formulas/artifactory.py b/dock/formulas/artifactory.py new file mode 100644 index 0000000..b749bf0 --- /dev/null +++ b/dock/formulas/artifactory.py @@ -0,0 +1,11 @@ +import docker + +container_name = 'artifactory' + +def run(args): + docker.force_stop(container_name) + docker.run(image='jfrog-docker-registry.bintray.io/jfrog/artifactory-oss', + name=container_name, + publish=[8081]) + docker.msg('Admin user', 'admin') + docker.msg('Admin password', 'password') From 338ead7b9951ba7768c8bc553762a4257518116a Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 20:26:49 +0100 Subject: [PATCH 32/44] Add Jenkins formula --- dock/formulas/jenkins.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 dock/formulas/jenkins.py diff --git a/dock/formulas/jenkins.py b/dock/formulas/jenkins.py new file mode 100644 index 0000000..9255968 --- /dev/null +++ b/dock/formulas/jenkins.py @@ -0,0 +1,9 @@ +import docker + +container_name = 'jenkins' + +def run(args): + docker.force_stop(container_name) + docker.run(image='jenkins', + name=container_name, + publish=[8080, 50000]) From a59000226f37bfec81be2e14be127b6e23b085f4 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 20:43:26 +0100 Subject: [PATCH 33/44] Add memcached formula --- dock/formulas/memcached.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 dock/formulas/memcached.py diff --git a/dock/formulas/memcached.py b/dock/formulas/memcached.py new file mode 100644 index 0000000..32141ff --- /dev/null +++ b/dock/formulas/memcached.py @@ -0,0 +1,9 @@ +import docker + +container_name = 'memcached' + +def run(args): + docker.force_stop(container_name) + docker.run(image='memcached:1.4.25', + name=container_name, + publish=[11211]) From bacb664cd682126535170f374698a955bd840f36 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 21:03:06 +0100 Subject: [PATCH 34/44] Add Nexus formula --- dock/formulas/nexus.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 dock/formulas/nexus.py diff --git a/dock/formulas/nexus.py b/dock/formulas/nexus.py new file mode 100644 index 0000000..a4e45f4 --- /dev/null +++ b/dock/formulas/nexus.py @@ -0,0 +1,11 @@ +import docker + +container_name = 'nexus' + +def run(args): + docker.force_stop(container_name) + docker.run(image='sonatype/nexus:latest', + name=container_name, + publish=[8081]) + docker.msg('Admin user', 'admin') + docker.msg('Admin password', 'admin123') From d77442d4ff4d612d0fd731dcc9cf866d2146b17a Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sun, 10 Jan 2016 21:19:52 +0100 Subject: [PATCH 35/44] Add sonarqube formula --- dock/formulas/sonarqube.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 dock/formulas/sonarqube.py diff --git a/dock/formulas/sonarqube.py b/dock/formulas/sonarqube.py new file mode 100644 index 0000000..0f555c6 --- /dev/null +++ b/dock/formulas/sonarqube.py @@ -0,0 +1,11 @@ +import docker + +container_name = 'sonarqube' + +def run(args): + docker.force_stop(container_name) + docker.run(image='sonarqube:5.2', + name=container_name, + publish=[9000]) + docker.msg('Admin user', 'admin') + docker.msg('Admin password', 'admin') From 710f0bdc00d701cb7077a820af2c4512aa86ada2 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Mon, 11 Jan 2016 06:18:12 +0100 Subject: [PATCH 36/44] Add rabbitmq formula --- dock/formulas/rabbitmq.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 dock/formulas/rabbitmq.py diff --git a/dock/formulas/rabbitmq.py b/dock/formulas/rabbitmq.py new file mode 100644 index 0000000..a7f9851 --- /dev/null +++ b/dock/formulas/rabbitmq.py @@ -0,0 +1,19 @@ +import docker + +container_name = 'rabbitmq' + +user = 'admin' +password = 'admin' + +def run(args): + docker.force_stop(container_name) + docker.run(image='rabbitmq:3.6.0-management', + name=container_name, + publish=[4369, 5671, 5672, 15671, 15672, 25672], + env={ + 'RABBITMQ_DEFAULT_USER': user, + 'RABBITMQ_DEFAULT_PASS': password + }) + docker.msg('Admin user', user) + docker.msg('Admin password', password) + docker.msg('Management Console', 'http://{}:15672'.format(docker.get_ip())) From d846c8d39bcad7b0e98eb3af0e44d14d95d1f71f Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Mon, 11 Jan 2016 06:19:29 +0100 Subject: [PATCH 37/44] Improve changelog --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec33478..dc5bf84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ # dock changelog -## 2.0.0 (unreleased) -TODO Ben: extend release notes - - Rewriting dock to Python for easier development. +## Unreleased + - Rewrite dock to Python for easier development. + - Use stable Docker image tags where possible to allow reproducible setups. ## 1.3.0 - dock is now compatible with docker-machine thanks to [@codingfabian](https://github.com/CodingFabian). From 02f422de3ececc6ede8f176a03d437b8785e02fe Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Tue, 12 Jan 2016 06:54:12 +0100 Subject: [PATCH 38/44] Rewrite rethinkdb formula --- dock/formulas/rethinkdb.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 dock/formulas/rethinkdb.py diff --git a/dock/formulas/rethinkdb.py b/dock/formulas/rethinkdb.py new file mode 100644 index 0000000..a78e7d4 --- /dev/null +++ b/dock/formulas/rethinkdb.py @@ -0,0 +1,11 @@ +import docker + +container_name = 'rethinkdb' + +def run(args): + docker.force_stop(container_name) + docker.run(image='rethinkdb:2.2.2', + name=container_name, + publish=[8080, 28015, 29015]) + + docker.msg('Admin Interface', 'http://{}:8080'.format(docker.get_ip())) From 9a91973982b46a4d947306caaadadf61368c96a3 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Tue, 12 Jan 2016 06:54:57 +0100 Subject: [PATCH 39/44] Rewrite orientdb formula --- dock/formulas/orientdb.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 dock/formulas/orientdb.py diff --git a/dock/formulas/orientdb.py b/dock/formulas/orientdb.py new file mode 100644 index 0000000..7adc0b7 --- /dev/null +++ b/dock/formulas/orientdb.py @@ -0,0 +1,21 @@ +import docker + +# see +# https://github.com/orientechnologies/docker-docs/blob/master/orientdb/content.md +# https://github.com/orientechnologies/orientdb-docker/issues/4 +# https://hub.docker.com/r/orientdb/orientdb/~/dockerfile/ + +container_name = 'orientdb' + +password = 'root' + +def run(args): + docker.force_stop(container_name) + docker.run(image='orientdb/orientdb:2.1.5', + name=container_name, + publish=[2424, 2480], + env={ + 'ORIENTDB_ROOT_PASSWORD': password + }) + + docker.msg('Root password', password) From 975f6d78221d5db5cd11ff7cdc77ab6da9fa12dd Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Tue, 12 Jan 2016 07:05:36 +0100 Subject: [PATCH 40/44] Execution of only a single formula at a time is a breaking change --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc5bf84..58d7589 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - Rewrite dock to Python for easier development. - Use stable Docker image tags where possible to allow reproducible setups. + - Only allow a single formula to be started at a time **(BREAKING)**. ## 1.3.0 - dock is now compatible with docker-machine thanks to [@codingfabian](https://github.com/CodingFabian). From fbbe8e4e3f1d0712bb97a8317c4717f9bd916be3 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Wed, 13 Jan 2016 10:00:20 +0100 Subject: [PATCH 41/44] Use mongo-express 0.29.3 --- dock/formulas/mongo-express.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dock/formulas/mongo-express.py b/dock/formulas/mongo-express.py index 64ebac7..da60419 100644 --- a/dock/formulas/mongo-express.py +++ b/dock/formulas/mongo-express.py @@ -5,7 +5,7 @@ def run(args): docker.force_stop(container_name) docker.requires(dependent=container_name, dependency='mongodb') - docker.run(image='knickers/mongo-express:latest', + docker.run(image='knickers/mongo-express:0.29.3', name=container_name, link=[['mongodb', 'mongo']], publish=[8081]) From bc6409fc05e99f60b16f5122fc63fbc14cf735b4 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Thu, 14 Jan 2016 07:25:48 +0100 Subject: [PATCH 42/44] Add consul formula --- dock/formulas/consul.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 dock/formulas/consul.py diff --git a/dock/formulas/consul.py b/dock/formulas/consul.py new file mode 100644 index 0000000..9cd8d75 --- /dev/null +++ b/dock/formulas/consul.py @@ -0,0 +1,9 @@ +import docker + +container_name = 'consul' + +def run(args): + docker.force_stop(container_name) + docker.run(image='voxxit/consul:latest', + name=container_name, + publish=[8300, 8301, 8302, 8400, 8500, 8600]) From be224eb13cef61cee46265cbe81d73b526547b0f Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Thu, 14 Jan 2016 07:41:43 +0100 Subject: [PATCH 43/44] Add couchdb formula --- dock/formulas/couchdb.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 dock/formulas/couchdb.py diff --git a/dock/formulas/couchdb.py b/dock/formulas/couchdb.py new file mode 100644 index 0000000..428e784 --- /dev/null +++ b/dock/formulas/couchdb.py @@ -0,0 +1,13 @@ +import docker + +container_name = 'couchdb' + +def run(args): + docker.force_stop(container_name) + docker.run(image='klaemo/couchdb:1.6.1', + name=container_name, + publish=[5984]) + # Define username and password via environment vars once + # https://github.com/klaemo/docker-couchdb/issues/43 + # has been resolved. + #docker.msg('Authentication', 'See auth information in docker logs dock-couchdb') From b09f49f446d5cf0e0e28354b073510f65c1b8f47 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Sat, 16 Jan 2016 08:02:11 +0100 Subject: [PATCH 44/44] Add PHP formulas --- dock/docker.py | 6 +++++- dock/formulas/php5-apache.py | 15 +++++++++++++++ dock/formulas/php5-fpm.py | 15 +++++++++++++++ dock/formulas/php7-apache.py | 15 +++++++++++++++ dock/formulas/php7-fpm.py | 15 +++++++++++++++ 5 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 dock/formulas/php5-apache.py create mode 100644 dock/formulas/php5-fpm.py create mode 100644 dock/formulas/php7-apache.py create mode 100644 dock/formulas/php7-fpm.py diff --git a/dock/docker.py b/dock/docker.py index 5e8a594..4de7567 100644 --- a/dock/docker.py +++ b/dock/docker.py @@ -57,7 +57,8 @@ def run(image, link=[], command=None, entrypoint=None, - env={}): + env={}, + volume={}): name = add_name_prefix(name) args = ['docker', 'run', '--name', name] @@ -77,6 +78,9 @@ def run(image, if mount_docker_socket: args.extend(['--volume', '/var/run/docker.sock:/var/run/docker.sock']) + for key in volume: + args.extend(['--volume', '{}:{}'.format(key, volume[key])]) + for publishedPort in publish: args.extend(['--publish', '{}:{}'.format(publishedPort, publishedPort)]) diff --git a/dock/formulas/php5-apache.py b/dock/formulas/php5-apache.py new file mode 100644 index 0000000..fbe7066 --- /dev/null +++ b/dock/formulas/php5-apache.py @@ -0,0 +1,15 @@ +import docker +import os + +cwd = os.getcwd() +container_name = 'php5-apache' + +def run(args): + docker.force_stop(container_name) + docker.run(image='php:5-apache', + name=container_name, + volume={ + os.getcwd(): '/var/www/html' + }, + publish=[80]) + docker.msg('Volume', '{} mounted to /var/www/html'.format(os.getcwd())) diff --git a/dock/formulas/php5-fpm.py b/dock/formulas/php5-fpm.py new file mode 100644 index 0000000..cd190ce --- /dev/null +++ b/dock/formulas/php5-fpm.py @@ -0,0 +1,15 @@ +import docker +import os + +cwd = os.getcwd() +container_name = 'php5-fpm' + +def run(args): + docker.force_stop(container_name) + docker.run(image='php:5-fpm', + name=container_name, + volume={ + os.getcwd(): '/var/www/html' + }, + publish=[9000]) + docker.msg('Volume', '{} mounted to /var/www/html'.format(os.getcwd())) diff --git a/dock/formulas/php7-apache.py b/dock/formulas/php7-apache.py new file mode 100644 index 0000000..498b0ac --- /dev/null +++ b/dock/formulas/php7-apache.py @@ -0,0 +1,15 @@ +import docker +import os + +cwd = os.getcwd() +container_name = 'php7-apache' + +def run(args): + docker.force_stop(container_name) + docker.run(image='php:7-apache', + name=container_name, + volume={ + os.getcwd(): '/var/www/html' + }, + publish=[80]) + docker.msg('Volume', '{} mounted to /var/www/html'.format(os.getcwd())) diff --git a/dock/formulas/php7-fpm.py b/dock/formulas/php7-fpm.py new file mode 100644 index 0000000..3fbf756 --- /dev/null +++ b/dock/formulas/php7-fpm.py @@ -0,0 +1,15 @@ +import docker +import os + +cwd = os.getcwd() +container_name = 'php7-fpm' + +def run(args): + docker.force_stop(container_name) + docker.run(image='php:7-fpm', + name=container_name, + volume={ + os.getcwd(): '/var/www/html' + }, + publish=[9000]) + docker.msg('Volume', '{} mounted to /var/www/html'.format(os.getcwd()))