diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96c54ca --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vagrant +.pyc diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..09819f8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM ubuntu:12.04 +MAINTAINER Chris Reeves + +ADD . /foo + +WORKDIR /foo +RUN cd /foo + +RUN apt-get install -y python python-dev python-software-properties +RUN apt-get install -y make +RUN apt-get install -y wget +RUN apt-get install -y tar +RUN wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py --no-check-certificate -O - | python +RUN wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py --no-check-certificate -O - | python +RUN make develop + +EXPOSE 8080 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d1ada7a --- /dev/null +++ b/Makefile @@ -0,0 +1,41 @@ +# +# Generic functions +# + +clean_pyc: + find . -name \*.pyc -delete + +documentation: + make -C docs clean + make -C docs html + +# +# Install for development +# + +# Install Development Requirements +install_develop: + ./install.sh develop + +develop: install_develop + +# +# Install for test running +# + +# Install Test Requirements +install_test: + ./install.sh test + +# Test Command +run_tests: + python setup.py test + +test: install_test run_tests + +# +# Application Related Commands +# + +runserver: + python src/foo/run.py diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..2c28cbd --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,45 @@ +#!/usr/bin/ruby + +# +# Vagrant File for Docker - Requires Vagrant 1.1+ +# Provisioner: Salt +# OS: Ubuntu 12.04 LTS 64Bit +# + +Vagrant.configure("2") do |config| + + # Base Box - http://www.vagrantbox.es/ - Ubuntu 12.04 LTS 64bit + config.vm.box = "precise64" + config.vm.box_url = "http://files.vagrantup.com/precise64.box" + config.ssh.forward_agent = true + + # Port Forwarding + config.vm.network :forwarded_port, guest: 4243, host: 4243 + (49000..49900).each do |port| + config.vm.network :forwarded_port, :host => port, :guest => port + end + + # Virutalbox Settings + config.vm.provider :virtualbox do |v| + # Enables symlinks + v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"] + end + + # + # Mounts + # + + config.vm.synced_folder ".", "/foo" + config.vm.synced_folder "./provisioner", "/srv/salt" + + # + # Provisioner - Salt + # + + config.vm.provision :salt do |salt| + salt.run_highstate = true + salt.minion_config = "provisioner/config/minion.conf" + salt.install_type = "stable" + end + +end diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..98e2af9 --- /dev/null +++ b/install.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if [ $1 ] +then + pip install -e .[$1] +else + pip install -e . +fi diff --git a/provisioner/config/minion.conf b/provisioner/config/minion.conf new file mode 100644 index 0000000..7675640 --- /dev/null +++ b/provisioner/config/minion.conf @@ -0,0 +1,14 @@ +# +# Salt Minion Config +# + +# Masterless Mode +file_client: local + +# File Roots +file_roots: + base: + - /srv/salt/states/ + +# Renderer +renderer: stateconf yaml . jinja diff --git a/provisioner/states/docker/config.sls b/provisioner/states/docker/config.sls new file mode 100644 index 0000000..b8f7ab4 --- /dev/null +++ b/provisioner/states/docker/config.sls @@ -0,0 +1,16 @@ +# +# docker.config +# +# Docker configuration +# + +.docker_service_config: + file: + - managed + - name: /etc/init/docker.conf + - source: salt://docker/files/docker.service.conf + - user: root + - group: root + - mode: 644 + - require: + - stateconf: docker.install::goal diff --git a/provisioner/states/docker/dependencies.sls b/provisioner/states/docker/dependencies.sls new file mode 100644 index 0000000..7bdd9e7 --- /dev/null +++ b/provisioner/states/docker/dependencies.sls @@ -0,0 +1,9 @@ +# +# docker.dependencies +# +# Dependencies for installing Docker +# + +.python-software-properties: + pkg: + - installed diff --git a/provisioner/states/docker/files/docker.service.conf b/provisioner/states/docker/files/docker.service.conf new file mode 100644 index 0000000..f6829fe --- /dev/null +++ b/provisioner/states/docker/files/docker.service.conf @@ -0,0 +1,10 @@ +description "Run docker" + +start on filesystem or runlevel [2345] +stop on runlevel [!2345] + +respawn + +script + /usr/bin/docker -d -H tcp://0.0.0.0:4243 +end script diff --git a/provisioner/states/docker/init.sls b/provisioner/states/docker/init.sls new file mode 100644 index 0000000..c1b86e1 --- /dev/null +++ b/provisioner/states/docker/init.sls @@ -0,0 +1,9 @@ +# +# Docker Salt Module +# + +include: + - ..dependencies + - ..install + - ..config + - ..service diff --git a/provisioner/states/docker/install.sls b/provisioner/states/docker/install.sls new file mode 100644 index 0000000..64b6003 --- /dev/null +++ b/provisioner/states/docker/install.sls @@ -0,0 +1,32 @@ +# +# docker.install +# +# Installs Docker +# + +.docker_repo: + pkgrepo: + - managed + - name: 'deb http://get.docker.io/ubuntu docker main' + - key_url: 'https://get.docker.io/gpg' + - require: + - pkg: .dependencies::python-software-properties + +.linux-image-generic-lts-raring: + pkg: + - installed + - require: + - pkgrepo: .docker_repo + +.linux-headers-generic-lts-raring: + pkg: + - installed + - require: + - pkgrepo: .docker_repo + +.lxc-docker: + pkg: + - installed + - require: + - pkg: .linux-image-generic-lts-raring + - pkg: .linux-headers-generic-lts-raring diff --git a/provisioner/states/docker/service.sls b/provisioner/states/docker/service.sls new file mode 100644 index 0000000..b3ef961 --- /dev/null +++ b/provisioner/states/docker/service.sls @@ -0,0 +1,17 @@ +# +# docker.service +# +# Docker Service Management +# + +.docker_service: + service: + - running + - name: docker + - enable: True + - reload: True + - watch: + - pkg: .install::lxc-docker + - file: .config::docker_service_config + - require: + - stateconf: docker.config::goal diff --git a/provisioner/states/top.sls b/provisioner/states/top.sls new file mode 100644 index 0000000..10eca95 --- /dev/null +++ b/provisioner/states/top.sls @@ -0,0 +1,8 @@ +# +# Top SLS File +# + +base: + + '*': + - docker diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..79ec2df --- /dev/null +++ b/setup.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python + +import os +import sys +import multiprocessing # NOQA + +from setuptools import setup, find_packages + +sys.path.append( + os.path.abspath(os.path.join(os.path.dirname(__file__), 'src'))) + + +def read(fname): + return open(fname).read() + + +install_requires = [ + 'flask==0.10.1', +] + +test_requires = [ + 'mock==1.0.1', + 'tox==1.4.3', + 'nose==1.3', + 'coverage==3.6', + 'coveralls==0.2', +] + +dev_requires = test_requires + [ + 'pytest==2.3.5', + 'pdbpp==0.7', + 'ipython==0.13.2', + 'flake8==2.0', +] + +setup( + name='foo', + version='0.0.1', + author='Christopher John Reeves', + author_email='chris@adaptivelab.co.uk', + url='https://github.com/krak3n/foo.git', + description='Fooythings', + long_description='foo', + package_dir={'': 'src'}, + packages=find_packages('src'), + include_package_data=True, + zip_safe=False, + install_requires=install_requires, + test_suite='runtests.runtests', + extras_require={ + 'test': test_requires, + 'develop': dev_requires, + }, + classifiers=[ + 'Environment :: Console', + 'Development Status :: 5 - Production/Stable', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2.7', + 'Operating System :: Unix', + 'License :: OSI Approved :: BSD License', + 'Topic :: Software Development', + 'Topic :: Software Development :: Libraries :: Python Modules', + ], + license='BSD' +) diff --git a/src/foo/__init__.py b/src/foo/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/foo/__init__.pyc b/src/foo/__init__.pyc new file mode 100644 index 0000000..da9c755 Binary files /dev/null and b/src/foo/__init__.pyc differ diff --git a/src/foo/run.py b/src/foo/run.py new file mode 100644 index 0000000..3a7d241 --- /dev/null +++ b/src/foo/run.py @@ -0,0 +1,16 @@ +from flask import Flask +app = Flask(__name__) + + +@app.route('/') +def hello_world(): + return 'Foo All The Things!' + + +if __name__ == '__main__': + kwargs = {} + kwargs.update({ + 'host': '0.0.0.0', + 'port': 8080 + }) + app.run(**kwargs)