JetBrains Space Help

Run Environment

A run environment is defined by the following parameters: a Docker image which will be used for the dev environment instance, an instance type, and a set of environment variables provided to the instance.

Default Docker image

If you don't specify a Docker image, Space will use the default one. The default image is based on Ubuntu OS and includes Git, curl, Docker, Docker Compose, Kubernetes, Google Cloud support, Open JDK, Python, PHP, .NET SDK, Ruby, Go, Node.js, npm, yarn, and other tools.

Default image Dockerfile:

FROM ubuntu:20.04 ENV LANG=C.UTF-8 MAINTAINER Alexander Sedov <alexander.sedov@jetbrains.com> ARG TARGETARCH # Support various rvm, nvm etc stuff which requires executing profile scripts (-l) SHELL ["/bin/bash", "-lc"] CMD ["/bin/bash", "-l"] # Set debconf to run non-interactively RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections RUN apt-get update && apt-get install -y apt-utils apt-transport-https software-properties-common # Newest git RUN apt-add-repository ppa:git-core/ppa -y && apt-get update RUN set -ex -o pipefail && apt-get install -y \ # Useful utilities \ curl unzip wget socat man-db rsync moreutils vim lsof \ # VCS \ git subversion subversion-tools mercurial \ # Database clients \ mongodb-clients mysql-client postgresql-client jq redis-tools \ # C/C++ \ build-essential cmake g++ m4 \ # R \ r-base r-base-dev \ # TeX \ texlive \ # JVM \ openjdk-8-jre-headless openjdk-11-jdk-headless openjdk-17-jdk-headless maven ant clojure scala \ # Python 3 \ python3-matplotlib python3-numpy python3-pip python3-scipy python3-pandas python3-dev pipenv \ # Python 2 \ python2-dev python-pip-whl \ # Ruby \ ruby-full \ && \ # Setup Java \ update-alternatives --get-selections | grep usr/lib/jvm | awk '{print $1}' | \ grep -v jpackage | grep -v jexec | \ while IFS= read line; do echo $line; update-alternatives --set $line /usr/lib/jvm/java-11-openjdk-$TARGETARCH/bin/$line; done && \ java -version && javac -version && \ # Check Python \ python3 --version && python2 --version && pip3 --version && \ # Go \ curl -fsSL "https://dl.google.com/go/$(curl -fsSL 'https://golang.org/VERSION?m=text').linux-$TARGETARCH.tar.gz" -o /tmp/go.tar.gz && \ tar -C /usr/local -xzf /tmp/go.tar.gz && rm /tmp/go.tar.gz && \ for x in /usr/local/go/bin/*; do echo $x; ln -vs $x /usr/local/bin/$(basename $x); done && ls -la /usr/local/bin && go version ## Nodejs, npm, yarn RUN set -ex -o pipefail && \ curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && \ curl -fsSL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /usr/share/keyrings/yarnkey.gpg >/dev/null && \ echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | tee /etc/apt/sources.list.d/yarn.list && \ apt-get update && apt-get install -y nodejs yarn ## PHP RUN set -ex -o pipefail && \ add-apt-repository ppa:ondrej/php -y && \ apt-get install -y --no-install-recommends php8.0-cli php8.0-common php8.0-curl php8.0-xml php8.0-mbstring && \ wget https://github.com/composer/composer/releases/download/2.2.1/composer.phar -O /usr/bin/composer -q && \ chmod +x /usr/bin/composer ## dotNet RUN if [ "$TARGETARCH" == "arm64" ] ; \ then echo "Skipping installation of .NET packages, as they are only available for arm64 starting from Ubuntu 22.04" ; \ else set -ex -o pipefail && \ wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb && \ dpkg -i packages-microsoft-prod.deb && \ rm packages-microsoft-prod.deb && \ apt-get update && \ apt-get install -y dotnet-sdk-6.0 ; \ fi ### Cloud Tools ## The awscli tools use a different naming scheme for arm64 builds RUN if [ "$TARGETARCH" == "arm64" ] ; \ then AWS_TOOLS_ARCH=aarch64 ; \ else AWS_TOOLS_ARCH=x86_64 ; \ fi && \ set -ex -o pipefail && \ # Docker \ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg && \ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list && \ apt-get install -y docker.io && \ docker --version && \ # Kubernetes \ curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg && \ echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | tee /etc/apt/sources.list.d/kubernetes.list && \ apt-get update && apt-get install -y kubectl && \ kubectl version --client && \ # aws-cli \ curl -fsSL "https://awscli.amazonaws.com/awscli-exe-linux-$AWS_TOOLS_ARCH.zip" -o /tmp/awscliv2.zip && \ mkdir -p /tmp/aws.extracted && \ unzip -q /tmp/awscliv2.zip -d /tmp/aws.extracted && \ /tmp/aws.extracted/aws/install && \ rm -rf /tmp/aws.extracted /tmp/awscliv2.zip && \ /usr/local/bin/aws --version && \ # gcloud \ curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && \ echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee /etc/apt/sources.list.d/google-cloud-sdk.list && \ apt-get update && apt-get install -y google-cloud-sdk && \ gcloud --version && \ # rclone \ curl -fsSL https://downloads.rclone.org/v1.56.2/rclone-v1.56.2-linux-$TARGETARCH.zip -o /tmp/rclone.zip && \ mkdir -p /tmp/rclone.extracted && unzip -q /tmp/rclone.zip -d /tmp/rclone.extraced && \ install -g root -o root -m 0755 -v /tmp/rclone.extraced/*/rclone /usr/local/bin && \ rm -rf /tmp/rclone.extraced /tmp/rclone.zip && \ rclone --version ## Docker compose (https://docs.docker.com/compose/install/) ## There are no arm64 builds of docker-compose for version 1.x.x, so version 2.x.x is used RUN if [ "$TARGETARCH" == "arm64" ] ; \ then DOCKER_COMPOSE_VERSION=v2.14.0 ; \ else DOCKER_COMPOSE_VERSION=1.29.2 ; \ fi && \ set -ex -o pipefail && \ curl -fsSL "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && \ chmod +x /usr/local/bin/docker-compose && \ rm -f /usr/bin/docker-compose && \ ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose RUN echo "############################### Versions #####################################" && \ java -version && \ javac -version && \ echo "" && \ python3 --version && \ python2 --version && \ pip3 --version && \ echo "" && \ go version && \ echo "" && \ echo ".NET SDK" && \ if [ "$TARGETARCH" != "arm64" ] ; then dotnet --list-sdks ; else echo "Not available for arm64" ; fi && \ echo "" && \ echo ".NET Runtimes" && \ if [ "$TARGETARCH" != "arm64" ] ; then dotnet --list-runtimes ; else echo "Not available for arm64" ; fi && \ echo "" && \ echo "Nodejs: $(node --version)" && \ echo "Npm: $(npm --version)" && \ echo "Yarn: $(yarn --version)" && \ echo "" && \ ruby --version && \ echo "" && \ php -v && \ composer -V && \ echo "" && \ docker --version && \ docker-compose --version && \ echo "" && \ echo "Kubectl: $(kubectl version --client)" && \ echo "" && \ gcloud --version && \ echo "" && \ rclone --version && \ echo "############################### Versions #####################################"

