Skip to content

Latest commit

Β 

History

History

README.md

Vite (vanilla)

This example demonstrates how to run a Vite project which executes via the vite program on top of the node runtime.

Note

This is not the most efficient way to run a Vite project! See httpserver-nginx-vite-vanilla for more details.

Initialization

The project was instantiated via:

npm create vite@latest my-vue-app -- --template vanilla

The accompanying Dockerfile and Kraftfile are necessary for deploying to Unikraft Cloud.

Deployment

To run this example, follow these steps:

  1. Install the CLI. Use the unikraft CLI or the legacy kraft CLI. You need a BuildKit builder. The easiest way to get one is via Docker. Alternatively, you can also directly set up and use BuildKit, see the 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 and cd into the examples/httpserver-node-vite-vanilla/ directory:

    git clone https://github.com/unikraft-cloud/examples
    cd examples/httpserver-node-vite-vanilla/

Make sure to log into Unikraft Cloud and pick a metro close to you. This guide uses fra (Frankfurt, πŸ‡©πŸ‡ͺ):

Using the unikraft CLI (Recommended)

unikraft login

or

Using the legacy kraft CLI

# Set Unikraft Cloud access token
export UKC_TOKEN=token
# Set metro to Frankfurt, DE
export UKC_METRO=fra

When done, run:

Using the unikraft CLI (Recommended)

unikraft build . --output <my-org>/httpserver-node-vite-vanilla:latest
unikraft run --metro fra \
  -m 4G \
  -p 443:8080/tls+http \
  --scale-to-zero policy=on,cooldown-time=2000,stateful=true \
  -e PWD=/app \
  --image <my-org>/httpserver-node-vite-vanilla:latest

or

Using the legacy kraft CLI

kraft cloud deploy \
  -M 4Gi \
  -p 443:8080/tls+http \
  --scale-to-zero on \
  --scale-to-zero-stateful \
  --scale-to-zero-cooldown 2s \
  -e PWD=/app \
  .

The output shows the instance address and other details:

Using the unikraft CLI (Recommended)

metro:        fra
name:         httpserver-node-vite-vanilla-w9f3p
uuid:         4d5e6f7a-8b9c-0d1e-2f3a-d4e5f6a7b8c9
state:        starting
image:        <my-org>/httpserver-node-vite-vanilla
resources:
  memory:     4096MiB
  vcpus:      1
service:
  uuid:       5e6f7a8b-9c0d-1e2f-3a4b-e5f6a7b8c9d0
  name:       bold-rain-mv5tx8wy
  domains:
  - fqdn:     bold-rain-mv5tx8wy.fra.unikraft.app
networks:
- uuid:       6f7a8b9c-0d1e-2f3a-4b5c-f6a7b8c9d0e1
  private-ip: 10.0.5.2
  mac:        12:b0:6c:3e:ab:95
timestamps:
  created:    just now

or

Using the legacy kraft CLI

[●] Deployed successfully!
 β”‚
 β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€ name: httpserver-node-vite-vanilla-w9f3p
 β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€ uuid: 4d5e6f7a-8b9c-0d1e-2f3a-d4e5f6a7b8c9
 β”œβ”€β”€β”€β”€β”€β”€β”€β”€ metro: https://api.fra.unikraft.cloud/v1
 β”œβ”€β”€β”€β”€β”€β”€β”€β”€ state: starting
 β”œβ”€β”€β”€β”€β”€β”€β”€ domain: https://bold-rain-mv5tx8wy.fra.unikraft.app
 β”œβ”€β”€β”€β”€β”€β”€β”€β”€ image: oci://unikraft.io/<my-org>/httpserver-node-vite-vanilla@sha256:5a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b
 β”œβ”€β”€β”€β”€β”€β”€β”€ memory: 4096 MiB
 β”œβ”€β”€β”€β”€β”€β”€ service: bold-rain-mv5tx8wy
 β”œβ”€ private fqdn: httpserver-node-vite-vanilla-w9f3p.internal
 └─── private ip: 10.0.5.2

In this case, the instance name is httpserver-node-vite-vanilla-w9f3p and the address is https://bold-rain-mv5tx8wy.fra.unikraft.app. They're different for each run.

After deploying, you can query the service using the provided URL.

You can list information about the instance by running:

Using the unikraft CLI (Recommended)

unikraft instances list
METRO  NAME                                STATE    IMAGE                                  ARGS  MEMORY   VCPUS  FQDN                                 CREATED
fra    httpserver-node-vite-vanilla-w9f3p  running  <my-org>/httpserver-node-vite-vanilla        4096MiB  1      bold-rain-mv5tx8wy.fra.unikraft.app  2 minutes ago

or

Using the legacy kraft CLI

kraft cloud instance list
NAME                                FQDN                                 STATE    STATUS        IMAGE                                                               MEMORY  VCPUS  ARGS  BOOT TIME
httpserver-node-vite-vanilla-w9f3p  bold-rain-mv5tx8wy.fra.unikraft.app  running  1 minute ago  oci://unikraft.io/<my-org>/httpserver-node-vite-vanilla@sha256:...  4 GiB   1            91.27 ms

When done, you can remove the instance:

Using the unikraft CLI (Recommended)

unikraft instances delete <instance-name>

or

Using the legacy kraft CLI

kraft cloud instance remove <instance-name>

Learn more

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

Using the unikraft CLI (Recommended)

unikraft --help

or

Using the legacy kraft CLI

kraft cloud --help

Or visit the CLI Reference or the legacy CLI Reference.