-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from nameko/orders
Orders
- Loading branch information
Showing
27 changed files
with
818 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[run] | ||
concurrency = eventlet | ||
|
||
omit = | ||
*/test/* | ||
*/setup.py | ||
|
||
source = orders | ||
|
||
[html] | ||
directory = htmlcov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
*.egg-info | ||
.cache | ||
*.pyc | ||
htmlcov | ||
.coverage | ||
*/wheelhouse | ||
*.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
HTMLCOV_DIR ?= htmlcov | ||
|
||
IMAGES := orders | ||
|
||
# test | ||
|
||
coverage-html: | ||
coverage html -d $(HTMLCOV_DIR) --fail-under 100 | ||
|
||
coverage-report: | ||
coverage report -m | ||
|
||
test: | ||
flake8 orders | ||
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-images: run-wheel-builder | ||
for image in $(IMAGES) ; do make -C $$image build-image; done | ||
|
||
build: build-images |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,25 @@ | ||
# Nameko Examples | ||
|
||
Work in progress | ||
[![CircleCI](https://circleci.com/gh/nameko/nameko-examples/tree/orders.svg?style=svg)](https://circleci.com/gh/nameko/nameko-examples/tree/orders) | ||
|
||
TODO: Overview of the project | ||
|
||
# Prerequisites | ||
|
||
* Python 3 | ||
* [Docker](https://www.docker.com/) | ||
* [Docker Compose](https://docs.docker.com/compose/) | ||
|
||
# Run tests | ||
|
||
Ensure RabbitMQ is running. | ||
|
||
`$ make coverage` | ||
|
||
# Run docker compose | ||
|
||
Quickest way to try out examples is to run them with [Docker Compose](https://docs.docker.com/compose/) | ||
|
||
`$ docker-compose up` | ||
|
||
Docker images for [RabbitMQ](https://hub.docker.com/_/rabbitmq/), [PostgreSQL](https://hub.docker.com/_/postgres/) and [Redis](https://hub.docker.com/_/redis/) will be automatically downloaded and their containers linked to our service containers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
machine: | ||
python: | ||
version: 3.4.3 | ||
services: | ||
- docker | ||
- rabbitmq-server | ||
pre: | ||
- sudo rabbitmq-plugins enable rabbitmq_management | ||
|
||
dependencies: | ||
pre: | ||
- pip install -U pip wheel setuptools | ||
- cd orders; pip install -U .[dev] | ||
|
||
test: | ||
override: | ||
- HTMLCOV_DIR=$CIRCLE_ARTIFACTS make coverage | ||
post: | ||
- make build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
version: "2" | ||
services: | ||
rabbit: | ||
container_name: nameko-example-rabbitmq | ||
image: rabbitmq:3.6-management | ||
ports: | ||
- "15673:15672" # Exposing RabbitMQ web management on different port for convenience | ||
restart: always | ||
|
||
postgres: | ||
container_name: nameko-example-postgres | ||
image: postgres | ||
ports: | ||
- "5433:5432" # Exposing Postgres on different port for convenience | ||
environment: | ||
POSTGRES_DB: "orders" | ||
POSTGRES_PASSWORD: "password" | ||
POSTGRES_USER: "postgres" | ||
restart: always | ||
|
||
orders: | ||
container_name: nameko-example-orders | ||
image: nameko/nameko-example-orders:latest | ||
depends_on: | ||
- rabbit | ||
- postgres | ||
ports: | ||
- "8001:8000" | ||
links: | ||
- "rabbit:nameko-example-rabbitmq" | ||
- "postgres:nameko-example-postgres" | ||
environment: | ||
DB_PASSWORD: "password" | ||
DB_USER: "postgres" | ||
DB_HOST: "postgres" | ||
DB_NAME: "orders" | ||
RABBIT_PASSWORD: "guest" | ||
RABBIT_USER: "guest" | ||
RABBIT_HOST: "rabbit" | ||
RABBIT_PORT: "5672" | ||
RABBIT_MANAGEMENT_PORT: "15672" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 libpq-dev python-psycopg2 curl && \ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 && \ | ||
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 . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 .; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# A generic, single database configuration. | ||
|
||
[alembic] | ||
# path to migration scripts | ||
script_location = alembic | ||
|
||
# template used to generate migration files | ||
# file_template = %%(rev)s_%%(slug)s | ||
|
||
# max length of characters to apply to the | ||
# "slug" field | ||
#truncate_slug_length = 40 | ||
|
||
# set to 'true' to run the environment during | ||
# the 'revision' command, regardless of autogenerate | ||
# revision_environment = false | ||
|
||
# set to 'true' to allow .pyc and .pyo files without | ||
# a source .py file to be detected as revisions in the | ||
# versions/ directory | ||
# sourceless = false | ||
|
||
# version location specification; this defaults | ||
# to alembic/versions. When using multiple version | ||
# directories, initial revisions must be specified with --version-path | ||
# version_locations = %(here)s/bar %(here)s/bat alembic/versions | ||
|
||
# the output encoding used when revision files | ||
# are written from script.py.mako | ||
# output_encoding = utf-8 | ||
|
||
# Logging configuration | ||
[loggers] | ||
keys = root,sqlalchemy,alembic | ||
|
||
[handlers] | ||
keys = console | ||
|
||
[formatters] | ||
keys = generic | ||
|
||
[logger_root] | ||
level = WARN | ||
handlers = console | ||
qualname = | ||
|
||
[logger_sqlalchemy] | ||
level = WARN | ||
handlers = | ||
qualname = sqlalchemy.engine | ||
|
||
[logger_alembic] | ||
level = INFO | ||
handlers = | ||
qualname = alembic | ||
|
||
[handler_console] | ||
class = StreamHandler | ||
args = (sys.stdout,) | ||
level = NOTSET | ||
formatter = generic | ||
|
||
[formatter_generic] | ||
format = %(levelname)-5.5s [%(name)s] %(message)s | ||
datefmt = %H:%M:%S |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Generic single-database configuration. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
from __future__ import with_statement | ||
import os | ||
from alembic import context | ||
from sqlalchemy import create_engine | ||
from logging.config import fileConfig | ||
|
||
from orders.models import DeclarativeBase | ||
|
||
|
||
# this is the Alembic Config object, which provides | ||
# access to the values within the .ini file in use. | ||
config = context.config | ||
|
||
# Interpret the config file for Python logging. | ||
# This line sets up loggers basically. | ||
fileConfig(config.config_file_name) | ||
|
||
# add your model's MetaData object here | ||
# for 'autogenerate' support | ||
# from myapp import mymodel | ||
# target_metadata = mymodel.Base.metadata | ||
target_metadata = DeclarativeBase.metadata | ||
|
||
# other values from the config, defined by the needs of env.py, | ||
# can be acquired: | ||
# my_important_option = config.get_main_option("my_important_option") | ||
# ... etc. | ||
|
||
|
||
def get_url(): | ||
return ( | ||
"postgresql://{db_user}:{db_pass}@{db_host}:" | ||
"{db_port}/{db_name}" | ||
).format( | ||
db_user=os.getenv("DB_USER", "postgres"), | ||
db_pass=os.getenv("DB_PASSWORD", "password"), | ||
db_host=os.getenv("DB_HOST", "localhost"), | ||
db_port=os.getenv("DB_PORT", "5432"), | ||
db_name=os.getenv("DB_NAME", "orders"), | ||
) | ||
|
||
|
||
def run_migrations_offline(): | ||
"""Run migrations in 'offline' mode. | ||
This configures the context with just a URL | ||
and not an Engine, though an Engine is acceptable | ||
here as well. By skipping the Engine creation | ||
we don't even need a DBAPI to be available. | ||
Calls to context.execute() here emit the given string to the | ||
script output. | ||
""" | ||
url = get_url() | ||
context.configure( | ||
url=url, target_metadata=target_metadata, literal_binds=True) | ||
|
||
with context.begin_transaction(): | ||
context.run_migrations() | ||
|
||
|
||
def run_migrations_online(): | ||
"""Run migrations in 'online' mode. | ||
In this scenario we need to create an Engine | ||
and associate a connection with the context. | ||
""" | ||
connectable = create_engine(get_url()) | ||
|
||
with connectable.connect() as connection: | ||
context.configure( | ||
connection=connection, | ||
target_metadata=target_metadata | ||
) | ||
|
||
with context.begin_transaction(): | ||
context.run_migrations() | ||
|
||
if context.is_offline_mode(): | ||
run_migrations_offline() | ||
else: | ||
run_migrations_online() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""${message} | ||
|
||
Revision ID: ${up_revision} | ||
Revises: ${down_revision | comma,n} | ||
Create Date: ${create_date} | ||
|
||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = ${repr(up_revision)} | ||
down_revision = ${repr(down_revision)} | ||
branch_labels = ${repr(branch_labels)} | ||
depends_on = ${repr(depends_on)} | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
${imports if imports else ""} | ||
|
||
def upgrade(): | ||
${upgrades if upgrades else "pass"} | ||
|
||
|
||
def downgrade(): | ||
${downgrades if downgrades else "pass"} |
Oops, something went wrong.