You can use this Dockerfile as a basis for creating your own image and hosting it in Space Packages. Learn more

Specify an image for the dev environment

A dev environment runs in a Docker container. If you don't specify an image in a devfile.yaml, Space will use the default image. As a custom image, you can use an image from Docker Hub (or other registries that doesn't require authentication), Space Packages, or create an image from Dockerfile each time a user creates a new dev environment. To specify the image, use the project's devfile.

Image requirements
  • OS: any glibc-based Linux distribution (for example, CentOS 7+, Debian 9+, Ubuntu 20.04+).

  • Tools: Git, OpenSSH (if you want to use a remote Git repository), lsof (if you need port forwarding in the IDE).

  • The container must run as root (there must be no non-root users in Dockerfile).

Container image vs warm-up snapshot

In some cases, you might face a dilemma where to put a certain preparation step: to the container image or to the environment warm-up? For example, your project requires an SDK. To get the SDK, you run curl - o sdk.zip $SDK_URL && unzip sdk.zip. Where do you put this line: to the Dockerfile or to the warm-up script?

Our recommendation:

  • All additional tools (e.g., the tools installed with apt get) should be installed to the dev environment's image, i.e., described in the Dockerfile.

  • All binary dependencies stored within the root or the project directory should go to a warm-up script. So, in the example above, the best solution would be to get the SDK in a warm-up script.

