How-To's Remote Development

How To Get Started With Space Cloud Dev Environments

Are you thinking about introducing remote development into your team or organization? JetBrains’ remote development workflow allows you to overcome the limits of local machines and slow laptops by keeping your source code safe and secure on a remote server.

With the orchestration functionality included in Space, you can create a dev environment, connect it to your favorite JetBrains IDE, and start coding in seconds.

In this blog post, we’ll look at how to get started with dev environments in Space!

Create a Space organization and a first project

To get started with dev environments in Space, you will first need to create a Space organization. A free plan is available with some credits so you can try out remote development.

After logging in to your newly created Space organization, you’ll need to create a project. Click the + icon on the bottom left-hand side of the screen, and then select Project. We’ll only be using this project to try out remote development, so any name will do.

Create new project in JetBrains Space

Projects in Space bring together repositories, issue tracking, CI/CD, package registries, and much more. If you’re interested in any of these aspects of Space, we encourage you to explore them further.

Create a mirrored Git repository

Once you have your project set up in Space, you’ll need a Git repository to work with. 

Space comes with its own Git hosting. If you already have an existing Git repository that contains your code, you can choose to either migrate it to Space or enable repository mirroring.

When you create a mirrored Git repository, Space makes a copy of your existing Git repository and keeps the two synchronized at all times. Any code pushed to your existing Git repository will appear in Space, and any code pushed to Space will be automatically added to your existing repository. This is true for all branches and tags.

Create new Git repository to host your project source code

Install any JetBrains IDE (or JetBrains Gateway)

To connect to a dev environment that is running in Space, you’ll need to install either a JetBrains IDE or the standalone JetBrains Gateway on your machine. The latter is a compact desktop application that allows you to work with a remote instance of a JetBrains IDE.

Note: If you have the JetBrains Toolbox App installed, you can use it to install JetBrains Gateway.

The JetBrains IDE (or JetBrains Gateway) configures the connection between your local machine and the remote dev environment and launches the thin client that connects to the remote machine. You can also use it to manage dev environments in your Space organization without having to use the browser.

Use JetBrains IDE to manage Space dev environment

Create a dev environment

Once you have a Git repository in Space, use the Open in IDE button to create your first dev environment. In the dialog that opens, choose the instance type your remote IDE will run in, as well as the JetBrains IDE and version you want to work with.

Create a dev environment in Space and start a virtual machine to code in

In Space Cloud, there are a couple of instance types that can host your remote environment: a Regular virtual machine size with 4 CPUs and 7 GB RAM, as well as Large and Extra Large options with additional CPUs and memory.

When it comes to IDEs, you have a variety to choose from: JetBrains Fleet, CLion, GoLand, IntelliJ IDEA Ultimate, PhpStorm, PyCharm Professional Edition, Rider, RubyMine, and WebStorm. 

Note: The default version, which will be selected automatically, can be configured for your Space organization. For each IDE, you can set the default version in Administration | Dev Environments.

When you’re ready, click Create. This will provision the selected virtual machine and IDE, and prompt JetBrains Gateway to connect to your dev environment.

Connecting to a dev environment in Space

Congratulations, you now have your first dev environment running! In the remote IDE instance, you can write and refactor code, run and debug your apps, and more. If you enabled Git repository mirroring, any changes you commit and push to Space will automatically be replicated back to your existing Git repository.

Hibernate your dev environment

Your Space dev environment will be hibernated when it goes unused for more than 30 minutes. Hibernation stops the underlying virtual machine so it does not consume resources unnecessarily. In addition, you can hibernate your dev environment manually in Space by navigating to the Dev Environments screen in your project:

Hibernating a dev environment so it no longer consumes resources

From Space, or from within JetBrains Gateway, you can always restart a dev environment and continue where you left off. In Space, click Open IDE to restart the environment and connect to it. In JetBrains Gateway, you can click on the environment name to do the same:

Restart dev environment using JetBrains Gateway

Space makes sure the project directory and the $HOME directory are preserved during hibernation, so uncommitted code changes will still be there when you reconnect to the dev environment.

Customize your dev environment with devfiles and Dockerfiles

When you create your dev environment, Space provisions the virtual machine based on the instance type and IDE you select in the dialog. If you want to specify your own default values for your project, you can add a devfile to your repository. With a devfile, you can set the default instance type, the default IDE and version, specific environment variables and secrets, and more.

A project may have a single devfile.yaml file or several *.devfile.yaml files located in the .space folder in the repository root. Here’s an example devfile.yaml file that preselects a large instance type and sets IntelliJ IDEA Ultimate version 2022.2 as the default IDE:

