Efficient webapp developing [closed] - django

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Is not efficient :).
I'm trying to learn django by building a simple app. I bought a hosting plan on webfaction, set up github account and a putty on my Windows machine. I'm writing the "code" on my Windows, pushing it to github repo, then connecting via putty to my webfaction account to pull from github.
This is extremely tedious and boring process and I can't help but wonder that I'm doing something wrong. Even fixing a simple typo takes a lot of time. Are developers writing everything server-side using vim? This sound even less encouraging. Can I do something to improve my workflow? How it's done by professionals?

To summarise Kit Sunde's answer: you shouldn't be deploying to the server until you've actually got a site to deploy. Normal development and testing is done locally, using manage.py runserver and a local db. This works fine on Windows.

You need to stop wasting your own time, which you are if you are editing code on the server. There are many reasons why you shouldn't deploy code that way the most important ones is that you'll waste time and also importantly is that you'll break things while users are looking at the site.
Setup a development server locally, this is why the django manage.py runserver exists. If you for some reason can't run it on windows, then install a server in virtualbox, mount the folder in windows where your code is and run it off that (this is what we do for our designers although we have a lot of dependencies).
There are IDE's out there that enables you to run Django via a GUI that you might find more comfortable, I use PyCharm and I hear good things about eclipse.
You'd save time if you learned how fabric worked so you can automate your deploy process. I am unsure how well fabric works on windows, but I'm sure you can use cygwin or similar to get it working.
A fairly basic example would be this one:
from fabric.api import *
env.hosts = ['ubuntu#example.org']
def deploy():
pid_file = "~/myproject/process.pid"
with cd('~/myproject/'):
run('git pull')
run('src/city_nomads/manage.py collectstatic --noinput')
# If the process isn't up we don't want the thing to exit.
with settings(warn_only=True):
run("cat {} | xargs kill -TERM".format(pid_file))
run("src/myproject/manage.py runfcgi "
"method=threaded "
"host=127.0.0.1 "
"port=8000 "
"pidfile={} "
"--settings=myproject.settings_release".format(pid_file))
It'll SSH into my server, pull the source, collectstatic, kill the process if it's there and then run django as fastcgi. I'm assuming you have nginx or apache set up to connect to Django on port 8000.

Related

