Skip to content

Commit

Permalink
added docker
Browse files Browse the repository at this point in the history
  • Loading branch information
kooba committed Aug 30, 2016
1 parent ab7626b commit 21a366a
Show file tree
Hide file tree
Showing 16 changed files with 136 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
*.pyc
htmlcov
.coverage
*/wheelhouse
*.sql
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
IMAGES := orders


# test

coverage-html:
Expand All @@ -11,3 +14,23 @@ test:
coverage run -m pytest */test $(ARGS)

coverage: test coverage-report coverage-html

# docker

build-example-base:
docker build -t nameko-example-base -f docker/docker.base .;

build-wheel-builder: build-example-base
docker build -t nameko-example-builder -f docker/docker.build .;

run-wheel-builder: build-wheel-builder
for image in $(IMAGES) ; do make -C $$image run-wheel-builder; done

#build-image-base: run-wheel-builder
# docker build -t nameko-example-base \
# -f docker/docker.run .;

build-images: run-wheel-builder
for image in $(IMAGES) ; do make -C $$image build-image; done

build: build-images
34 changes: 34 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: '2'
services:
rabbit:
container_name: rabbit
image: rabbitmq:3.6-management
ports:
# management plugin port, use RABBITMQ_DEFAULT_USER to log in
- "15673:15672"
# regular rabbit port, to enable access from the outside
- "5673:5672"
restart: always

postgres:
container_name: postgres
image: postgres
ports:
- "5433:5432"
environment:
POSTGRES_PASSWORD: "password"
POSTGRES_USER: "postgres"
restart: always

orders:
container_name: orders
image: nameko/nameko-example-orders:latest
depends_on:
- rabbit
- postgres
ports:
- "8001:8000"
links:
- "rabbit:rabbit"
- "postgres:postgres"

14 changes: 14 additions & 0 deletions docker/docker.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM debian:jessie

RUN apt-get update && \
apt-get install -qyy \
-o APT::Install-Recommends=false -o APT::Install-Suggests=false \
python3 python-pip ca-certificates && \
cd /usr/local/bin && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN pip install virtualenv

RUN virtualenv -p python3 /appenv
RUN . /appenv/bin/activate; pip install -U pip
23 changes: 23 additions & 0 deletions docker/docker.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM nameko-example-base

RUN apt-get update && \
apt-get install -qyy \
-o APT::Install-Recommends=false -o APT::Install-Suggests=false \
build-essential python3-dev libpq-dev python-psycopg2 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN . /appenv/bin/activate; \
pip install wheel


ENV WHEELHOUSE=/wheelhouse
ENV PIP_WHEEL_DIR=/wheelhouse
ENV PIP_FIND_LINKS=/wheelhouse

VOLUME /wheelhouse
VOLUME /application

CMD . /appenv/bin/activate; \
cd /application; \
pip wheel .
9 changes: 9 additions & 0 deletions orders/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# docker

run-wheel-builder:
docker run --rm \
-v "$$(pwd)":/application -v "$$(pwd)"/wheelhouse:/wheelhouse \
nameko-example-builder;

build-image:
docker build -t nameko/nameko-example-orders:latest -f docker.run .;
Empty file removed orders/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions orders/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DB_URIS:
"orders:Base": "postgresql://postgres:password@postgres/orders"

AMQP_URI: "amqp://guest:guest@rabbit:5672/"
15 changes: 15 additions & 0 deletions orders/docker.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM nameko-example-base

ADD wheelhouse /var/nameko/wheelhouse

WORKDIR /var/nameko/

COPY config.yml /var/nameko/config.yml

RUN . /appenv/bin/activate; \
pip install --no-index -f wheelhouse nameko_examples_orders

EXPOSE 8000

CMD . /appenv/bin/activate; \
nameko run --config config.yml service --backdoor 3000
4 changes: 2 additions & 2 deletions orders/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from nameko.rpc import rpc
from nameko_sqlalchemy import DatabaseSession

from orders.models import DeclarativeBase, Order, OrderDetail
from orders.schemas import OrderSchema
from models import DeclarativeBase, Order, OrderDetail
from schemas import OrderSchema


class OrdersService:
Expand Down
6 changes: 4 additions & 2 deletions orders/setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#!/usr/bin/env python
from setuptools import setup
from setuptools import find_packages, setup

setup(
name='nameko-examples-orders',
version='0.0.1',
description='Store and serve orders',
packages=[''],
install_requires=[
'nameko==2.3.1',
'nameko-sqlalchemy==0.0.3',
'alembic==0.8.7',
'marshmallow==2.9.1'
'marshmallow==2.9.1',
'psycopg2==2.6.2'
],
extras_require={
'dev': [
Expand Down
Empty file removed orders/test/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion orders/test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from orders.models import DeclarativeBase
from models import DeclarativeBase


@pytest.fixture(scope='session')
Expand Down
2 changes: 1 addition & 1 deletion orders/test/interface/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from nameko.standalone.rpc import ServiceRpcProxy
from nameko.testing.services import replace_dependencies

from orders.service import OrdersService
from service import OrdersService


@pytest.fixture
Expand Down
5 changes: 3 additions & 2 deletions orders/test/interface/test_service.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import pytest

from mock import call
from orders.models import Order, OrderDetail
from orders.schemas import OrderSchema, OrderDetailSchema

from models import Order, OrderDetail
from schemas import OrderSchema, OrderDetailSchema


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion orders/test/unit/test_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from orders.models import Order, OrderDetail
from models import Order, OrderDetail


def test_can_create_order(db_session):
Expand Down

0 comments on commit 21a366a

Please sign in to comment.