schemaVersion: 2.2.0
attributes:
  space:
    instanceType: large
    editor:
      type: Idea
      version: '2022.2'

When you next create a dev environment, Space will automatically fill in the settings for the dev environment based on the selected devfile:

Select devfile when creating a new dev environment

But wait! There’s more! Your dev environment will run in a container on that virtual machine using the default Space container image. The default Docker image is based on the Ubuntu OS and includes tools like Git, curl, Docker, Docker Compose, Kubernetes, Google Cloud, Open JDK, Python, PHP, the .NET SDK, Ruby, Go, Node.js, npm, yarn, and others.

You can customize the container image that is used to provision your dev environment by adding a custom Dockerfile to your repository. Here’s an example Dockerfile based on Ubuntu 20.04, with some additional tools and JDK versions installed:

FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive
ENV LC_ALL=C.UTF-8

RUN apt-get update && apt-get install -y apt-utils apt-transport-https

RUN apt-get install -y \
  # Utilities \
  curl unzip wget software-properties-common socat man-db gnupg2 pass lsof \
  # VCS \
  git \
  # JVM \
  openjdk-8-jre-headless openjdk-11-jdk-headless openjdk-16-jdk-headless openjdk-17-jdk-headless maven \
  # Docker
  docker docker-compose \
  # Required tools
  cowsay \
  # Reduce image size
  && rm -rf /var/lib/apt/lists/*

ENV PATH="${PATH}:/usr/games"
ENV JAVA_HOME=/usr/lib/jvm/java-16-openjdk-amd64

Note: When using a custom image for remote development, we recommended always installing a number of command-line tools, such as curl, unzip, wget, lsof (to enable port forwarding in the remote IDE), and git.

To use a custom Docker image for your dev environment, you’ll need to update your devfile.yaml file and specify the path to the Dockerfile in your repository:

schemaVersion: 2.2.0
attributes:
  space:
    instanceType: large
    editor:
      type: Idea
      version: '2022.2'
components:
- name: image-build
  image:
      imageName: myapp:latest
      dockerfile:
        uri: .space/Dockerfile

Once done, the remote IDE will run in a container that uses your custom Docker image.

Warm up your dev environment to start it faster

When you start a new dev environment and connect to it, there’s a good chance you’ll see the remote IDE resolve project dependencies, build indexes, and perform other background activities. Depending on the size of your project and the number of dependencies, this may take some time.

The good news is that you can speed this process up significantly by building a warm-up snapshot. Warm-up snapshots are created with Space Automation. In the root of your repository, you can add a .space.kts file and configure how your dev environment should be warmed up.

Here’s an example .space.kts file that defines a job that runs every night. It downloads all Git branches, and then runs the steps to prepare a warm-up snapshot with the IDE configured in our devfile.yaml file:

job("Dev Environment Warmup") {
    startOn {
        schedule { cron("0 5 * * *") }
    }
    git {
        depth = UNLIMITED_DEPTH
        refSpec = "refs/*:refs/*"
    }
    warmup(ide = Ide.Idea) {
        devfile = ".space/devfile.yml"
    }
}

After you’ve warmed up your dev environment, everyone in your Space organization will benefit from a faster startup time, with project indexes ready to go.

One more thing – you can run additional steps as part of the warm-up. In your .space.kts file, just add a scriptLocation parameter that tells Space Automation to run a specific script file:

job("Dev Environment Warmup") {
    // …
    warmup(ide = Ide.Idea) {
        devfile = ".space/devfile.yml"
        scriptLocation = "./dev-env-warmup.sh"
    }
}

The ./dev-env-warmup.sh file in your Git repository can perform steps such as an initial mvn install or npm install to pre-populate dependencies in the environment, further reducing the time it takes to start a new dev environment and get coding.

Note: Space Automation can be used for many other tasks, including continuous integration (CI). Check out our documentation to learn more.

Summary

Space is a complete software development platform that offers remote development orchestration functionality.

You can create and work with dev environments to code on a secure remote machine in the Space cloud. With custom devfile.yml files and Dockerfiles, you can fine-tune how your remote development environment looks, while warm-up snapshots can help reduce the time it takes for your dev environment to start up.

In addition, Space covers the entire software development lifecycle, from hosting Git repositories, automating CI/CD, and publishing packages to managing issues, documents, and chats – all in one place and integrated with JetBrains IDEs. Give it a try!

image description