user3214546
user3214546

Reputation: 6831

Deploying python site to production server

I have django website in testing server and i am confused with how should the deployement procedure goes.

Locally i have these folders

code
virtualenv
static
static/app/bower_components
node_modules

Current on git i only have code folder in there.

My Initial thought was to do this on production server

git clone repo
pip install
npm install 
bower install
colectstatic

But i had this problem that sometimes some components in pip or npm or bowel fail to install and then production deployemnet fails.

I was thinking of put everything in static, bower, npm etc inside git so that i can fetch all in prodcution.

Is that the right way to do. i want to know the right way to tackle that problem

Upvotes: 0

Views: 735

Answers (2)

0x4a50
0x4a50

Reputation: 923

In addition this might be helpful for some guidelines on deployment.

Upvotes: 0

Burhan Khalid
Burhan Khalid

Reputation: 174624

But i had this problem that sometimes some components in pip or npm or bowel fail to install and then production deployment fails.

There is no solution for this other than to find out why things are failing in production (or a way around would be to not install anything in production, just copy stuff over).

I would caution against the second option because Python virtual environments are not designed to be portable. If you have components such as PIL/Pillow or database drivers, these need system libraries to be installed and compiled against at build time.

Here is what I would recommend, which is in-line with the deployment section in the documentation:

  1. Create an updated requirements file (pip freeze > requirements.txt)
  2. Run collectstatic on your testing environment.
  3. Move the static directory to your frontend/proxy machine, and map it to STATIC_URL. Confirm this works by browsing the static URL (for example: http://example.com/static/images/logo.png)
  4. Clone/copy your codebase to the production server.
  5. Create a blank virtual environment.
  6. Install dependencies with pip install -r requirements.txt
  7. Make sure you run through the deployment checklist, which includes security tips and settings you need to enable for production.

After this point, you can bring up your django server using your favorite method.

There are many, many guides on deploying django and many are customized for particular environments (for example, AWS automation, Heroku deployment tips, Digital Ocean, etc.) You can browse those for ideas (I usually pick out any automation tips) but be careful adopting one strategy without making sure it works with your particular environment/requirements.

Upvotes: 2

Related Questions