Skip to content

Commit

Permalink
[add] tests inside docker and run before start
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-web committed Oct 30, 2017
1 parent 6ab78d4 commit d7dbb57
Show file tree
Hide file tree
Showing 18 changed files with 153 additions and 94 deletions.
7 changes: 5 additions & 2 deletions app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ FROM python:3.6

MAINTAINER Stanislav WEB "[email protected]"

ARG SERVERMODE

COPY . /app

WORKDIR /app

# Install requirements
RUN pip install -r requirements.txt
RUN pip install -r requirements-dev.txt
RUN chmod +x server.py

EXPOSE 5001
EXPOSE 5000

# Set the default command to execute
ENTRYPOINT ["/usr/local/bin/gunicorn", "--config", "./config.py", "server", "--reload"]
ENTRYPOINT ["sh", "./entrypoint.sh", "$SERVERMODE"]
5 changes: 1 addition & 4 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
from multiprocessing import cpu_count

SERVER_HOST = os.getenv('SERVER_HOST', '0.0.0.0')
SERVER_PORT = int(os.getenv('SERVER_PORT', '5001'))
APPLICATION = os.getenv('APPLICATION', 'PyRuc:DEVELOPMENT')

print('\033[32m'+"{app}".format(app=APPLICATION))
SERVER_PORT = int(os.getenv('SERVER_PORT', '5000'))

#
# Server socket
Expand Down
13 changes: 13 additions & 0 deletions app/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

APPLICATION="${APPLICATION}"
printf '\033[32m%s\n' "${APPLICATION}"

if [ $@ == '--reload' ]
then
/usr/local/bin/gunicorn --config ./config.py server "$@"
else
/usr/local/bin/coverage run setup.py test
/usr/local/bin/coverage report
/usr/local/bin/gunicorn --config ./config.py server
fi
27 changes: 22 additions & 5 deletions app/env/development.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Application

APPLICATION=PyRuc:DEVELOPMENT
APPLICATION_LOG_LEVEL=20
APPLICATION_REG_CODE_TTL=3600
Expand All @@ -8,28 +10,43 @@ APPLICATION_LIMIT_AUTH=100000 per day
APPLICATION_LIMIT_RESTORE=100000 per day
APPLICATION_LIMIT_PER_SEC=500000 per second
APPLICATION_LIMIT_PER_MIN=5000000 per minute
APPLICATION_LIMIT_STORAGE_URI=redis://d70e25e734dedbd1ca52fe81459b23af88f82819d06a823e07a79a86955e8ac8@redis:6379
APPLICATION_LIMIT_STORAGE_URI=redis://redis_db:6379

# Authentication

JWT_TOKEN_EXP_DELTA_SECONDS=60
JWT_TOKEN_SECRET=secret
JWT_TOKEN_ALGORITHM=HS256

# Server

SERVER_PROTOCOL=http://
SERVER_HOST=0.0.0.0
SERVER_PORT=5001
SERVER_PORT=5000

# Users storage

REDIS_HOST=redis
REDIS_HOST=redis_db
REDIS_PORT=6379
REDIS_DBNO=2
REDIS_PASSWORD=d70e25e734dedbd1ca52fe81459b23af88f82819d06a823e07a79a86955e8ac8
REDIS_PASSWORD=
REDIS_SOCKET_TIMEOUT=10
REDIS_SOCKET_CONNECT_TIMEOUT=3
REDIS_MAX_CONNECTIONS=3

# Sms notifier

TWILIO_ACCOUNT_SID=ACfba6742794f57556d26f2362be925e03
TWILIO_AUTH_TOKEN=5591456e24738c0c45277d1326c58f20
TWILIO_SEND_FROM=+15005550006

# Logs server

LOGSTASH_NODENAME=pyruс
LOGSTASH_PORT=6000
LOGSTASH_HOST=127.0.0.1
LOGSTASH_HOST=127.0.0.1

# Test params

TEST_PHONE_NO=15005550006
TEST_EXPECTED_CTYPE=application/json
27 changes: 22 additions & 5 deletions app/env/production.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Application

APPLICATION=PyRuc:PRODUCTION
APPLICATION_LOG_LEVEL=50
APPLICATION_REG_CODE_TTL=300
Expand All @@ -8,28 +10,43 @@ APPLICATION_LIMIT_AUTH=3000 per hour
APPLICATION_LIMIT_RESTORE=6 per hour
APPLICATION_LIMIT_PER_SEC=1 per second
APPLICATION_LIMIT_PER_MIN=10000 per minute
APPLICATION_LIMIT_STORAGE_URI=redis://d70e25e734dedbd1ca52fe81459b23af88f82819d06a823e07a79a86955e8ac8@redis:6379
APPLICATION_LIMIT_STORAGE_URI=redis://d70e25e734dedbd1ca52fe81459b23af88f82819d06a823e07a79a86955e8ac8@redis_db:6379

# Authentication

JWT_TOKEN_EXP_DELTA_SECONDS=604800
JWT_TOKEN_SECRET=GNmcG5ddDvwjKqTaCcsfpW
JWT_TOKEN_ALGORITHM=HS256

# Server

SERVER_PROTOCOL=http://
SERVER_HOST=0.0.0.0
SERVER_PORT=5001
SERVER_PORT=5000

REDIS_HOST=redis
# Users storage

REDIS_HOST=redis_db
REDIS_PORT=6379
REDIS_PASSWORD=d70e25e734dedbd1ca52fe81459b23af88f82819d06a823e07a79a86955e8ac8
REDIS_DBNO=1
REDIS_PASSWORD=d70e25e734dedbd1ca52fe81459b23af88f82819d06a823e07a79a86955e8ac8
REDIS_SOCKET_TIMEOUT=10
REDIS_SOCKET_CONNECT_TIMEOUT=3
REDIS_MAX_CONNECTIONS=3

