Skip to content
This repository has been archived by the owner on Aug 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #13 from ncrmro/dev
Browse files Browse the repository at this point in the history
Adds base docker support
  • Loading branch information
ncrmro authored Dec 22, 2016
2 parents c33fd38 + 2df9cf3 commit 1698437
Show file tree
Hide file tree
Showing 8 changed files with 362 additions and 5 deletions.
195 changes: 195 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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/
53 changes: 52 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@

*/db.sqlite3



### START PRE GENERATED IGNORE TEMPLATE
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -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/
43 changes: 43 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
5 changes: 5 additions & 0 deletions deps/nginx/default_location
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
location /static {
access_log off;
log_not_found off;
alias /ango/staticfiles;
}
36 changes: 36 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions src/ango/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Loading

0 comments on commit 1698437

Please sign in to comment.