Run a Bun app
In this guide we create and deploy a Bun app. To run this example, follow these steps:
-
Install the
kraft
CLI tool and a container runtime engine, e.g. Docker. -
Clone the
examples
repository andcd
into theexamples/bun
directory:
Make sure to log into Unikraft Cloud by setting your token and a metro close to you.
We use fra0
(Frankfurt, 🇩🇪) in this guide:
When done, invoke the following command to deploy the application on Unikraft Cloud:
The output shows the instance URL and other details:
In this case, the instance name is bun-700mp
and the URL is https://quiet-pond-ao44imcg.fra0.kraft.host
.
They are different for each run.
Use curl
to query the Unikraft Cloud instance of the Bun instance:
At any point in time, you can list information about the instance:
When done, you can remove the instance:
Customize your Application
To customize the application, update the files in the repository, listed below:
Kraftfile
: the Unikraft Cloud specificationDockerfile
: the Docker-specified application filesystemserver.ts
: the Bun server implementation
Lines in the Kraftfile
have the following roles:
-
spec: v0.6
: The currentKraftfile
specification version is0.6
. -
runtime: base-compat:latest
: The kernel to use. -
rootfs: ./Dockerfile
: Build the application root filesystem using theDockerfile
. -
cmd: ["/usr/bin/bun", "run", "/usr/src/server.ts"]
: Use/usr/bin/bun run /usr/src/server.ts
as the starting command of the instance.
Lines in the Dockerfile
have the following roles:
-
FROM scratch
: Build the filesystem from thescratch
container image, to create a base image. -
COPY ...
: Copy required files to the application filesystem: thebun
binary executable, libraries, configuration files, the/usr/src/server.ts
implementation. -
RUN ...
: Run specific commands to generate or to prepare the filesystem contents.
The following options are available for customizing the application:
-
If only updating the implementation in the
server.ts
source file, no other change is required. -
If you want to add additional files, you need to copy them into the filesystem using the
COPY
command in theDockerfile
. -
If you want to replace
server.ts
with a different source file, update thecmd
line in theKraftfile
and replace/usr/src/server.ts
with the path to your new source file. -
More extensive changes may require extending the
Dockerfile
with additionalDockerfile
commands.
Learn More
Use the --help
option for detailed information on using Unikraft Cloud:
Or visit the CLI Reference.