Breaking down Environment and branch (develop, master)

DRAFT DOCUMENT - Please review and help correct errors and misinterpretations.

I did something stupid, one thing led to another and soon my first ERPNext client was without ERPNext for 5 days. I don’t know if anybody have been in that situation before, but I think ERPNext must be some type of an addiction as my client’s users kept badgering and harassing me about restoring ERPNext.

The fact that they miss ERPNext is very satisfying. The fact that it took 5 days for me to restore ERPNext - not so much. While I won’t bore each of you about the complete details of why it took 5 days, here are a few learnings from this incident.

ERPNext has two environments: Development and Production

Two Branches: develop and master

The term develop that exists in both is what confused the heck out of me. After 5 agonizing days, this is what I have been able to figure out.

These two work independently. So you can have a Development Environment with develop branch; or with master branch. Similarly you can have Production environment with develop branch; or with master branch.

The master branch is the stable version. The develop branch gets all new features. But along with that can come a few bugs and problems.

So it makes sense to use the master branch in a Production environment and the develop branch in the Development environment. To make this association clear, may I suggest that we rechristen these branches as latest (for develop) and stable (for master).

If you are impatient and you want the latest releases to be used in your production environment, you could choose to use the develop branch in your production environment. If you end up using the master in your development environment and you are not careful, you could end up on working on features and enhancements that are already part of Frappe’s roadmap.

Why is this important for you to know this?

When things are going well, you really are reasonably transparent to this, but if disaster strikes, you will be confronted with these realities and unless you are conscious of this you will stumble through this for days (or hours, as most of you are wayyy smarter than I am).

For instance if you had a develop branch in a production environment and you didn’t know this and you have to build a new instance of ERPNext and restore onto it, you could very well end up building a master branch and could end up having errors when you do bench --site sitename migrate. This is exactly what I did. Once I got to know of this issue, I tried a few instances and could figure out that when I tried to restore the database onto a master branch (the crashed site was on develop branch) I got the same error. But when I built a develop branch it went through easily.

So, how do you build a production environment with the develop branch? You use the easy install option but build for develop. If the installation goes through without any issues, go to the frappe-bench/apps/frappe and frappe-bench/apps/erpnext and run a git branch and ensure that the installation is the right branch before you proceed ahead trying to restore the files. But if the installation fails, never mind, it usually will fail after it installs all the prerequisites, so now you just run the manual install, which is not as hard as I thought it would be.

Once you complete the installation by installing the bench which installs Frappe and you install app ERPNext, just go to the frappe-bench/apps/frappe and frappe-bench/apps/erpnext and run a git branch and ensure that the installation is the right branch before you proceed ahead trying to restore the files.

Once you have the right branch, do the restoration and then setup production by running bench setup supervisor and bench setup nginx. You have to copy the supervisor.conf in the frappe-bench/config folder to the /etc/supervisor/conf.d/ folder but the file has to be copied as frappe-bench.conf into that folder.

Similarly you have to copy the nginx.conf in the frappe-bench/config folder to the /etc/nginx/conf.d/ folder but the file has to be copied as frappe-bench.conf into that folder.

Now run sudo service supervisor restart and sudo service nginx restart and your Production environment with develop branch is ready for use. Congratulations!!

Question: How would you install a Development environment with master branch. You would go ahead just as I described. If you don’t have to restore a site, you run a bench switch-to-master and that should switch your branch to master, I guess. I guess it’s a bit more tricky if you have to restore a site. Do you run bench switch-to-master before or after restoration?

I hope it helps. If it confuses everybody, profuse apologies. Just remember, I mean well!!

3 Likes

Very good point. As a bit of a newcomer to ERPNEXT I thought what you describe is the setup but I wasn’t sure. Also having two terms that are the same used for different aspects IS very confusing.

So generally you will want to be using the develop environment of the Master branch for making code changes to the stable branch

Right. But when you do that, you may want to be sure that the code changes you want to make is not already part of the develop branch of ERPNext. You could end up wasting time on something that’s already part of ERPNext.

Hi,

@JayRam mentioned “These two work independently. So you can have a Development Environment with develop branch; or with master branch. Similarly you can have Production environment with develop branch; or with master branch.”

I do checked for my branch is master branch like the attached photo below:

  1. However, i do not know , what is development environment or production environment am i using, how can i check it?

Good question jcyh!

I puzzled over what distinguishes production and development, especially since either environment can run from the same directory if you wish. (Hence developer_mode can be enabled in a production environment.)

‘bench start’ to run the development environment
werkzeug + honcho used in development.

‘sudo supervisorctl start all’ to run the production environment.
nginx + gunicorn are used in production

If you forget to shutdown one environment before starting the other you will get for example ‘bind: Address already in use’ errors to remind you to close down that running instance.

3 Likes

In VM environment downloaded from Not Found

have Production if it is reachable
http://localhost:8080
no need bench start

have Develop if reachable
http://localhost:8000
need bench start

As far as I understand.

1 Like