Skip to content
Snippets Groups Projects
Commit 2c3acc59 authored by nimrod's avatar nimrod
Browse files

- First commit.

parents
No related branches found
No related tags found
No related merge requests found
FROM debian:latest
MAINTAINER Nimrod Adar <nimrod@shore.co.il>
RUN apt-get update && apt-get install -yf python-dev python-pip python-mysqldb
COPY ./ /opt/docker-intro/
WORKDIR /opt/docker-intro
RUN pip install -r requirements.txt
EXPOSE 5000
CMD ./trivial.py
LICENSE 0 → 100644
Copyright (c) 2015, Nimrod Adar
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Makefile 0 → 100644
build:
docker build --tag intro .
run:
docker run --publish 5000:5000 intro
pull:
docker pull mysql:5.5
rundb:
docker run --detach --publish-all --env MYSQL_ROOT_PASSWORD=qwerty123 --name mysql mysql:5.5
createdb:
echo 'create database db' | mysql -uroot -pqwerty123 --protocol tcp --port $$MYSQL_PORT
run-linked:
docker run --link mysql:mysql --publish 5000:5000 intro
docker-intro
============
A hands-on introduction to Docker.
Requirements:
- Docker
- Make
Commands: ::
make build
make run
make pull
make startdb
make run-linked
#!/usr/bin/env python
''' Trivial Eve-SQLAlchemy example. '''
# SQLAlchemy Imports
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import column_property
from sqlalchemy import (
Column,
String,
Integer,
)
# Eve imports
from eve import Eve
from eve_sqlalchemy import SQL
from eve_sqlalchemy.validation import ValidatorSQL
# Eve-SQLAlchemy imports
from eve_sqlalchemy.decorators import registerSchema
Base = declarative_base()
class People(Base):
__tablename__ = 'people'
id = Column(Integer, primary_key=True, autoincrement=True)
firstname = Column(String(80))
lastname = Column(String(120))
fullname = column_property(firstname + " " + lastname)
@classmethod
def from_tuple(cls, data):
"""Helper method to populate the db"""
return cls(firstname=data[0], lastname=data[1])
registerSchema('people')(People)
SETTINGS = {
'DEBUG': True,
'SQLALCHEMY_DATABASE_URI': 'mysql://root:qwerty123@mysql/db',
'DOMAIN': {
'people': People._eve_schema['people'],
}
}
app = Eve(auth=None, settings=SETTINGS, validator=ValidatorSQL, data=SQL)
# bind SQLAlchemy
db = app.data.driver
Base.metadata.bind = db.engine
db.Model = Base
db.create_all()
# Insert some example data in the db
test_data = [
(u'George', u'Washington'),
(u'John', u'Adams'),
(u'Thomas', u'Jefferson'),
]
if not db.session.query(People).count():
for item in test_data:
db.session.add(People.from_tuple(item))
db.session.commit()
app.run(debug=True, use_reloader=False, host='0.0.0.0')
# using reloaded will destory in-memory sqlite db
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment