Need advice on how to modify or fix things on another device

Hi guys,

How do you guys code remotely? Im hoping to edit or fix my version of erpnext that is located on another device running ubuntu server

One way is to login via ssh

On Linux you just type ssh user@remote-server
On Windows you can use Putty as ssh client.

Make sure the ssh server is running on your remote device.

It’s generally not a great idea to do heavy coding on a live/remote server, but for the occasional hotfix I tend to just ssh in and use vim/nano. If you need a remote environment for development, remote editing plugins exist for most of the major tools, including Sublime, Atom, Visual Studio, etc.

Well in this case yoi can try to foward the X server on the remote machine to you local computer via ssh.
That way you should be able to use GUIs.

For developmemt it’s also handy to use a local instance.
Just restore a DB snapshot of your remote DB on your local ERPnext (or in a VM if using windows).

How do you usually do enhancements? Do you like create a new private repo in github and upload your own version of erpnext there? Will this break the usual bench update command or the easy install script?

Method we follow is create app in local machine, merge with Git and pull to production server from Git. All modification/changes are made in local machine. Its easier to test and fix it in local machine. Once satisfied merge with Git.

I have several techniques I use for different circumstances:

If I have problems on a remote server that I can’t replicate on a local machine I have two techniques:

  1. If I see that there’s a lot of OS activity I need to examine, in addition to coding, I’ll install XFCE and X2GO server. XFCE is a very lightweight GUI. X2GO is an incredibly good XWindows client.

  2. SSHFS. This is ridiculously easy. I keep an empty directory on my local machine called /home/you/Desktop/SSHFS_MOUNT. When I need to try out some code changes on a remote server (like putting a print statement in ERPNext code) I just have to do the following and then open the SSHFS_MOUNT directory in my code editor …

you@Yours:~$ sshfs derpl:/home/erpdev/frappe-bench-DENH/apps/erpnext ./SSHFS_MOUNT
you@Yours:~$ ls -la ./SSHFS_MOUNT
total 232
drwxr-xr-x 1  1001  1001  4096 Dec 30 14:51 .
drwxr-xr-x 9 you you  4096 Dec 21 07:03 ..
-rw-r--r-- 1  1001  1001   200 Dec 30 14:50 attributions.md
-rw-r--r-- 1  1001  1001  3212 Dec 30 14:50 CODE_OF_CONDUCT.md
-rw-r--r-- 1  1001  1001   849 Dec 30 14:50 CODEOWNERS
-rw-r--r-- 1  1001  1001   238 Dec 30 14:50 .editorconfig
drwxr-xr-x 1  1001  1001  4096 Dec 30 14:51 erpnext
drwxr-xr-x 1  1001  1001  4096 Dec 30 14:59 erpnext.egg-info
     :     :     :     :     :
     :     :     :     :     :
-rw-r--r-- 1  1001  1001  2209 Dec 30 14:50 .travis.yml
-rw-r--r-- 1  1001  1001 90446 Dec 30 14:50 yarn.lock
you@Yours:~$ 

I use virtual machines a lot. To get code changes from the base machine into the VM, I use a continuous rsync script in the root directory of a project:

# Retrieve variables like: SERVER_ALIAS, remote USER, etc
source ${HOME}/projects/Project_A/environmentVariables.sh;


export EXCLUSION_A="--exclude 'a_stuff'";
export WORK_DIR="\${HOME}/frappe-bench-DENH/apps/Project_A";

echo -e "Preparing target directory '${SERVER_ALIAS}:${WORK_DIR}'";
ssh -t ${SERVER_ALIAS} ". .profile; sudo -A mkdir -p ${WORK_DIR}";
ssh -t ${SERVER_ALIAS} ". .profile; sudo -A chown \${USER}:\${USER} ${WORK_DIR}";

echo -e "Synching this directory with :: ${SERVER_ALIAS}:${WORK_DIR}  ( EXCLUSIONS : \"${EXCLUSION_A}\" )";

while inotifywait -qqr -e close_write,move,create,delete ./*; do
  rsync ${EXCLUSION_A} -avx . ${SERVER_ALIAS}:${WORK_DIR};
done;

Every change I save is replicated into the VM in less than a second, so it feels like it’s all in the same machine. It works almost as well on remote sites too if the files are small.

Depending on your Linux distribution you may need to install inotify.

1 Like

If i created an app and want it on my repo i should be using git and nit bench command?

With repo do you mean your bench instance on your ERPNext server or the source code repo?

@Paul_Frydlewicz I want the app that i created locally to be in my own private git repo. also is it bad practise to use the same frappe/bench folder for production and development. like im gonna switch to development mode to edit stuff then switch to production mode if its ready or should i create a new user for development and new user for production?

Yes it’s very advisable to separate dev and production at least in different benches.
The problem is, that changing files like e.g. web templates or others will have direct impact on all sotes in the same bench.
So it’s really bad practice to mix dev and production.

But you can create a new bench (bench init #name#) for your dev environment. Bench usually takes care if the port numbers to have multiple benches run in parallel.

Btw regarding your question about remote editing of files.
I recently switched to VS code. It has a ssh plugin where you can work on remote folders as if it’s on your machine.
Search for vs code and ssh remote folder plugin (or alike). Really easy to set up and super smooth to use.

Seasoned developers won’t need to be told this, but technically competent business people may be unaware …

An enormously useful tool for learning, experimentation, testing, etc is a virtual machine hypervisor.

You can choose between:

  • VMWare
  • Virtual Box
  • KVM/Qemu
  • Microsoft Hyper-V
  • others

You want to pick one that permits snap shots!

In a virtual machine you can install your favorite operating system (snap shot), then install ERPNext (snap shot), then restore your database (snapshot), then install you customization (snap shot), then modify your customization, etc.

If at any point you discover you cannot move forward because of a bug or lack of something vital you can revert to the snap shot just before, make the correction, then repeat only the intervening steps.

When you get absolutely mortally sick of filling out the setup Wizard form over and over again you’ll see what I mean.

Hi @CuriousPasserby,

You can try using ssh but make sure you enable your ssh. By using vscode, you can be able to edit your code remotely. But it is only good for development purpose, not recommended for production. Using this kind of method is only good for minimizin setup time for other developers in case you are in a team. You can refer to this link for more info of how you edit your code using vscode and ssh. Remote dev with vscode. Hope this help