# Visual Studio Code Server

import { Tabs, TabsContent, TabsList, TabsTrigger } from "zudoku/ui/Tabs"

{/* vale off */}
{/* THIS FILE WAS AUTOGENERATED FROM THE PUBLIC EXAMPLE REPOSITORY. DO NOT EDIT THIS FILE DIRECTLY. */}


[Visual Studio Code](https://code.visualstudio.com/) is a source-code editor developed by Microsoft.
It includes support for debugging, syntax highlighting, intelligent code completion, snippets, code refactoring, and embedded Git.
It features a [Code server](https://code.visualstudio.com/docs/remote/vscode-server), which allows you to run Visual Studio Code remotely and access it through a web browser or your local Visual Studio Code client.

This guide explains how to create and deploy a Visual Studio Code server app.
To run it, follow these steps:

1. Install the CLI.
   Use the [unikraft CLI](/cli/unikraft) or the legacy [kraft CLI](https://unikraft.org/docs/cli/install).
   You need a [BuildKit](https://github.com/moby/buildkit) builder. The easiest way to get one is via [Docker](https://docs.docker.com/engine/install/).
   Alternatively, you can also directly set up and use BuildKit, see the [quick start](https://github.com/moby/buildkit#quick-start).

:::note
The unikraft CLI is the current standard, while kraft is the legacy version.
Choose one of the CLIs below and only run the commands associated with it for the rest of this guide.
:::

2. Clone the [`examples` repository](https://github.com/unikraft-cloud/examples) and `cd` into the `examples/visual-studio-code-server` directory:

```bash
git clone https://github.com/unikraft-cloud/examples
cd examples/visual-studio-code-server/
```

Make sure to log into Unikraft Cloud and pick a [metro](/platform/metros) close to you.
This guide uses `fra` (Frankfurt, 🇩🇪):

<CodeTabs syncKey="cli">

```bash title="unikraft"
unikraft login
```

```bash title="kraft"
# Set Unikraft Cloud access token
export UKC_TOKEN=token
# Set metro to Frankfurt, DE
export UKC_METRO=fra
```

</CodeTabs>

When done, invoke the following command to deploy this app on Unikraft Cloud:

<CodeTabs syncKey="cli">

```bash title="unikraft"
unikraft volume create --set metro=fra --set name=code-workspace --set size=1G

unikraft build . --output <my-org>/visual-studio-code-server:latest
unikraft run --metro fra -p 443:8443/tls+http -m 2G --volume code-workspace:/workspace --scale-to-zero policy=on,cooldown-time=4000,stateful=true -e PGUID=0 -e PGID=0 -e PASSWORD=unikraft -e SUDO_PASSWORD=unikraft -e DEFAULT_WORKSPACE="/workspace" --image <my-org>/visual-studio-code-server:latest
```

```bash title="kraft"
kraft cloud volume create --name code-workspace --size 1Gi

kraft cloud deploy --scale-to-zero on --scale-to-zero-stateful --scale-to-zero-cooldown 4s --name code-server -p 443:8443/tls+http -M 2Gi -v code-workspace:/workspace -e PGUID=0 -e PGID=0 -e PASSWORD=unikraft -e SUDO_PASSWORD=unikraft -e DEFAULT_WORKSPACE="/workspace" .
```

</CodeTabs>

The output shows the instance address and other details:

<CodeTabs syncKey="cli">

```ansi title="unikraft"
metro:        fra
name:         code-server
uuid:         c1a619a0-e222-4042-94b8-ba4b39353417
state:        [92mstarting[0m
image:        <my-org>/visual-studio-code-server
resources:
  memory:     2048MiB
  vcpus:      1
service:
  uuid:       4a0866e4-3bec-3666-c4aa-61672de542e2
  name:       blue-shape-chmxf1g4
  domains:
  - fqdn:     blue-shape-chmxf1g4.fra.unikraft.app
networks:
- uuid:       dcec209f-31a6-b355-a88e-f5ac3edfa20e
  private-ip: 10.0.0.49
  mac:        12:b0:ec:d2:df:1c
timestamps:
  created:    just now
```

```ansi title="kraft"
[90m[[0m[92m●[0m[90m][0m Deployed successfully!
 [90m│[0m
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mname[0m: code-server
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90muuid[0m: c1a619a0-e222-4042-94b8-ba4b39353417
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mmetro[0m: https://api.fra.unikraft.cloud/v1
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mstate[0m: [92mstarting[0m
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mdomain[0m: https://blue-shape-chmxf1g4.fra.unikraft.app
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mimage[0m: oci://unikraft.io/<my-org>/visual-studio-code-server@sha256:633ec8a8dcb342b093c6f055f84fc056ee1abe40ff56e98bd612c4b9d4ddffcb
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mmemory[0m: 2048 MiB
 [90m├[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m[90m─[0m [90mservice[0m: blue-shape-chmxf1g4
 [90m├[0m[90m─[0m [90mprivate fqdn[0m: code-server.internal
 [90m└[0m[90m─[0m[90m─[0m[90m─[0m [90mprivate ip[0m: 10.0.0.49
```

</CodeTabs>

This will create a volume for data persistence, and mount it at `/workspace` inside the VM.

In this case, the instance name is `code-server` and the address is `https://blue-shape-chmxf1g4.fra.unikraft.app`.
The name was preset, but the address is different for each run.
Enter the provided address into your browser of choice to access the Code server instance.

You can list information about the volume by running:

<CodeTabs syncKey="cli">

```bash title="unikraft"
unikraft volumes list
```

```bash title="kraft"
kraft cloud volume list
```

</CodeTabs>

<CodeTabs syncKey="cli">

```ansi title="unikraft"
[1mMETRO[0m  [1mNAME[0m            [1mSTATE[0m    [1mSIZE[0m    [1mCREATED[0m
fra    code-workspace  [92mmounted[0m  1.0GiB  13 minutes ago
```

```ansi title="kraft"
[1mNAME[0m            [1mCREATED AT[0m      [1mSIZE[0m     [1mATTACHED TO[0m  [1mMOUNTED BY[0m   [1mSTATE[0m      [1mPERSISTENT[0m
code-workspace  13 minutes ago  1.0 GiB  code-server  code-server  [92mmounted[0m    true
```

</CodeTabs>

You can list information about the instance by running:

<CodeTabs syncKey="cli">

```bash title="unikraft"
unikraft instances list
```

```bash title="kraft"
kraft cloud instance list
```

</CodeTabs>

<CodeTabs syncKey="cli">

```ansi title="unikraft"
[1mMETRO[0m  [1mNAME[0m         [1mSTATE[0m    [1mIMAGE[0m                               [1mARGS[0m  [1mMEMORY[0m  [1mVCPUS[0m  [1mFQDN[0m                                  [1mCREATED[0m
fra    code-server  [94mstandby[0m  <my-org>/visual-studio-code-server        2.0GiB  1      blue-shape-chmxf1g4.fra.unikraft.app  2 minutes ago
```

```ansi title="kraft"
[1mNAME[0m         [1mFQDN[0m                                  [1mSTATE[0m    [1mSTATUS[0m   [1mIMAGE[0m                                                            [1mMEMORY[0m   [1mVCPUS[0m  [1mARGS[0m  [1mBOOT TIME[0m
code-server  blue-shape-chmxf1g4.fra.unikraft.app  [94mstandby[0m  standby  oci://unikraft.io/<my-org>/visual-studio-code-server@sha256:...  2.0 GiB  1            8.45 ms
```

</CodeTabs>

When done, you can remove the instance:

<CodeTabs syncKey="cli">

```bash title="unikraft"
unikraft instances delete code-server
```

```bash title="kraft"
kraft cloud instance remove code-server
```

</CodeTabs>

The volume isn't removed by default, so you can recreate the instance and still have access to your old data.
Remove it using:

<CodeTabs syncKey="cli">

```bash title="unikraft"
unikraft volume delete code-workspace
```

```bash title="kraft"
kraft cloud volume remove code-workspace
```

</CodeTabs>

## Learn more

Use the `--help` option for detailed information on using Unikraft Cloud:

<CodeTabs syncKey="cli">

```bash title="unikraft"
unikraft --help
```

```bash title="kraft"
kraft cloud --help
```

</CodeTabs>

Or visit the [CLI Reference](/cli/unikraft) or the [legacy CLI Reference](/cli/kraft/overview).
{/* vale on */}
