Skip to content

Commit

Permalink
working example due to rearranging directory structure and fixing doc…
Browse files Browse the repository at this point in the history
…kerfile/docker-compose volumes to not overwrite egg
  • Loading branch information
Raj committed Jan 22, 2019
1 parent a95d0cc commit 2c2c111
Show file tree
Hide file tree
Showing 18 changed files with 244 additions and 82 deletions.
20 changes: 15 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
container_name: postgres
image: "postgres:11.1"
env_file:
- services_config/env_file
- services_config/postgres_config/env_file
networks:
- db_nw

Expand All @@ -14,14 +14,22 @@ services:
# tty: true
image: image_from_dockerfile
env_file:
- services_config/env_file
- services_config/postgres_config/env_file
volumes:
- ./volumes/src:/app
- ./volumes/testsite:/app/testsite
# - ./logs:/var/log
# - ./config:/etc/appconfig
image: image_from_dockerfile
working_dir: /app
#command: bin/pserve testsite_config/development.ini --reload
expose:
- 8000
command: /app/venv/bin/pserve /app/testsite_config/development.ini --reload
# command: >
# sh -c "virtualenv /app/venv &&
# /app/venv/bin/pip install -r /app/testsite_config/requirements.pip &&
# /app/venv/bin/pip install -e '.[testing]' &&
# /app/venv/bin/pserve /app/testsite_config/development.ini --reload"
# /app/venv/bin/pserve /app/testsite_config/development.ini --reload
networks:
- db_nw
- web_nw
Expand All @@ -30,11 +38,13 @@ services:
nginx:
image: nginx:1.13.5
ports:
- "6543:6543"
- "8000:80"
volumes:
- ./volumes/conf.d:/etc/nginx/conf.d
networks:
- web_nw
depends_on:
- pyramid_app

networks:
db_nw:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,23 @@ sqlalchemy.url = sqlite:///%(here)s/testsite.db
#sqlalchemy.pool_recycle = 3600
#sqlalchemy.pool_size = 20

# session settings
redis.sessions.secret = my_cookie_signing_secret_A2

# session cookie settings

# redis connection string as a URL
redis.sessions.url = redis://raj:thisismyreallyreallyreallylongredispassword@localhost:6379/0



# email testsite list
email_list = %(here)s/email_list.txt


POSTGRES_USER=postgres
POSTGRES_PASSWORD=testpw
POSTGRES_DB=pyramid_app_db
APP_SECRET_KEY=USE_YOUR_SECRET_KEY

[pipeline:main]
pipeline =
Expand All @@ -32,7 +43,7 @@ pipeline =
[server:main]
use = egg:Pyramid#wsgiref
host = 0.0.0.0
port = 6543
port = 8000

# Begin logging configuration

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'pyramid_tm',
'pyramid_debugtoolbar',
'pyramid_mailer',
'pyramid_redis_sessions',
'zope.sqlalchemy']

