Chapter 6. Deploy Django App

Tips for Managing Local Development and Remote Production Environment

Tips for Managing Local Development and Remote Production Environment
Tag:

As the requirements (e.g., security, specs, scalability, etc.) of the local development environment and the production environment on a server are different, you need to manage those differences properly and carefully.

There are three key points in managing the differences in the deployment process.

  1. Do not share irrelevant files (.gitignore)
  2. Do not install irrelevant dependencies (requirements.txt)
  3. Do not set irrelevant configurations (settings.py)

1. Do not share irrelevant files (.gitignore)

As some directories and files are not relevant to the production environment, you should not transfer the directories and files that are irrelevant to the production server. For example, the .env file is highly confidential and should not be shared. (we'll explain about .env later).

Also, the virtual environment directory (for example, d_env in our course case study) depends on the machine you have installed. You need to create another virtual environment directory on your server. Thus, you don't want to transfer the directory to the server.

To avoid sharing irrelevant files and directories when you are using Git, you can use the .gitignore file. We'll explain how to create .gitignore for Django deployment on the next page.

2. Do not install irrelevant dependencies (requirements.txt)

In principle, you want to create the same environment on both the local machine and the server; however, there should be some adjustments. As explained, you may want to switch your database software or need additional libraries only for the production environment.

One of the best practices for managing different dependencies is via creating different text files to list requirements for each environment. We'll explain this later in this chapter.

3. Do not set irrelevant configurations (settings.py)

You need to adjust several settings in the production environment, especially for security reasons. For example, you want to change the DEBUG from True to False, so that normal users cannot see the detailed error logs when they encounter errors. The details will be explained later in this chapter.

As these points are critical, we'll explain how to manage the three key points in detail in this chapter and summarize the points at the end of this chapter.

As the requirements (e.g., security, specs, scalability, etc.) of the local development environment and the production environment on a server are different, you need to manage those differences properly and carefully.

There are three key points in managing the differences in the deployment process.

  1. Do not share irrelevant files (.gitignore)
  2. Do not install irrelevant dependencies (requirements.txt)
  3. Do not set irrelevant configurations (settings.py)

1. Do not share irrelevant files (.gitignore)

As some directories and files are not relevant to the production environment, you should not transfer the directories and files that are irrelevant to the production server. For example, the .env file is highly confidential and should not be shared. (we'll explain about .env later).

Also, the virtual environment directory (for example, d_env in our course case study) depends on the machine you have installed. You need to create another virtual environment directory on your server. Thus, you don't want to transfer the directory to the server.

To avoid sharing irrelevant files and directories when you are using Git, you can use the .gitignore file. We'll explain how to create .gitignore for Django deployment on the next page.

2. Do not install irrelevant dependencies (requirements.txt)

In principle, you want to create the same environment on both the local machine and the server; however, there should be some adjustments. As explained, you may want to switch your database software or need additional libraries only for the production environment.

One of the best practices for managing different dependencies is via creating different text files to list requirements for each environment. We'll explain this later in this chapter.

3. Do not set irrelevant configurations (settings.py)

You need to adjust several settings in the production environment, especially for security reasons. For example, you want to change the DEBUG from True to False, so that normal users cannot see the detailed error logs when they encounter errors. The details will be explained later in this chapter.

As these points are critical, we'll explain how to manage the three key points in detail in this chapter and summarize the points at the end of this chapter.

Tag: