Customize the development environment in Space, one-click collection! | Practical Raiders

In JetBrains Space, you can start a development environment to work with code remotely. A powerful, dedicated virtual machine will run a Docker container, the virtual machine can access your project's source code, and provide backend components for your native code editor. You can use these remote machines to develop software without using your local computer .

 

One of the many advantages of using the Space development environment is that you can standardize the development environment for your team so everyone can start working on projects right away without wasting time setting up their local computers. Additionally, you can run a warmup task and prepare a snapshot with all necessary package dependencies downloaded and an index of prebuilt projects ready to use.

 

In this article, we'll dive into the customization options for the Space development environment and see how you can customize the development environment to suit your team's needs .

 

 

Create a development environment

 

Before we dive into the customization options, let's click here for a quick review of how to get started with the Space development environment.

 

From any Git repository in your Space organization, you can start a development environment by clicking  Open in IDE . Additionally, you can create a new development environment for any merge request, so you don't have to manually clone code and download dependencies on your local machine to review and test changes.

Tip: You can migrate or mirror an existing Git repository from GitHub or BitBucket and make it available in Space, including all branches, tags, and commits. This way, you can leverage your existing repositories to use the Space development environment.

 

Depending on the needs of your project, you can choose from one of three VM instance types: Regular (4 CPU cores, 8GB memory), Large (8 CPU cores, 16GB memory), or Extra Large (16 CPU cores, 32GB RAM).

 

Next, you need to choose the IDE you want to use: IntelliJ IDEA  with  JetBrains Gateway (available through the Toolbox App), or  JetBrains Fleet . Support for other IntelliJ-based IDEs is in development.

  • IntelliJ IDEA

    https://www.jetbrains.com.cn/idea/

  • JetBrains Gateway

    https://www.jetbrains.com.cn/remote-development/gateway/

  • JetBrains Fleet

    https://www.jetbrains.com.cn/fleet/

 

You'll also notice two other elements in this dialog: a warmup snapshot and a development container for launching the remote IDE . In the example above, the warmup snapshot is not shown yet (we'll explain why later), and the default Docker image is used as the container to start the IDE.

https://www.jetbrains.com.cn/help/space/set-up-a-dev-evnvironment.html#using-the-default-dev-environment

 

When you click  Create , Space will launch your IDE in the cloud. Once the virtual machine is set up and the IDE backend is ready, the JetBrains Gateway (or Fleet) will open and connect to it.

 

The IntelliJ IDEA backend is now running in the Space cloud, and we used the thin client JetBrains Gateway to connect to it. For many projects, this is enough to start coding right away. However, in this specific example, it looks like something is missing:

  • We still need to download the correct JDK, as indicated by the warning in the editor.

  • We still need to run  mvnw compileto download dependencies, and we also need to sync the project in the IDE.

 

This might be fine for a one-off development environment, but if your entire team is going to be working on this repository, it's best to customize the development environment to make sure all dependencies are there from the start. Let's see how to make it happen!

 

 

Custom development environment Dockerfile

 

By default, Space runs your development environment using the default container image based on the Ubuntu operating system and includes Git, cURL, Docker, Docker Compose, and OpenJDK.

 

You can add a custom Dockerfile to your project to install any necessary tools and libraries. Depending on the IDE you use, you must create  ./.jb-gateway/Dockerfile(IntelliJ IDEA with JetBrains Gateway) or  ./.fleet/Dockerfile(Fleet).

 