setup(name='testsite',
Expand Down
23 changes: 13 additions & 10 deletions testsite.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@ MAINTAINER Raj <[email protected]>
ENV VENV=/app
ENV PYTHONUNBUFFERED 1

RUN mkdir /config /app
COPY /services_config/requirements.pip /config/requirements.pip
#COPY /volumes/src/testsite_config/development.ini /app/development.ini
COPY /volumes/src /app
#COPY /volumes/src/testsite_config/setup.py /app/setup.py
RUN mkdir /app
COPY /volumes/testsite /app/testsite
COPY /services_config/pyramid_app_config/setup.py /app/setup.py
COPY /services_config/pyramid_app_config/development.ini /app/testsite_config/development.ini
COPY /services_config/pyramid_app_config/requirements.pip /app/testsite_config/requirements.pip

RUN apt-get -yqq update && apt-get install -yqq python python-dev python-pip python-virtualenv
RUN mkdir /app/venv
RUN echo "hello"

RUN virtualenv /app/venv
RUN ls /app/venv
#RUN source /app/venv/bin/activate
RUN /app/venv/bin/pip install -r /config/requirements.pip
RUN /app/venv/bin/pip install -e /app/testsite_config
RUN /app/venv/bin/pserve /app/testsite_config/development.ini --reload
RUN source /app/venv/bin/activate
RUN /app/venv/bin/pip install -r /app/testsite_config/requirements.pip
# RUN /app/venv/bin/pip install -e /app/testsite_config
RUN /app/venv/bin/pip install -e "./app[testing]"
# RUN /app/venv/bin/pserve /app/testsite_config/development.ini --reload
WORKDIR /app
# RUN source /app/venv/bin/activate
RUN which python
RUN ls -a

#RUN /app/venv/bin/pserve /app/testsite_config/development.ini --reload
#CMD ["python", "app.py"]
4 changes: 2 additions & 2 deletions volumes/conf.d/testsite.conf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
server {

listen 80;
server_name testsite.test;
server_name testsite.org;
charset utf-8;

location / {
proxy_pass http://testsite:8000;
proxy_pass http://pyramid_app:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand Down
18 changes: 0 additions & 18 deletions volumes/src/testsite/app.py

This file was deleted.

24 changes: 0 additions & 24 deletions volumes/src/testsite/database.py

This file was deleted.

8 changes: 0 additions & 8 deletions volumes/src/testsite/forms.py

This file was deleted.

13 changes: 0 additions & 13 deletions volumes/src/testsite/models.py

This file was deleted.

53 changes: 53 additions & 0 deletions volumes/testsite/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from pyramid.config import Configurator

from sqlalchemy import engine_from_config
from testsite.models import initialize_sql
from pyramid.registry import Registry
#from pyramid_jinja2 import _get_or_build_default_environment # ?#?#?
from pyramid.response import Response
from pyramid.authentication import AuthTktAuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy

from pyramid_redis_sessions import session_factory_from_settings
#from pyramid_beaker import session_factory_from_settings
#from pyramid.session import UnencryptedCookieSessionFactoryConfig
#from pyramid_redis_sessions import session_factory_from_settings
from testsite.security import groupfinder

registry = Registry()


def hello_world(request):
print('Incoming request')
return Response('<body><h1>Hello World!</h1></body>')


def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
initialize_sql(engine)

session_factory = session_factory_from_settings(settings) #redis
# session_factory = UnencryptedCookieSessionFactoryConfig('itsaseekreet')

authn_policy = AuthTktAuthenticationPolicy(secret='s0secret',
callback=groupfinder)
authz_policy = ACLAuthorizationPolicy()

config = Configurator(
settings=settings,
root_factory='testsite.security.RootFactory',
authentication_policy=authn_policy,
authorization_policy=authz_policy,
session_factory=session_factory,
)
# jinja_env = _get_or_build_default_environment(config.registry) # ?#?#?
#config.set_request_factory(RequestWithUserAttribute)

config.add_route('hello', '/')
config.add_view(hello_world, route_name='hello')


config.scan()
return config.make_wsgi_app()
Binary file added volumes/testsite/__init__.pyc
Binary file not shown.
96 changes: 96 additions & 0 deletions volumes/testsite/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import transaction
import datetime

from sqlalchemy import Column, Table, ForeignKey
from sqlalchemy import Integer, Unicode, Date, DateTime, Boolean
from sqlalchemy import event, func
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import scoped_session, sessionmaker, synonym
from sqlalchemy.orm import relationship, backref, relation
from sqlalchemy.orm import configure_mappers, validates
from zope.sqlalchemy import ZopeTransactionExtension
from pyramid.security import Everyone, Authenticated, Allow

from sqlalchemy import Column, Integer, String
from sqlalchemy.types import DateTime


class BaseModel(object):
def __json__(self, request=None):
## creates and returns a dict object
props = {}
# for key in self.__dict__:
# if not key.startswith(('_', '_sa_')):
# obj = getattr(self, key)
for key in self.__table__.columns:
if not key.name.startswith(('_', '_sa_')):
obj = getattr(self, key.name)
if isinstance(obj, datetime.datewhich):
props[key.name] = obj.isoformat()
else:
props[key.name] = obj
return props


DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
Base = declarative_base(cls=BaseModel)


class Signups(Base):
"""
Example Signups table
"""
__tablename__ = 'signups'
id = Column(Integer, primary_key=True)
name = Column(String(256))
email = Column(String(256), unique=True)
date_signed_up = Column(DateTime())


##########################################
def initialize_sql(engine): ##
DBSession.configure(bind=engine) ##
Base.metadata.bind = engine ##
Base.metadata.create_all(engine) ##
##########################################




class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
title = Column(Unicode(255))
first_name = Column(Unicode(255))
middle_names = Column(Unicode(255))
last_name = Column(Unicode(255))
email = Column(Unicode(255), unique=True, nullable=False)
username = Column(Unicode(255))
sex = Column(Integer, default=0)
dob = Column(Date)
marital_status = Column(Unicode(255))
currenttown = Column(Unicode(255))
hometown = Column(Unicode(255))
tz = Column(Unicode(255), nullable=False)
join_date = Column(DateTime, default=datetime.datetime.utcnow)

confirm_status = Column(Integer, nullable=False)
_confirm_code = Column(Unicode(16))
_password = Column(Unicode(60), nullable=False)

# unconfirmed = 0
# confirmed = 1
# invited = 2

#########################################################
# Hashing the password ####################################
def _get_password(self): #### ####
return self._password # ## # ####
def _set_password(self, password): #### ####
self._password = hash_password(password) ####
####
password = property(_get_password, _set_password) ####
password = synonym('_password', descriptor=password) ####
###########################################################
#########################################################
Binary file added volumes/testsite/models.pyc
Binary file not shown.
Loading

0 comments on commit 2c2c111

Please sign in to comment.