Remote Development: An Efficient Solution to the Time-Consuming Local Build Process

Remote Development: An Efficient Solution to the Time-Consuming Local Build ProcessSource: AI generated image integrated with Bing browser

Introduction

In contemporary software development, the processes of local development for immediate testing and continuous integration (CI) for deploying code to hosted environments are pivotal. However, the challenge in app development, particularly web development, lies in the time-consuming nature of CI build and deployment processes. As a workaround, developers often resort to local development builds, augmented by features like live reload and hot module replacement (HMR) for instant code feedback.

The Need for an Enhanced Approach

Nevertheless, there is an opportunity to achieve the efficiency of local development while offloading the build process to a remote host. This article delves into this solution, exploring how it diverges from the conventional local development setup.

Leveraging the Same Build System Remotely

In this approach, we leverage the familiar local development build system, with a crucial twist — the development server runs on a remote host instead of the local machine. By configuring the development environment to access the remote host’s IP instead of the typical “localhost,” we maintain the benefits of local development with enhanced efficiency.

Optimizing Development Workflow: A Streamlined Approach

Direct Approach Drawbacks

The straightforward solution involves using an SSH editor and updating the code directly on the remote machine. However, this process proves cumbersome, introducing challenges such as delays in code updates caused by network latency and the geographic location of the remote server. These hurdles can hinder the development experience and compromise efficiency.

Our Streamlined Approach

In contrast, our approach offers a refined solution that enhances the development workflow. Developers can remain in their familiar coding environment on their local machines, enabling them to make edits and enhancements seamlessly without the need for direct interaction with the remote host. This not only mitigates the challenges posed by the cumbersome process of updating code directly on the remote machine but also eliminates delays associated with network latency and server location. Our streamlined process ensures a more responsive and efficient development experience, allowing developers to focus on coding tasks with minimal disruptions.

Here’s how the process unfolds:

  • Local Development Continuity: Developers initiate the coding process on their preferred integrated development environment (IDE) or text editor, such as Visual Studio Code. This ensures a consistent and comfortable coding experience.
  • Background Synchronization: As developers work locally, a background process is in play. This process continually monitors code changes on the local machine.
  • Automated Code Sync: When a developer saves changes to a file, the background process swiftly and automatically syncs these changes with the remote host. This synchronization occurs seamlessly in the background, without disrupting the developer’s workflow.
  • Effortless Module Updates: With the code changes now residing on the remote machine, the development server serves these updated modules. This enables live reloading and hot module replacement (HMR) functionalities, ensuring that the latest version of the application is served without manual intervention.

Automating Code Synchronization with Rsync

This can be accomplished using the rsync tool over SSH. Here is a technical breakdown:

  • Clone the repository on the local machine.
  • Execute an initial rsync command to establish a shadow repository on the remote machine through SSH.
  • Set up the development environment on the remote machine, mirroring the local system’s configuration.
  • Initiate the development server on the remote machine.
  • Configure a host on the local system to reference the remote machine, eliminating the need to manually input the IP address.
  • Access the host URL in a web browser.

With this setup, the development server becomes accessible.

The Power of Rsync: A Technical Exploration

Now, let’s delve into the technical aspects of this solution:

This approach relies significantly on “Rsync,” which stands for “remote sync.” Rsync is a robust file synchronization tool designed to minimize data transfer by selectively copying only the parts of files that have changed. It boasts great flexibility and widespread usage on Linux and Unix-like systems, making it a standard inclusion in most Linux distributions.

Using Rsync to synchronize with a remote system:

rsync --delete -avz --protocol=31 --exclude-from=syncIgnore.txt source destination

Output:

sending incremental file list
created directory destination
source/
source/file1
0 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=99/101)
sourcefile10
0 100% 0.00kB/s 0:00:00 (xfr#2, to-chk=98/101)
source/file100
0 100% 0.00kB/s 0:00:00 (xfr#3, to-chk=97/101)
source/file11
0 100% 0.00kB/s 0:00:00 (xfr#4, to-chk=96/101)
source/file12
0 100% 0.00kB/s 0:00:00 (xfr#5, to-chk=95/101)
. . .

Customizing Rsync for Your Needs

This command incorporates various flags, such as -a for archiving, -v for verbosity, -z for compression, and --delete to remove files on the destination that no longer exist on the source. It is adaptable to meet specific requirements.

Automating Rsync for Seamless Development

Although rsync provides a robust solution for file synchronization, manual execution may be cumbersome. However, automation can be achieved by configuring the command to run automatically on each file save within an integrated development environment (IDE). Most popular IDEs offer extensions that detect file changes and allow the invocation of specific commands, facilitating seamless code synchronization and triggering HMR automatically.

Practical Considerations

Here are critical takeaways for developers to consider:

  • Employing a remote virtual machine offers access to diverse system configurations and scalability options, which can be advantageous compared to a physical laptop.
  • This solution is cost-effective and relatively simple to set up, making it accessible for developers of all levels.
  • Shifting the compilation and build process to a remote machine capitalizes on multiple threading, potentially resulting in faster build times compared to local development.
  • The initial setup time can be a drawback, especially when dealing with large amounts of data. Depending on the size and complexity of the data, the first synchronization can take a while. However, the trade-off is often worth it in terms of efficiency and bandwidth optimization in subsequent transfers. It’s like the saying goes, “good things come to those who wait.”

Choosing Efficiency and Flexibility: Rsync vs. GitHub Codespaces

When comparing our proposed solution, which utilizes rsync for remote development, with GitHub’s remote development features like ‘Codespaces,’ distinct advantages emerge. While GitHub provides a remote development environment through their ‘Codespaces’ offering, it comes with associated costs and limitations. Codespaces can be more resource-intensive and may not offer the same level of customization as deploying on a remote virtual machine. Additionally, our approach allows developers to leverage existing build systems seamlessly, ensuring a consistent development experience. The flexibility of rsync, combined with SSH-based synchronization, offers control and efficiency without relying on platform-specific solutions. This makes our solution particularly appealing for developers seeking a cost-effective, customizable, and efficient remote development setup.

Conclusion

This approach excels in maintaining a smooth local coding experience while harnessing the benefits of a remote development environment. Developers can focus on coding, testing, and iterating without the complexities of directly managing code on the remote machine. This streamlined process enhances productivity and code reliability, fostering a more efficient development workflow.

It enables developers to work faster and better without incurring additional costs. In essence, our coding journey not only addresses challenges but also enhances the enjoyment and productivity of developers. In summary, the combination of remote development, powered by rsync and IDE extensions, presents a robust solution to overcome the obstacles posed by time-consuming local build processes. Automated file synchronization with remote systems empowers developers to elevate their efficiency and productivity in the development experience.

Remote Development: An Efficient Solution to the Time-Consuming Local Build Process was originally published in Walmart Global Tech Blog on Medium, where people are continuing the conversation by highlighting and responding to this story.

Article Link: Remote Development: An Efficient Solution to the Time-Consuming Local Build Process | by Anindya Ghosh | Walmart Global Tech Blog | Dec, 2023 | Medium