For this particular project, we'll customize the environment to be based on Ubuntu 20.04, and we'll also install a bunch of command line tools including Git, curl, Docker, and more. We also added several versions of OpenJDK and set it to default to version 16 so that the development environment can pick it up.

 

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 \
  && rm -rf /var/lib/apt/lists/*


ENV JAVA_HOME=/usr/lib/jvm/java-16-openjdk-amd64

 

A custom Dockerfile has several requirements:

  • The operating system must be a glibc-based Linux distribution (eg: CentOS 7+, Debian 9+, or Ubuntu 20.04+).

  • You must install Git, OpenSSH (if you want to use a remote Git repository) and  lsof(if you need port forwarding in the IDE).

  • Containers must be run as root (without any non-root users in the Dockerfile).

 

Note that the Dockerfile is branch specific. This makes it easy to test customizations in separate branches, update to newer tool versions in feature branches, and more without affecting other developers on the team.

 

When you commit and push this custom Dockerfile to your project repository, Space will use it as a base image when creating new development environments in this branch.

 

After starting this custom development environment, you will see that the IDE can now use the correct JDK version. However, the IntelliJ IDEA and Maven projects still need to be synchronized. This is the perfect time to use a warmup script!

 

 

Warm up the development environment

 

You can reduce the time the IDE takes to resolve project dependencies, build indexes, and perform other background activities by building warm-up snapshots. In our example, running  mvnw compileand indexing the project will help us prepare our development environment.

 

Warm-up snapshots are created using  Space Automation  . By adding a  .space.ktsfile, you can not only start configuring continuous integration (CI) for your project, but also how your development environment should be warmed up.

  • Space Automation

    https://www.jetbrains.com.cn/space/features/software-development.html#a-automation

 

Here's an example  .space.ktsfile that defines a job that runs nightly, downloads all Git branches, and then runs steps to prepare a warmup snapshot using IntelliJ IDEA:

 

job("Dev Environment Warmup - Gateway") {
    startOn {
        schedule { cron("0 5 * * *") }
    }

    git {
        depth = UNLIMITED_DEPTH
        refSpec = "refs/*:refs/*"
    }

    warmup(ide = Ide.IJGateway) {
        scriptLocation = "warmup.sh"
    }
}

 

scriptLocation is optional. If you omit it, Space Automation will clone your project's Git repository and handle project indexing in the IDE. If added, you can specify the name of the warmup script (eg  warmup.sh) and perform some action in that script (eg run  mvnw compile), download all Maven dependencies into the warmup snapshot, or run  npm install. Here is an example  warmup.sh script:

 

#!/bin/bash
./mvnw compile

 

Note that it warmup.sh must be committed to your repo with executable permissions. You can  git update-index --chmod=+x warmup.sh do this by running.

 

Once Space Automation has finished running the warmup job, the newly created development environment will utilize the custom Dockerfile we created earlier and mount the warmup snapshot we just created, with the project index and dependencies in a ready state.

If you need to troubleshoot a warmup job, you can use Space Automation to find logs of all the steps performed and their console output.

 

 

Additionally, from the project's  Dev Environments menu, you can manage and remove snapshots that are no longer needed.

 

 

Container images, warm-up snapshots, or both?

 

So far, we've seen how to customize the container image of the development environment and how to build a warm-up snapshot. But where should you run which type of task?

 

In general, custom container images should be used to configure the environment and operating system, while warmup jobs should be used for project-specific tasks such as downloading binary dependencies and preparing the IDE for the project.

 

 

in conclusion

 

In this article, we describe how to start and customize a development environment in JetBrains Space. With custom container images, you can standardize the development environment for your team. With the warmup task, you can prepare a snapshot that includes downloaded package dependencies and prebuilt project indexes, so you can start developing faster with your development environment.

 

Give the JetBrains Space and development environment a try! We are happy to receive your feedback!

https://www.jetbrains.com.cn/space/#sign-up-popup

 

Outside the number - JetBrains Chinese official website upgrade

Recently, we officially launched the  Chinese official website with the domain name jetbrains.com.cn  , which will bring you faster access speed and smoother experience. JetBrains China will continue to work on creating more convenient support and services for local users. If you have any suggestions to help us improve and improve, please leave us a message in the background.

 

Please remember our newly upgraded official website domain name: 

jetbrains.com.cn

 

Thanks!

JetBrains China

 

English blog post original author: Maarten Balliauw

 

 Related Reading 

"In-depth understanding of JetBrains Gateway, easy to start remote development!

 

 

This article is shared from the WeChat public account - JetBrains (JetBrainsChina).
If there is any infringement, please contact [email protected] to delete it.
This article participates in the " OSC Yuanchuang Project ", you are welcome to join and share with us.

{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/5494143/blog/5452280