PythonConsole(4)DeploymentandDocker
>pip-V
pip9.0.1from/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages(python2.7)
>pipinstallgunicorn
>pipinstallgreenlet
>pipinstalleventlet
>pipinstallgevent
Configurationfile
>catgunicorn.py.ini
importmultiprocessing
bind="127.0.0.1:8000"
workers=multiprocessing.cpu_count()*2+1
worker_class='gevent'
runningcommand
>gunicorn-cgunicorn.py.inimyconsole.wsgi
DeploymentonRaspberryPiUbuntu
>sudoapt-getinstallpython3-picamera
>python-V
Python2.7.9
>python3-V
Python3.4.2
>sudoapt-getinstallpython3-pip
>pip3-V
pip1.5.6from/usr/lib/python3/dist-packages(python3.4)
>sudopip3installdjango
>sudopip3installgunicorn
>sudopip3installgreenlet
>sudopip3installgevent
>sudopip3installeventlet
>catgunicorn.py.ini
importmultiprocessing
bind="0.0.0.0:8000"
workers=multiprocessing.cpu_count()*2+1
>gunicorn-cgunicorn.py.inimyconsole.wsgi
Configurethesettings.pytosolvetheallowedhostissue
ALLOWED_HOSTS=['*']
Itisakindofworking,butIgetthewrongCSS,IwasthinkingIdonotneedcareaboutthe/static,butIhaveto.
SolvetheStaticIssue
>sudoln-s/home/carl/work/myconsole/opt/myconsole
myconsole/settings.py
STATIC_URL='/static/‘
STATIC_ROOT='/opt/myconsole/static/'
STATICFILES_FINDERS=('django.contrib.staticfiles.finders.AppDirectoriesFinder','django.contrib.staticfiles.finders.FileSystemFinder',)
>python3manage.pycollectstatic
Stillhaveissue
NotFound:/static/admin/css/base.css
NotFound:/static/admin/css/dashboard.css
Followthisbookindetails
https://docs.djangoproject.com/en/1.11/howto/static-files/deployment/
Actuallyafterallthestepsbellow,itwillcopyallhefilestoSTATIC_ROOTundertheURLSTATIC_URL.
addthethingstotheurls.py
fromdjango.contrib.staticfiles.urlsimportstaticfiles_urlpatterns
urlpatterns+=staticfiles_urlpatterns()
Itworkswell.
AndIalsotriedtodockerthatapplicationonmyraspberrypimachine.insillycat-docker
Makefile
IMAGE=sillycat/public
TAG=raspberrypi-django
NAME=raspberrypi-django
app-build:
rm-frinstall/*
wget--no-check-certificatehttps://github.com/luohuazju/myconsole/archive/master.tar.gz-Pinstall/
docker-context:
build:docker-context
dockerbuild-t$(IMAGE):$(TAG).
run:
dockerrun-d-p8000:8000--name$(NAME)$(IMAGE):$(TAG)
debug:
dockerrun-ti-p8000:8000--name$(NAME)$(IMAGE):$(TAG)/bin/bash
clean:
dockerstop${NAME}
dockerrm${NAME}
logs:
dockerlogs${NAME}
publish:
dockerpush${IMAGE}:${TAG}
fetch:
dockerpull${IMAGE}:${TAG}
Dockerfile
#PrepretheOS
FROMresin/rpi-raspbian:jessie
MAINTAINERCarlLuo<[email protected]>
ENVDEBIAN_FRONTENDnoninteractive
RUNecho"debhttp://mirrordirector.raspbian.org/raspbian/jessiemaincontribnon-freerpi\n\
deb-srchttp://archive.raspbian.org/raspbian/jessiemaincontribnon-freerpi\n\
">/etc/apt/sources.list
RUNapt-get-yupdate
RUNapt-getinstall-yapt-utils
RUNapt-get-ydist-upgrade
RUNapt-getinstall-ybuild-essentialgccmake
#installthesoftware
RUNapt-getinstall-ypython3-picamera
RUNapt-getinstall-ypython3-dev
RUNapt-getinstall-ypython3-pip
RUNpip3installdjango
RUNpip3installgunicorn
RUNpip3installgreenlet
RUNpip3installgevent
RUNpip3installeventlet
#installourdjangoapp
RUNmkdir/share/
ADDinstall/master.tar.gz/share/
#starttheapplication
EXPOSE8000
RUNmkdir-p/app/
ADDstart.sh/app/
WORKDIR/app/
CMD["./start.sh"]
Thestart.shisalsoimportant
#!/bin/sh-ex
#starttheservice
cd/share/myconsole-master
ln-s/share/myconsole-master/opt/myconsole
python3manage.pycollectstatic
gunicorn-cgunicorn.py.inimyconsole.wsgi
References:
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/gunicorn/
http://stackoverflow.com/questions/2751227/how-to-download-source-in-zip-format-from-github
https://www.raspberrypi.org/documentation/linux/software/python.md
http://stackoverflow.com/questions/16676314/should-server-ip-address-be-in-allowed-hosts-django-setting