# Sms notifier

TWILIO_ACCOUNT_SID=ACa988afd5f42c8a4a9b21ddbc2f77b915
TWILIO_AUTH_TOKEN=85d1cd8958c709634941caa2d3d7bb87
TWILIO_SEND_FROM=+15005550006

# Logs server

LOGSTASH_NODENAME=pyruс
LOGSTASH_PORT=6000
LOGSTASH_HOST=127.0.0.1
LOGSTASH_HOST=127.0.0.1

# Test params

TEST_PHONE_NO=15005550006
TEST_EXPECTED_CTYPE=application/json
3 changes: 1 addition & 2 deletions app/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
coverage==4.4.1
coveralls==1.2.0
unittest2py3k==0.5.1
python-dotenv==0.7.1
unittest2py3k==0.5.1
5 changes: 4 additions & 1 deletion app/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
from setuptools import setup, find_packages

VERSION = '1.0.0'
LONG_DESCRIPTION = open('../README.md').read()
try:
LONG_DESCRIPTION = open('../README.md').read()
except FileNotFoundError:
LONG_DESCRIPTION = 'Docker build images in progress...'

setup(name='PyRuc',

Expand Down
2 changes: 1 addition & 1 deletion app/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
APPLICATION_LIMIT_RESTORE = os.getenv('APPLICATION_LIMIT_RESTORE', '100000 per day')
APPLICATION_LIMIT_PER_SEC = os.getenv('APPLICATION_LIMIT_PER_SEC', '100000 per second')
APPLICATION_LIMIT_PER_MIN = os.getenv('APPLICATION_LIMIT_PER_MIN', '100000 per minute')
APPLICATION_LIMIT_STORAGE_URI = os.getenv('APPLICATION_LIMIT_STORAGE_URI', 'redis://127.0.0.1:6379')
APPLICATION_LIMIT_STORAGE_URI = os.getenv('APPLICATION_LIMIT_STORAGE_URI', 'redis://redis_db:6379')
LOGSTASH_HOST = os.getenv('LOGSTASH_HOST', '127.0.0.1')
LOGSTASH_PORT = os.getenv('LOGSTASH_PORT', 6000)
40 changes: 0 additions & 40 deletions app/tests/.env

This file was deleted.

5 changes: 0 additions & 5 deletions app/tests/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@
import sys

from http import HTTPStatus
from dotenv import load_dotenv
from src import application
from src.modules.mod_authentication.services.db.redis import RedisRepository


dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
load_dotenv(dotenv_path, verbose=True)


class DevNull(object):
def write(self, data):
pass
Expand Down
4 changes: 0 additions & 4 deletions app/tests/test_invalid_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@
import sys

from http import HTTPStatus
from dotenv import load_dotenv
from src import application
from src.modules.mod_registration.services.db.redis import RedisRepository

dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
load_dotenv(dotenv_path, verbose=True)


class DevNull(object):
def write(self, data):
Expand Down
5 changes: 0 additions & 5 deletions app/tests/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@
import sys

from http import HTTPStatus
from dotenv import load_dotenv
from src import application
from src.modules.mod_registration.services.db.redis import RedisRepository


dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
load_dotenv(dotenv_path, verbose=True)


class DevNull(object):
def write(self, data):
pass
Expand Down
5 changes: 0 additions & 5 deletions app/tests/test_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@
import sys

from http import HTTPStatus
from dotenv import load_dotenv
from src import application
from src.modules.mod_restore.services.db.redis import RedisRepository


dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
load_dotenv(dotenv_path, verbose=True)


class DevNull(object):
def write(self, data):
pass
Expand Down
22 changes: 14 additions & 8 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
version: "3.3"
services:
app:
build: ./app
build:
context: ./app
args:
SERVERMODE : ""
restart: always
container_name: app
env_file:
- ./app/env/development.env
volumes:
- ./app:/app
links:
- redis
- redis_db
ports:
- "5001:5001"
redis:
build: ./redis
- "5000:5000"
redis_db:
build:
context: ./redis
args:
ENVMODE : dev
restart: on-failure
container_name: redis
container_name: redis_db
volumes:
- ./redis/config/redis.conf:/usr/local/etc/redis/redis.conf
- ./redis/config/redis-dev.conf:/usr/local/etc/redis/redis.conf
- ./redis/data:/var/lib/redis
ports:
- "6379:6379"
- "6379:6379"
18 changes: 12 additions & 6 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
version: "3.3"
services:
app:
build: ./app
build:
context: ./app
args:
SERVERMODE : "--reload"
restart: always
container_name: app
env_file:
- ./app/env/production.env
volumes:
- ./app:/app
links:
- redis
- redis_db
ports:
- "5000:5000"
redis:
build: ./redis
redis_db:
build:
context: ./redis
args:
ENVMODE : prod
restart: always
container_name: redis
container_name: redis_db
volumes:
- ./redis/config/redis.conf:/usr/local/etc/redis/redis.conf
- ./redis/config/redis-prod.conf:/usr/local/etc/redis/redis.conf
- ./redis/data:/var/lib/redis
ports:
- "6379:6379"
4 changes: 3 additions & 1 deletion redis/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ MAINTAINER Stanislav WEB "[email protected]"
# or UNIX socket.
#################################################

COPY ./config/redis.conf /usr/local/etc/redis/redis.conf
ARG ENVMODE

COPY ./config/redis-$ENVMODE.conf /usr/local/etc/redis/redis.conf
EXPOSE 6379
CMD [ "redis-server", "/usr/local/etc/redis/redis.conf"]
Loading

0 comments on commit d7dbb57

Please sign in to comment.