Skip to content

Commit

Permalink
initial commit of multiple dockerfile experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Carey committed Aug 7, 2014
1 parent d6833a5 commit e31065d
Show file tree
Hide file tree
Showing 20 changed files with 164 additions and 175 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ops/logs/
*.pyc
28 changes: 0 additions & 28 deletions Dockerfile

This file was deleted.

32 changes: 16 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
ENV=live
TAG=rehabstudio/pythonproject

help:
@echo "\nall - Build & run a fresh Container"
@echo "build-container - Build Container"
@echo "run-container - Run Container"
@echo "remove-container - Remove Container"
@echo "\nGLOBAL ARGS (ENV=local, TAG=rehabstudio/pythonproject)"
@echo "\neg. make all ENV=live TAG=myapp\n"
@echo "build-local - Build container for local development"
@echo "build-deploy - Build container in production mode"
@echo "run-local - Run container for local development"
@echo "run-deploy - Run container for in production mode"
@echo "$(CURDIR)"

build-base:
cd ops/base/; docker build -t="rehabstudio/python-base" .

all: build run
build-local: build-base
cd ops/local/; docker build -t="rehabstudio/python-local" .

build:
@docker build -t="$(TAG)" .
build-deploy: build-base
cd ops/deploy/; docker build -t="rehabstudio/python-deploy" .

run:
@docker run -P -v=$(CURDIR)/app/:/var/app:rw -d -e ENV=$(ENV) $(TAG)
run-local: build-local
docker run -P -t -i -v $(CURDIR)/app:/opt/app rehabstudio/python-local

remove:
-@docker rmi $(TAG)
run-deploy: build-deploy
docker run -P -v $(CURDIR)/app:/opt/app rehabstudio/python-deploy
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
Docker Python Base
==================

A bare bones python Docker setup to support local and production development from a single ops base
A bare bones python Docker setup to support local and production development from a single ops base. A super simple Flask app is contained in the `app/` directory for demo purposes, but this can easily be switched for any WSGI compatible application.

##Steps to run

1. `make all`. Note: you may need to run this as sudo, depending on how your docker install is set up, eg. `sudo make all`
## Steps to run

##Useful Docker Commands (use with care)
For local development simply run `sudo make run-local`. Once built, the container will run the Flask demo app on http://<container_ip>:5000.

To run the deploy in a production container, run `sudo make run-deploy`. Once built, the container will run the Flask demo app on http://<container_ip>.

In addition to the `run` commands, `make build-local` and `make build-deploy` are available to allow building containers without running them.


## Useful Docker Commands (use with care)

- View docker images
```
Expand All @@ -25,11 +31,11 @@ sudo docker logs -f <containerID>
```
sudo docker stop <containerID>
```
- Delete dead images
- Delete dead images
```
for i in `sudo docker images|grep \<none\>|awk '{print $3}'`;do sudo docker rmi $i;done
```
- Delete containers
- Delete containers
```
sudo docker rm -f `sudo docker ps --no-trunc -a -q`
```
11 changes: 11 additions & 0 deletions app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from flask import Flask
app = Flask(__name__)


@app.route("/")
def hello():
return "Hello World!"


if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0')
2 changes: 0 additions & 2 deletions app/requirements.txt

This file was deleted.

32 changes: 32 additions & 0 deletions ops/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM ubuntu:14.04
MAINTAINER Peter McConnell <[email protected]>

# keep upstart quiet
RUN dpkg-divert --local --rename --add /sbin/initctl
RUN ln -sf /bin/true /sbin/initctl

# no tty
ENV DEBIAN_FRONTEND noninteractive

# get up to date
RUN apt-get update --fix-missing

# global installs [applies to all envs!]
RUN apt-get install -y build-essential git
RUN apt-get install -y python python-dev python-setuptools
RUN apt-get install -y python-pip python-virtualenv
RUN apt-get install -y nginx supervisor

# stop supervisor service as we'll run it manually
RUN service supervisor stop

# build dependencies for postgres and image bindings
RUN apt-get build-dep -y python-imaging python-psycopg2

# create a virtual environment and install all depsendecies from pypi
RUN virtualenv /opt/venv
ADD ./requirements.txt /opt/venv/requirements.txt
RUN /opt/venv/bin/pip install -r /opt/venv/requirements.txt

# expose port(s)
EXPOSE 80
3 changes: 3 additions & 0 deletions ops/base/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Flask
gunicorn
requests
15 changes: 15 additions & 0 deletions ops/deploy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM rehabstudio/python-base
MAINTAINER Peter McConnell <[email protected]>

RUN pip install supervisor-stdout

# file management, everything after an ADD is uncached, so we do it as late as
# possible in the process.
ADD ./supervisord.conf /etc/supervisord.conf
ADD ./nginx.conf /etc/nginx/nginx.conf

# restart nginx to load the config
RUN service nginx stop

# start supervisor to run our wsgi server
CMD supervisord -c /etc/supervisord.conf -n
48 changes: 48 additions & 0 deletions ops/deploy/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
daemon off;
worker_processes 1;

# user nobody nogroup;
pid /tmp/nginx.pid;
error_log /tmp/nginx.error.log;

events {
worker_connections 1024;
accept_mutex off;
}

http {
include mime.types;
default_type application/octet-stream;
access_log /tmp/nginx.access.log combined;
sendfile on;

upstream app_server {
# For a TCP configuration:
server 127.0.0.1:5000 fail_timeout=0;
}

server {
listen 80 default;
client_max_body_size 4G;
server_name _;

keepalive_timeout 5;

# path for static files
root /opt/app/static;

location / {
# checks for static file, if not found proxy to app
try_files $uri @proxy_to_app;
}

location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;

proxy_pass http://app_server;
}

}
}
19 changes: 19 additions & 0 deletions ops/deploy/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[supervisord]
nodaemon = true

[program:nginx]
command = /usr/sbin/nginx
startsecs = 5
stdout_events_enabled = true
stderr_events_enabled = true

[program:app-gunicorn]
command = /opt/venv/bin/gunicorn app:app -w 4 -b 127.0.0.1:5000 --log-level=debug --chdir=/opt/app
stdout_events_enabled = true
stderr_events_enabled = true

[eventlistener:stdout]
command = supervisor_stdout
buffer_size = 100
events = PROCESS_LOG
result_handler = supervisor_stdout:event_handler
4 changes: 0 additions & 4 deletions ops/dev/docker-build.sh

This file was deleted.

4 changes: 0 additions & 4 deletions ops/dev/docker-run.sh

This file was deleted.

21 changes: 0 additions & 21 deletions ops/live/docker-build.sh

This file was deleted.

4 changes: 0 additions & 4 deletions ops/live/docker-run.sh

This file was deleted.

15 changes: 0 additions & 15 deletions ops/live/supervisord.conf

This file was deleted.

15 changes: 0 additions & 15 deletions ops/live/uwsgi_params.conf

This file was deleted.

35 changes: 0 additions & 35 deletions ops/live/vhost.conf

This file was deleted.

7 changes: 7 additions & 0 deletions ops/local/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM rehabstudio/python-base
MAINTAINER Peter McConnell <[email protected]>

# start supervisor to run our wsgi server
CMD cd /opt/app/ && /opt/venv/bin/python app.py

EXPOSE 5000
24 changes: 0 additions & 24 deletions ops/run.sh

This file was deleted.

0 comments on commit e31065d

Please sign in to comment.