A
A
Artem Skopintsev2016-07-23 14:02:22
Django
Artem Skopintsev, 2016-07-23 14:02:22

How to build and deploy a Django application?

Good time of the day.
There is a project - a site on Django. We use Git as a VCS, the repository is stored in the BitBucket service.
We use SASS to develop the project, as well as Gulp & Bower. SASS code must be stored in the repository, it cannot be excluded. However, on the production server, of course, it and such files as gulpfile.js, package.json, bower.json, .bowerrc should not be. That's the question itself: how to build the project correctly so that all the code is stored in the BitBucket repository, and only what should be there on the production server?
I had different ideas, but they all seem to me not very good. For example, create a folder in the project folder where a copy of the entire site will be stored, but without unnecessary files. But here is the problem: how will I push to the combat server? And in general, it seems to me that making a copy of the site in such cases is far from the best method.
I will be glad for any help. I am not yet experienced enough in this area, so I turn to the masters of the toaster. Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Danil Biryukov-Romanov, 2016-07-23
@SharperX

Your task comes down to a simple thing - how to correctly deploy the code to production.
This is done very simply:
- Just clone the code to production
- Put the dependencies (and everything else)
- Remove everything that should not be on production - gulpfile.js, package.json, bower.json, .bowerrc and of course the .git directory .
Then the options begin:
- Do not delete the .git directory, but create a separate key for the prod environment, which has access only to the prod branch of the repository. To increase the security - you can still open the repository for production only before the deployment and close it after the deployment.
- Use Docker. We just assemble the container somewhere else, remove everything unnecessary from the container, and then deploy the container itself to production.
The Docker option is the most popular now and has a huge plus - you build an image with Django code, submit this image for testing, and after testing, the same image goes into production. This allows you to avoid bugs not found due to differences between test and production environments. However, there are many features of building Docker containers - it would be good to study Best Practice first to understand what can be applied in your case.
In order not to do everything by hand, it makes sense to automate this process - there are a huge number of tools for you - CI servers (the same Jenkins or web counterparts) and deployment automation tools - ansible, salt-stack, puppet, chef. As practice shows, ansible is one of the simplest.

W
werevolff, 2016-07-28
@werevolff

I do so .

S
Stanislav Gordienko, 2016-07-28
@stagor

I also use factories for this purpose. Check out my repository at https://github.com/stagor/django-ubuntu-deploy-live
I use a simple bash script to set up and configure the server. Every time I deploy code to production, I do it on a new server. Vagrant is used for testing locally. The code is easy to maintain and easy to use. If you have questions, please ask.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question