Python Console(4)Deployment and Docker
>pip -V
pip 9.0.1 from /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (python 2.7)
>pip install gunicorn
>pip install greenlet
>pip install eventlet
>pip install gevent
Configuration file
>cat gunicorn.py.ini
import multiprocessing
bind = "127.0.0.1:8000"
workers = multiprocessing.cpu_count() * 2 + 1
worker_class = 'gevent'
running command
>gunicorn -c gunicorn.py.ini myconsole.wsgi
Deployment on RaspberryPi Ubuntu
>sudo apt-get install python3-picamera
>python -V
Python 2.7.9
>python3 -V
Python 3.4.2
>sudo apt-get install python3-pip
>pip3 -V
pip 1.5.6 from /usr/lib/python3/dist-packages (python 3.4)
>sudo pip3 install django
>sudo pip3 install gunicorn
>sudo pip3 install greenlet
>sudo pip3 install gevent
>sudo pip3 install eventlet
>cat gunicorn.py.ini
import multiprocessing
bind = "0.0.0.0:8000"
workers = multiprocessing.cpu_count() * 2 + 1
>gunicorn -c gunicorn.py.ini myconsole.wsgi
Configure the settings.py to solve the allowed host issue
ALLOWED_HOSTS = ['*']
It is a kind of working, but I get the wrong CSS, I was thinking I do not need care about the /static, but I have to.
Solve the Static Issue
>sudo ln -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', )
>python3 manage.py collectstatic
Still have issue
Not Found: /static/admin/css/base.css
Not Found: /static/admin/css/dashboard.css
Follow this book in details
https://docs.djangoproject.com/en/1.11/howto/static-files/deployment/
Actually after all the steps bellow, it will copy all he files to STATIC_ROOT under the URL STATIC_URL.
add the things to the urls.py
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns += staticfiles_urlpatterns()
It works well.
And I also tried to docker that application on my raspberrypi machine. in sillycat-docker
Makefile
IMAGE=sillycat/public
TAG=raspberrypi-django
NAME=raspberrypi-django
app-build:
rm -fr install/*
wget --no-check-certificate https://github.com/luohuazju/myconsole/archive/master.tar.gz -P install/
docker-context:
build: docker-context
docker build -t $(IMAGE):$(TAG) .
run:
docker run -d -p 8000:8000 --name $(NAME) $(IMAGE):$(TAG)
debug:
docker run -ti -p 8000:8000 --name $(NAME) $(IMAGE):$(TAG) /bin/bash
clean:
docker stop ${NAME}
docker rm ${NAME}
logs:
docker logs ${NAME}
publish:
docker push ${IMAGE}:${TAG}
fetch:
docker pull ${IMAGE}:${TAG}
Dockerfile
#Prepre the OS
FROM resin/rpi-raspbian:jessie
MAINTAINER Carl Luo <[email protected]>
ENV DEBIAN_FRONTEND noninteractive
RUN echo "deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi\n\
deb-src http://archive.raspbian.org/raspbian/ jessie main contrib non-free rpi\n\
" > /etc/apt/sources.list
RUN apt-get -y update
RUN apt-get install -y apt-utils
RUN apt-get -y dist-upgrade
RUN apt-get install -y build-essential gcc make
#install the software
RUN apt-get install -y python3-picamera
RUN apt-get install -y python3-dev
RUN apt-get install -y python3-pip
RUN pip3 install django
RUN pip3 install gunicorn
RUN pip3 install greenlet
RUN pip3 install gevent
RUN pip3 install eventlet
#install our django app
RUN mkdir /share/
ADD install/master.tar.gz /share/
#start the application
EXPOSE 8000
RUN mkdir -p /app/
ADD start.sh /app/
WORKDIR /app/
CMD[ "./start.sh" ]
The start.sh is also important
#!/bin/sh -ex
#start the service
cd /share/myconsole-master
ln -s /share/myconsole-master /opt/myconsole
python3 manage.py collectstatic
gunicorn -c gunicorn.py.ini myconsole.wsgi
References:
http://sillycat.iteye.com/blog/2117576
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
Python Console(4)Deployment and Docker
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326352344&siteId=291194637
Recommended
Ranking