Working Offline with Eclipse Che

Florent Benoit
Apr 29, 2020 · 7 min read

Eclipse Che has many thousands of users. Most of them use the VS Code-inspired browser IDE, but sometimes you know you’re going to be offline for awhile and want to be able to work with a local editor, then sync back your changes when you’re back online.

Obviously if you only care about changes to the source code then git will handle this just fine. But if you want to run it offline, make changes to your tools, runtimes or dependencies then it’s great to be able to have all that synced back to Eclipse Che.

In this article we’ll cover how to set this up, by:

  1. Updating your Eclipse Che workspace to allow rsync.
  2. Importing files into your local computer/laptop.
  3. Edit/work with your project on your laptop
  4. Synchronize back all code changes from your laptop to the remote workspace.

Prerequisites

1. On my laptop: check all tools are available

  • Check local installation of rsync on the laptop by trying to execute the command $ rsync.
  • Check installation of kubectl to execute remote rsync command.
  • Check installation of theoc CLI if Eclipse Che is running on OpenShift.

These tools will need to be on your local machine if they’re not already.

2. In Eclipse Che Workspace

The rsync tool needs to be part of the workspace.

Note: with OpenShift we could use oc rsync command. But there is no exclude filter taken into account, for example. So in this blog post I will use only kubectl and rsync.

Your Eclipse Che workspaces may include several running containers. (Workspace pod). Let’s add a new container that will manage only rsync operations.

I will use the rsync tool included in the image quay.io/fbenoit/rsync-simple so no need to build it.

The image includes the following:

As you can see this just adds the rsync tool inside the smallest container possible (based on alpine linux).

I’ve also added an entry-point to keep the container always-on, and an extra permissions to make it compliant with the random user-id generated by OpenShift.

Workflow

1. Updating your Eclipse Che workspace to allow rsync

The devfile is responsible of the definition of the Eclipse Che workspace.

Edit the devfile of the workspace from the Eclipse Che dashboard:

Editing your Che workspace’s devfile in the Che user dashboard

As seen in prerequisites, rsync tool needs to be part of the workspace and by default it’s not there. Let’s add a new rsync component and let it have access to /projects folder using mountSources: true

Add this component into components section (or create a new components section first if it’s not there).

component to add to your workspace

Now restart the workspace to finish the inclusion of this new rsync component. You can check if you’ve been successful by opening the workspace in an IDE and opening the Workspace panel (the cube icon on the right of the IDE):

Checking rsync is in the workspace

3. Importing files into your local computer/laptop

To share files on our laptop and use rsync, we will need some information.

  1. kubectl ready-to-use (authentication performed)
  2. The name of the running remote workspace pod
  3. An rsync bash script

3.1. kubectl

In my example, I am using the online Eclipse Che instance hosted on che.openshift.io. I will copy the command to be able to log into OpenShift instance.

I can use the OpenShift web console to do that. To get the web console link, open a terminal inside the IDE by using the Workspace panel within the IDE.

Open a terminal inside the Theia IDE container for example. Then type:

It will display the URL of the console:

Use command+click on https://console.starter-us-east-2.openshift.com/
It will open link in default browser. Note that your workspace might be assigned to a different cluster, so the URL might be different as well.

When logged in in the OpenShift console:

  • Open the top right corner link
  • Click on copy Login command and execute that command on your laptop.

copy the oc login command and execute it on your laptop:

Then use your namespace (ending with -che) using oc project <namespace> command:

And we can check that the workspace pod is there by using oc get pods or kubectl get pods commands.

list pods using the kubectl command

3.2. Name of the workspace pod

We will copy files from the remote workspace to our local machine.

We need the name of the workspace. It is available from a terminal with the following command:

Grab workspace pod name

Another way is to use the kubectl or oc tool to find the workspace pod name ($ kubectl get pods or $ oc get pods).

The name of the container that includes rsync is “rsync” as it’s the alias name we defined in the devfile.

3.3. The rsync script

To import the project files into Eclipse Che workspace, we will now use rsync.

We will need a shell script to perform the copy and this script will use kubectl exec command.

Create a new file kubectl-rsync.sh with the following content:

kubectl-rsync.sh

Don’t forget to make it executable: chmod u+x kubectl-rsync.sh and now let’s assume you copy it to ${HOME}/bin folder.

Now, let’s create another script named workspace-sync.sh

workspace-sync.sh script

Apply permissions by using chmod u+x workspace-sync.sh.

Copy it, for example, to ${HOME}/bin folder. We’re using the -e option in rsync parameters to specify another shell.

Now that our scripts have been setup, it’s time to use them.

First, we store the workspace pod into an env variable:

Let’s proceed to the first import.

Assuming our remote workspace has files in /projects/ and that we want to copy workspace files it to ${HOME}/my-workspace on our laptop, execute the following command:

Now files are being transferred into our laptop.

We see progress due to --progress option. You may add--exclude ‘node_modules' in RSYNC_OPTIONS for nodejs projects to exclude unwanted files.

In your laptop you should see my-project folder in ${HOME} directory.

initial import of our workspace’s files

4. Edit/work with your project on your laptop

Well here, you can do whatever you like with your project that has been synchronized to ${HOME}/my-workspace/my-project

For example if it’s a java/maven project you can run mvn command there or run yarn for nodejs project, etc.

5. Synchronize back all the changes

All modified files are now on your local computer so you can edit them. But at some point you’ll want those changes back in the remote Che workspace.

We’ll use the same workspace-sync.sh script but we’ll reverse the source and destination. Because now we want to copy laptop’s changes to the remote workspace and not the previous way. Also, we’ll set this time RSYNC_INFINITE=true to do rsync every 15s (to never miss local changes).

You can drop --progress --stats from RSYNC_OPTIONS so you don’t generate too much output now that you’ve confirmed it works.

One issue is that when syncing back the changes, we don’t want to upload the whole node_modules folder. Adding the --exclude node_modules parameter takes care of that.

The script now checks all the changes every 15 seconds.

All changes from my filesystem are now inside my remote workspace.

Let’s check:

rsync to remote workspace

6. Finishing

When we’re done working we can double-check that the rsync script has finished to copy all files remotely and then delete the project on our laptop.

One you have this all set up it’s easy to either leave it running all the time and fluidly move from editing on your laptop and editing in the cloud. Or only turn it on when you know you’ll be offline for awhile (like for a trip).

Eclipse Che Blog

News and articles for Eclipse Che - next-generation Eclipse…

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store