In the components.container.image parameter, specify the full image URL.

Important: the Space Packages registry must either belong to the same project where you configure a dev environment or be attached to this project.

schemaVersion: 2.2.0 attributes: space: instanceType: regular editor: type: Idea components: - name: ubuntu-container container: image: mycompany.registry.jetbrains.space/p/myprj/container/dev-image:latest

A dev environment can use a custom Dockerfile for its container image. The Dockerfile can be located anywhere in the project repository. Note that in this case, Space will build the image each time a user creates a new dev environment. To reduce startup time of the dev environment, we recommend that you build the image once and publish it to the project's Space Packages registry.

  1. Open the project source code and create a Dockerfile, for example, in the docker directory.

  2. Edit the Dockerfile to configure the image.

    For example, an image for a Java project:

    FROM ubuntu:20.04 ENV DEBIAN_FRONTEND=noninteractive ENV LC_ALL=C.UTF-8 RUN apt-get update RUN apt-get install -y \ git \ openjdk-11-jdk \ && rm -rf /var/lib/apt/lists/* ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
  3. Open the project source code and open the project's devfile. If it doesn't exist, create a new one, for example, .space/devfile.yaml.

  4. In the devfile, specify the path to a Dockerfile (uri) and, optionally, to the Docker context (buildContext). You must specify both paths relative to the projectRoot. For example:

    schemaVersion: 2.2.0 attributes: space: instanceType: large editor: type: Idea components: - name: image-build image: # (Required) imageName: my-image:latest dockerfile: # (Optional) path to Docker context relative to projectRoot # by default, projectRoot is repository root buildContext: docker # (Required) path to Dockerfile relative to projectRoot uri: docker/Dockerfile args: - 'ARG1=A' - 'ARG2=B'

  5. Commit and push the changes.

You can use images not only from Docker Hub but from any public registry that doesn't require authentication. In case of an image from Docker Hub, you can specify only the image name. For other registries, you must specify the full image URL.

schemaVersion: 2.2.0 attributes: space: instanceType: regular editor: type: Idea components: - name: openjdk-container container: # image from Docker Hub image: openjdk:latest

Specify a default dev environment instance type

Dev environments can run on three different virtual machine instances: regular (4 vCPUs, 8 GB), large (8 vCPUs, 16 GB), and extra large (16 vCPUs, 32 GB). Learn more about dev environments billing

To specify a default instance type, use the space.instanceType parameter. Users can choose another instance type when creating a dev environment.

schemaVersion: 2.2.0 attributes: space: # regular, large, xlarge instanceType: large editor: type: Idea

Set environment variables

To define environment variables in a dev environment container, use the components.container.env parameter.

schemaVersion: 2.2.0 attributes: space: instanceType: large editor: type: Idea components: - name: dev-container container: env: - name: VAR_A value: 'valueA' - name: VAR_B value: 'valueB'

When creating a new environment, you can view the added variables under Environment variables.

Env vars in dev environments

After you push the updated devfile to the project repository, the specified environment variables will be available only in the newly created dev environments.

Last modified: 04 March 2024