diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a4881ba --- /dev/null +++ b/.dockerignore @@ -0,0 +1,195 @@ +# Handle here so .docker doesn't pick these files up for a build . + +# Docs +/LICENSE +/README.md +# Heroku +/Procfile +/runtime.txt +# Deployment, CI +/circle.yml +/Dockerfile +# Ignores' +/.gitignore +/.dockerignore +# Dev +*/db.sqlite3 + + + + +# Created by .ignore support plugin (hsz.mobi) +### Python template +# 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 +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# IPython Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# dotenv +.env + +# virtualenv +venv/ +ENV/ + +# Spyder project settings +.spyderproject + +# Rope project settings +.ropeproject +### OSX template +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk +### VirtualEnv template +# Virtualenv +# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ +[Bb]in +[Ii]nclude +[Ll]ib +[Ll]ib64 +[Ll]ocal +[Ss]cripts +pyvenv.cfg +.venv +pip-selfcheck.json +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/workspace.xml +.idea/tasks.xml +.idea/dictionaries +.idea/vcs.xml +.idea/jsLibraryMappings.xml + +# Sensitive or high-churn files: +.idea/dataSources.ids +.idea/dataSources.xml +.idea/dataSources.local.xml +.idea/sqlDataSources.xml +.idea/dynamic.xml +.idea/uiDesigner.xml + +# Gradle: +.idea/gradle.xml +.idea/libraries + +# Mongo Explorer plugin: +.idea/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +/src/staticfiles/ diff --git a/.gitignore b/.gitignore index 8046ca9..cfb55ce 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ + +*/db.sqlite3 + + + +### START PRE GENERATED IGNORE TEMPLATE # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] @@ -88,4 +94,49 @@ ENV/ # Rope project settings .ropeproject /db.sqlite3 -/src/db.sqlite3 +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/workspace.xml +.idea/tasks.xml +.idea/dictionaries +.idea/vcs.xml +.idea/jsLibraryMappings.xml + +# Sensitive or high-churn files: +.idea/dataSources.ids +.idea/dataSources.xml +.idea/dataSources.local.xml +.idea/sqlDataSources.xml +.idea/dynamic.xml +.idea/uiDesigner.xml + +# Gradle: +.idea/gradle.xml +.idea/libraries + +# Mongo Explorer plugin: +.idea/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +/src/staticfiles/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d9b59db --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +FROM python:3.6-alpine + +ENV INSTALL_PATH=/ango/ \ + DJANGO_SETTINGS_MODULE=ango.settings.prod \ + SECRET_KEY=000000000000000 \ + DATABASE_URL=postgres://admin:randomTestPassword@postgres:5432/admin \ + ALLOWED_HOSTS=['*'] + +RUN mkdir $INSTALL_PATH + +WORKDIR $INSTALL_PATH + +COPY ./deps/ $INSTALL_PATH/deps/ + +RUN apk add --no-cache --virtual .build-deps \ + build-base postgresql-dev libffi-dev \ + && pip3 install -r $INSTALL_PATH/deps/prod.txt \ + && find /usr/local \ + \( -type d -a -name test -o -name tests \) \ + -o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \ + -exec rm -rf '{}' + \ + && runDeps="$( \ + scanelf --needed --nobanner --recursive /usr/local \ + | awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \ + | sort -u \ + | xargs -r apk info --installed \ + | sort -u \ + )" \ + && apk add --virtual .rundeps $runDeps \ + && apk del .build-deps + +COPY ./src $INSTALL_PATH + +COPY ./deps/nginx/ /etc/nginx/vhost.d/ + + +RUN python3 manage.py collectstatic --no-input + +VOLUME ["/ango/staticfiles", "/etc/nginx/vhost.d"] + +EXPOSE 8000 + +ENTRYPOINT ["/usr/local/bin/python3", "-u"] \ No newline at end of file diff --git a/README.md b/README.md index 934148d..c2053f0 100644 --- a/README.md +++ b/README.md @@ -8,15 +8,40 @@ https://github.com/ncrmro/reango * Relay Support * User Registration/Sign up using JWT +* Heroku or Docker Deployment +* Docker Deployment has nginx staticfile proxy, letsencrypt csupport commming soon. ## Quick start: -source ~/.virtualenvs/bin/activate +source ~/.virtualenvs/ango/bin/activate pip3 install -r ./deps/dev.txt ## Prod + +### Docker +Sample docker-compose.yml and dockerfile are enough to test out the nginx/database/staticfiles + +Base image is alpine and after dependencies and staticfiles weighs in at 130.5mb + +You can tell if nginx is picking up the default vhost config by changing if static files are logged in the /deps/nginx/default_conf + + +Docker deployment should not be considered secure yet until the docker socket is moved to it's own container for nginx-gen and letsencrypt support.. +Wait for the docker-compose.prod.yml + + +#### Docker Compose +``` +docker-compose build +docker-compose up +docker-compose run ango manage.py migrate +docker-compose run ango manage.py createsuperuser + +``` + +### Heroku A fresh dyno will need the following ran `heroku run --app APP bash` `python manage.py migrate` diff --git a/deps/nginx/default_location b/deps/nginx/default_location new file mode 100644 index 0000000..96702fe --- /dev/null +++ b/deps/nginx/default_location @@ -0,0 +1,5 @@ +location /static { + access_log off; + log_not_found off; + alias /ango/staticfiles; +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b180561 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,36 @@ +version: '2' +services: + nginx-proxy: + image: jwilder/nginx-proxy + container_name: nginx-proxy + ports: + - "80:80" + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + volumes_from: + - ango:ro + + postgres: + image: kiasaki/alpine-postgres:9.5 + container_name: postgres + environment: + - POSTGRES_USER=admin + - POSTGRES_PASSWORD=randomTestPassword + + ango: + build: . + container_name: ango + command: "/usr/local/bin/waitress-serve --host=0.0.0.0 --port=8000 ango.wsgi:application" + image: ncrmro/ango + volumes: + - /ango/staticfiles + - ./deps/nginx:/etc/nginx/vhost.d:ro + environment: + - VIRTUAL_HOST=192.168.99.101 + - VIRTUAL_PORT=8000 + - DJANGO_SETTINGS_MODULE=ango.settings.prod + - SECRET_KEY='000000000000000' + - DATABASE_URL=postgres://admin:randomTestPassword@postgres:5432/admin + - ALLOWED_HOSTS=['*'] + depends_on: + - postgres \ No newline at end of file diff --git a/src/ango/settings/dev.py b/src/ango/settings/dev.py index 011815f..9cae410 100644 --- a/src/ango/settings/dev.py +++ b/src/ango/settings/dev.py @@ -2,6 +2,9 @@ SECRET_KEY = 'ojk@86z9*$zyuhge#3)p*%$q0psoo2lq*tv9jw90#1eezcl^y2' +# Must mention ALLOWED_HOSTS in production! +ALLOWED_HOSTS = ['*'] + DEBUG = True MIDDLEWARE.remove('django.middleware.csrf.CsrfViewMiddleware') diff --git a/src/ango/settings/prod.py b/src/ango/settings/prod.py index 5e22015..ab84484 100644 --- a/src/ango/settings/prod.py +++ b/src/ango/settings/prod.py @@ -12,12 +12,11 @@ SECRET_KEY = env('SECRET_KEY') +ALLOWED_HOSTS = env('ALLOWED_HOSTS') + DEBUG = False TEMPLATE_DEBUG = False -# Must mention ALLOWED_HOSTS in production! -ALLOWED_HOSTS = ['*'] - DATABASES = { # Raises ImproperlyConfigured exception if DATABASE_URL not in # os.environ