|
|
@@ -0,0 +1,88 @@
|
|
|
+# Deploy Django Application ( Non Dockerize )
|
|
|
+
|
|
|
+To deploy your Django Application in Porter. You need to tweak something on your Django Application.
|
|
|
+
|
|
|
+> 📘 Prerequisites
|
|
|
+> - Django Application
|
|
|
+> - Docker Registry Integrate on your account ( Work only on ACR, GCR, DOCR )
|
|
|
+
|
|
|
+
|
|
|
+## Prepare Django Application
|
|
|
+
|
|
|
+1. Install django-allow-cidr ( A Django Middleware to enable use of CIDR IP ranges in ALLOWED_HOSTS )
|
|
|
+ ```sh
|
|
|
+ pip install django-allow-cidr
|
|
|
+ ```
|
|
|
+2. Go to Django Settings and add os.environ.get in allowed host.
|
|
|
+ ```python
|
|
|
+ ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS", default='127.0.0.1').split(" ")
|
|
|
+ ```
|
|
|
+3. Add this below allowed host. Put CIDR accordning to the K8s kubelet CIDR
|
|
|
+ ```python
|
|
|
+ ALLOWED_CIDR_NETS = os.environ.get("ALLOWED_CIDR_NETS", default='10.0.0.0/8').split(" ")
|
|
|
+ ```
|
|
|
+4. Add django-allow-cidr middleware on the top of django middleware
|
|
|
+ ```python
|
|
|
+ MIDDLEWARE = [
|
|
|
+ 'allow_cidr.middleware.AllowCIDRMiddleware',
|
|
|
+ #'django.middleware.security.SecurityMiddleware',
|
|
|
+ ]
|
|
|
+ ```
|
|
|
+5. Add Gunicorn
|
|
|
+ ```sh
|
|
|
+ pip install gunicorn
|
|
|
+ ```
|
|
|
+6. Add static folder then put your html and css files. Locate static url settings and add static file dirs below
|
|
|
+ ```python
|
|
|
+ STATICFILES_DIRS = (
|
|
|
+ os.path.join(BASE_DIR, 'static'),
|
|
|
+ )
|
|
|
+ STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
|
|
+ ```
|
|
|
+7. Add Procfile file and add this
|
|
|
+ ```
|
|
|
+ web: gunicorn <project-name>.wsgi -b 0.0.0.0:8989 --timeout 120 (ex. web: gunicorn djangosample.wsgi -b 0.0.0.0:8989 --timeout 120 )
|
|
|
+ ```
|
|
|
+8. Then pip freeze requirements
|
|
|
+ ```sh
|
|
|
+ pip freeze > requirements.txt
|
|
|
+ ```
|
|
|
+ Reference:
|
|
|
+ https://github.com/jimcru21/porter-sample-django-non-docker
|
|
|
+
|
|
|
+## Deploy Django in Porter
|
|
|
+
|
|
|
+1. Click Web Service then Launch Template
|
|
|
+2. Name your application. ex. django-sample
|
|
|
+
|
|
|
+ 
|
|
|
+
|
|
|
+3. In Deployment Method. Connect git repo. After that, select repo. ( ex. porter-sample-django-non-docker )
|
|
|
+
|
|
|
+ 
|
|
|
+
|
|
|
+4. Click Main then continue
|
|
|
+
|
|
|
+ 
|
|
|
+
|
|
|
+ 
|
|
|
+
|
|
|
+5. Click web then choose an image destination ( ex. mine is aws (see image) )
|
|
|
+
|
|
|
+ 
|
|
|
+
|
|
|
+ 
|
|
|
+
|
|
|
+6. Then in Destination, just leave it default.
|
|
|
+7. In Additional settings, especify container port that you use in gunicorn in Procfile ( ex. 8989).
|
|
|
+ You can configure your own domain, click Configure Custom Domain then put your desire domain name (im using default porter domain)
|
|
|
+
|
|
|
+ 
|
|
|
+
|
|
|
+8. In Environtment. Put DJANGO_ALLOWED_HOSTS that we especify on django settings. Then inpute your domain that you put in Configure Custom Domain.
|
|
|
+
|
|
|
+ 
|
|
|
+
|
|
|
+9. Click Deploy then wait buildpack to finish and push to porter. (You can see it on your repository under Action tab )
|
|
|
+
|
|
|
+ 
|