-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
itiel
authored and
itiel
committed
Mar 18, 2017
0 parents
commit c616166
Showing
14 changed files
with
192 additions
and
0 deletions.
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 @@ | ||
SANIC_LOGO="OVERRIDE LOGO USING CONFIG" |
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,66 @@ | ||
#Me | ||
.github | ||
.idea | ||
venv | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*,cover | ||
.hypothesis/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# pyenv python configuration file | ||
.python-version |
Empty file.
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 @@ | ||
FROM python:3.6-onbuild |
Empty file.
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 @@ | ||
sanic |
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 @@ | ||
import os | ||
|
||
from sanic import Sanic | ||
from sanic.response import json | ||
|
||
from app.utils.helper import hello_world | ||
|
||
SANIC_PREFIX = "SANIC_" | ||
|
||
app = Sanic() | ||
|
||
|
||
@app.route("/hello-world") | ||
async def test(request): | ||
return json(hello_world()) | ||
|
||
|
||
app.static('/static', './static') # while in docker files from static will be served by ngnix | ||
if __name__ == "__main__": | ||
for k, v in os.environ.items(): | ||
if k.startswith(SANIC_PREFIX): | ||
_, config_key = k.split(SANIC_PREFIX, 1) | ||
app.config[config_key] = v | ||
app.run(host="0.0.0.0", port=8000, debug=True) |
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,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Hello World</title> | ||
</head> | ||
<body> | ||
SANIC HTML - HELLO WORLD :) | ||
</body> | ||
</html> |
Empty file.
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,2 @@ | ||
def hello_world(): | ||
return {"hello": "world"} |
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,22 @@ | ||
app: | ||
restart: always | ||
build: ./app | ||
expose: | ||
- "8000" | ||
volumes: | ||
- /usr/src/app/static | ||
env_file: .env | ||
command: bash -c "cd /usr/src && APP_SETTING=.env python -m app.server" | ||
|
||
nginx: | ||
restart: always | ||
build: ./nginx/ | ||
ports: | ||
- "80:80" | ||
volumes: | ||
- /www/static | ||
volumes_from: | ||
- app | ||
links: | ||
- app:app | ||
|
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,3 @@ | ||
FROM tutum/nginx | ||
RUN rm /etc/nginx/sites-enabled/default | ||
ADD sites-enabled/ /etc/nginx/sites-enabled |
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,17 @@ | ||
server { | ||
|
||
listen 80; | ||
server_name example.org; | ||
charset utf-8; | ||
|
||
location /static { | ||
alias /usr/src/app/static/; | ||
} | ||
|
||
location / { | ||
proxy_pass http://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; | ||
} | ||
} |
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,45 @@ | ||
# Sanic & Nginx & docker-compose example | ||
# About | ||
Simple and easy to use skelton-project using [Sanic] behined [nginx]. | ||
|
||
Using docker and docker-compose to orchestrate everything. | ||
|
||
The app is based on the (great) blog-post for flask: | ||
https://realpython.com/blog/python/dockerizing-flask-with-compose-and-machine-from-localhost-to-the-cloud/ | ||
|
||
# How to run? | ||
- git clone the project | ||
- Start a new docker-machine: | ||
`docker-machine create -d virtualbox sanic;` | ||
- Attach to the machine: | ||
`eval "$(docker-machine env sanic)"` | ||
- Build the containers (This will take a while for the first time!): | ||
`docker-compose build` | ||
- Create and start containers: | ||
`docker-compose up -d` | ||
|
||
## Ok what now? | ||
- Use `docker-machine ip sanic` to get the machine IP | ||
- Go to `MACHINE-IP/hello-world` or `MACHINE-IP/static/index.html` and validate everything worked. | ||
- That's It! | ||
|
||
## Features: | ||
- /static/* files are served using the nginx. | ||
- Use the .env file to override or add config values (i override the logo): | ||
- Just add SANIC_ prefix before var name. | ||
|
||
### Development | ||
|
||
Want to contribute? Great! | ||
Feel free to open PR/Issue :) | ||
|
||
License | ||
---- | ||
|
||
MIT - **Free Software, Hell Yeah!** | ||
|
||
[//]: #URLs | ||
|
||
[sanic]: <https://github.com/channelcat/sanic> | ||
[nginx]: <https://www.nginx.com/resources/wiki/> | ||
|