Docker for deploying djano application [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I have seen some pages with title deploy django with docker .
I deploy just with nginx & gunicorn and its awesome .
Is docker good for deploying django app ?
Does it make application faster or with better performance ?
So whats the main purpose ?
Docker helps developers bring their ideas to life by conquering the complexity of app development. It packages your Django app and creates a run time making sure that it works the same on all machines.
"But, It works on my system" - Developer without docker!
Also, you might be using nginx and gunicorn with Docker as well for hosting your django app. Containerization is a generic concept to have a machine independent run time to package everything. It simplifies your deployment process.

Is Git really necessary for deployment? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Disclaimer: I am a newbie to web development.
I built a program using Python, on Django framework. I am at a point where I feel ready to deploy my site, and make it go live.
After extensive research, I've noticed that every possible path to deployment requires me to use Git.
The problem is that Git is so hard to manipulate on my computer. I have the wrong version (I guess) installed, and my attempts to fix compatibility issue has been a nightmare (Im using Mac 10.7.5, and for some reason cant upgrade to newer MAC El Captain)
My question is this: Is there a way to deploy WITHOUT using Git? Evenmore, is there a way to deploy without the use of version control (I'm the only one building this site).
I just want the easiest path to deployment possible, since I am a complete newbie.
PS Please dont direct me to this link: Is git branches necessary for a single developer?
my questions is about the importance of using Git altogether.
For some platforms, git is required for deployment. Heroku, in particular, requires git for pushing changes to a remote defined on the command heroku create. See here for more details.
In other instances, you have more options, with the caveat that you may spend a lot of time configuring a system to do so and that you may suffer from the inability to have continuous deployment without downtime.
For example, using an Amazon EC2 instance or DigitalOcean, you essentially have a bare-bones Ubuntu installation upon which you control pretty much all facets of configuration, you would be able to send files to your remote instance via SSH or using one of their clients. In this case, you would generally do the following:
Shut down your Django server
Backup your existing application and DB, just in case
Upload the files for your updated application
Run any manage.py commands for migrations and updates
pip install -r requirements.txt to check for updated dependencies
Start your server up again
As stated before, git is not required for deployment, but most Django devs would highly, highly suggest you find the root of the issue you are having with git as it helps to protect against potentially devastating problems down the line and can greatly simplify deployment when your production environment is set up correctly.
EDIT: It's worth noting that git can provide deployment functionality when your deployment environment is set up properly, but deployment often is too complex a task to rely on git alone. A commonly used method is to use Fabric with a custom fabfile to automate deployment tasks. In tandem with git you gain version control, simplified deployment commands, and the ability to run tasks as part of your deployment.

Development and production with docker with multiple sites

Currently I have 3 linode servers:
1: Cache server (Ubuntu, varnish)
2: App server (Ubuntu, nginx, rabbitmq-server, python, php5-fpm, memcached)
3: DB server (Ubuntu, postgresql + pg_bouncer)
On my app-server I have multiple sites (topdomains). Each site is inside a virtualenviroment created with virtualenvwrapper. Some sites are big with a lot of traffic, and some site are small with little traffic.
A typical site consist of python (django), celery (beat, flower) and gunicorn.
My current development pattern now is working inside a staging environment on the app-server and committing changes to git. Then change environment to the production environment and doing a git pull, and a ./manage.py migrate and restarting the process doing sudo supervisorctl restart sitename:, but this takes time! There must be a simpler method!
Therefore it seems like docker could help simplify everything, but I can't decide the best approach for how I could manage all my sites and containers inside each site.
I have looked at http://panamax.io and https://github.com/progrium/dokku, but not sure if one of them fit my needs.
Ideally I would run a development version of each site on my local machine (emulating cache-server, app-server and db-server), do code changes there and test them. When I would see the changes worked, I would execute a command that would do all the heavy lifting and send the changes to the linode servers (I would think mostly the app-server), do all the migration and restarting the project on the server.
Could anyone point me in the right direction as how to achieve this?
I have faced the same problem. I don't claim this is the best possible answer and am interested to see what others have come up with.
There doesn't seem to be any really turnkey solution on Docker yet.
It's also been frustrating that most of the 'Django+Docker' tutorials just focus on a single Django site, so they bundle up the webserver and everything in the same Docker container. I think if you have multiple sites on a server you want them to share a single webserver, but this quickly gets more complicated than presented in the tutorials, which are no longer much help.
Roughly what I came up with is this:
using Fig to manage containers and complicated Docker config that would be tedious to type as commandline options all the time
sites are Django, on uWSGI+Nginx (no reason you couldn't have others though)
I have a git repo per site, plus a git repo for the 'server'
separate containers for db, nginx and each site
each site container has it's own uWSGI instance... I do some config switching so I can either bring up a 'dev' container with uWSGI as acting standalone web server, or a 'live' container where the uWSGI socket is exposed to the main Nginx container, which then takes over as front-side web server.
I'm not sure yet how useful the 'dev' uWSGI servers are, I might switch to just running Django dev server and sharing my local code dir as a volume in the container, so I can edit and get live reloading.
In the 'server' repo I have all the shared Dockerfiles, for Nginx server, base uWSGI app etc.
In the 'server' repo I have made Fabric tasks to do my deployment (checkout server and site repos on the server, build docker images, run fig up etc).
Speaking of deployment, frankly I'm not much keen on the Docker Registry idea. This seems to mean you have to upload hundreds of megabytes of image file to the registry server each time you want to deploy a new container version. This sucks if you are on a limited bandwidth connection at the time and seems very inefficient.
That's why so far I decided to deploy new code via Git and build the new images on the server. I don't use a Docker Registry at all (apart from the public one for a base Ubuntu image). This seems to go against the grain of Docker practice a bit so I'm curious for feedback.
I'd strongly recommend getting stuck in and building your own solution first. If you have to spend time learning a solution like Dokku, Panamax etc that may or may not work for you (I don't think any of them are really ready yet) you may as well spend that time learning Docker directly... it will then be easier to evaluate solutions further down the line.
I tried to get on with Dokku early on in my search but had to abandon because it's not compatible with boot2docker... which means on OS X you're faced with the 'fun' of setting up your own VirtualBox vm to run the Docker daemon. It didn't seem worth the hassle of this when I wasn't certain I wanted to be stuck with how Dokku works at the end of the day.

Django + Apache: make project accessible from WWW [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I've developed a Django project running on dev server. Now I am struggling in using Apache as the web server to run this project.
I've changed the port (say, 8088) at Router, and also edited http.conf in Apache dir to listen this port 8088.
Now I can view apache page at http://XX.XX.XX.XX:8088 (using ip) which shows 'It works'..
however, when I tried to run Django project using 'python manage.py runserver 0.0.0.0:8088', it says 'ERROR 10013: An attempt was made to access a socket in a way forbidden by its access permissons'.
It seems that the connection between Django and Apache doesn't work out, since I can view Apache working page but I can't get the project page...
I did configurate mod_wsgi.
maybe there are other silly stuff I've mistakenly done.
if anybody has some advice, that would be much appreciated!
If you've configured mod_wsgi properly, you don't need to run python manage.py runserver. Simply running the Apache daemon will make it listen on the port configured and will make it use the mod_wsgi file you've defined in the site-available.
Re-read this Django - how to use Django with Apache and mod_wsgi to verify you have it set up appropriately. You cannot run python manage.py runserver on a port that is already being listened to by Apache. Hence, the error attempting to access a socket (on port 8088) in a forbidden way.

how do I deploy Django on AWS? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I'm looking to deploy a django app on AWS (since I have some credit coupon) and am looking for a good place to read about it - mostly b/c I never used it before. thanks
looking for a good place to read about it
Here you go
I am a developer at BitNami, you may want to take a look at our free Django AMI. It is compatible with the AWS free tier.
2 new tutorials are given
realpython doc
and
Ashok Fernandez blog
The simplest approach is to simply spin up an EC2 instance, install nginx (mysql? and any other dependencies you might have) then follow the steps on the django site: https://code.djangoproject.com/wiki/DjangoAndNginx to deploying it. This basically goes through setting up a script to run "python [your app directory]/manage.py runfcgi host=127.0.0.1 port=8080" and setting up nginx to proxy requests to that port.
Another approach is to simply use a 3rd party tool like http://nudow.com to automate the deployment. For now the initial deployment I believe has to be done manually, however subsequent deployments can be done with one click. (and has other benefits like versioning)
I usually use Nginx on an EC2 instance
If you wish to deploy your Django app ASAP, without scratching your head :
You can use this script that I wrote:
Safely deploy your Django app in less 1 minute!
Instructions
Installing the DeployDjango script
$ wget https://raw.githubusercontent.com/yask123/DeployDjango/master/deploydjango.sh && chmod +x deploydjango.sh
From your Django App’s root directory (Where manage.py file exists).
$ sudo ./deploydjango.sh project_name
Done!
Visit http://ip-address-of-your-instance to see your web app live!