diff --git a/Makefile b/Makefile index c797d53..55b904b 100644 --- a/Makefile +++ b/Makefile @@ -3,27 +3,48 @@ BUILD:=$(shell bash -c 'source version.sh ; echo $$BUILD') OS_NAME:=$(shell bash -c 'source version.sh ; echo $$OS_NAME') ifeq "$(OS_NAME)" "win" PIP=$(shell pwd)/virtualenv/Scripts/pip - SDIST_EXT=zip VIRTUALENV_PKGS_DIR=$(shell pwd)/virtualenv/Lib/site-packages else PIP=$(shell pwd)/virtualenv/bin/pip - SDIST_EXT=tar.gz VIRTUALENV_PKGS_DIR=$(shell pwd)/virtualenv/lib/site-packages endif VIRTUALENV=$(shell which virtualenv) PYTHON=$(shell which python) PYTHON_FILES=setup.py mercy/version.py $(shell find mercy -iname "*py") -PYTHON_SDIST=./dist/mercy-$(MAJOR)-$(BUILD).$(SDIST_EXT) - -.PHONY: virtualenv -virtualenv: - $(VIRTUALENV) --no-site-packages --distribute virtualenv +PYTHON_SDIST=./dist/mercy-$(MAJOR)-$(BUILD).tar.gz .PHONY: clean clean: rm -fr dist/* find mercy -iname "*pyc" -exec rm -vf \{\} \; + cd puppet && make clean + +############## Targets for puppet module + +puppet/version.sh: version.sh + cp version.sh $@ + +.PHONY: puppet +puppet: puppet_dist + +.PHONY: puppet_dist +puppet_dist: puppet/version.sh + cd puppet && make dist + +.PHONY: puppet_install +puppet_install: puppet/version.sh + cd puppet && make install + +.PHONY: puppet_uninstall +puppet_uninstall: puppet/version.sh + cd puppet && make uninstall + +################ /puppet module + +############### Targets for python app + +dist: $(PYTHON_SDIST) puppet sdist: $(PYTHON_SDIST) @@ -31,10 +52,18 @@ mercy/version.py: version.sh source version.sh && echo "VERSION=\"$${MAJOR}-$${BUILD}\"" > $@ $(PYTHON_SDIST): $(PYTHON_FILES) - $(PYTHON) setup.py sdist + $(PYTHON) setup.py sdist --formats=gztar uninstall: rm -fr $(VIRTUALENV_PKGS_DIR)/mercy-* || echo 'not installed' -install: $(PYTHON_SDIST) +install: $(PYTHON_SDIST) virtualenv $(PIP) install $(PYTHON_SDIST) --upgrade + +.PHONY: virtualenv +virtualenv: + if [ ! -e $(PIP) ]; then \ + $(VIRTUALENV) --no-site-packages --distribute virtualenv ; \ + fi + +################## /python app diff --git a/puppet/Makefile b/puppet/Makefile new file mode 100644 index 0000000..3cbe528 --- /dev/null +++ b/puppet/Makefile @@ -0,0 +1,32 @@ +MAJOR:=$(shell bash -c 'source version.sh ; echo $$MAJOR') +BUILD:=$(shell bash -c 'source version.sh ; echo $$BUILD') +MODULEPATH:=$(shell puppet config print modulepath) +ifeq ($(MODULEPATH),) +$(error "I can't figure out your puppet modulepath, this will cause all kinds of bad things to happen with 'make install' and 'make uninstall'") +endif +PUPPET_DEPS=$(find mercy -type f) +PUPPET_DIST=mercy/pkg/akesterson-mercy-$(MAJOR).$(BUILD).tar.gz + +.PHONY: clean +clean: + rm pkg/* + rm Modulefile + +mercy/Modulefile: Modulefile.template.sh version.sh + source version.sh && bash Modulefile.template.sh > Modulefile + +$(PUPPET_DIST): $(PUPPET_DEPS) mercy/Modulefile + rm -f $(PUPPET_DIST) + mkdir -p $$(dirname $(PUPPET_DIST)) + echo 'We would use puppet module tool here but we dont because it doesnt work on windows buildhosts and cant upload from the command line anyway' + tar --exclude=mercy/Modulefile --exclude=mercy/pkg -czvf $(PUPPET_DIST) mercy/ + +dist: $(PUPPET_DIST) + +all: $(PUPPET_DIST) + +install: $(PUPPET_DIST) + tar -zxvf $(PUPPET_DIST) -C $(MODULEPATH) + +uninstall: + rm -fr $(MODULEPATH)/mercy \ No newline at end of file diff --git a/puppet/Modulefile.template.sh b/puppet/Modulefile.template.sh new file mode 100644 index 0000000..1a5b974 --- /dev/null +++ b/puppet/Modulefile.template.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +cat <' +EOF diff --git a/puppet/README.md b/puppet/README.md new file mode 100644 index 0000000..a2eb68c --- /dev/null +++ b/puppet/README.md @@ -0,0 +1,36 @@ +mercy +===== + +A puppet module for installing the Mercy Flask application + +Requirements +============ + +This puppet module assumes that you have: + +* Working apache with a puppet service +* Working python 2.7 and pip +* Working postgres with a username, password, and database for mercy to use + +Aside from that, the module has no dependencies. + +Usage +========= + + class { 'mercy::application': + environment => 'dev|production', + ensure => 'absent|latest|MAJOR-MINOR', + vhost_dir => '/etc/apache/httpd/conf.d', + apache_service => 'httpd', + postgres_uri => 'localhost', + postgres_user => 'mercy', + postgres_pw => 'mercy', + postgres_db => 'mercy' + } + +If 'environment' is dev, then the mercy application will be installed via a tarball located in ./mercy/files/mercy-${ensure}.tar.gz. If 'environment' is production, then mercy will be installed via pip and ensured at the given version. + +Events +====== + +This puppet module will notify your apache service whenever the vhost is modified, or the mercy application version is updated, since an apache graceful restart will be required in either case.