From 2b923405c2b1ed2907728b3682b8e39350354755 Mon Sep 17 00:00:00 2001 From: Pradumna Saraf Date: Mon, 30 Sep 2024 13:39:54 +0530 Subject: [PATCH] docs: Update Bun language-specific guides --- content/guides/language/bun/_index.md | 12 +++++++++++ content/guides/language/bun/containerize.md | 22 ++++++++++++++++++++- content/guides/language/bun/develop.md | 2 +- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/content/guides/language/bun/_index.md b/content/guides/language/bun/_index.md index 8d9a0717c8e8..bbd67308a40a 100644 --- a/content/guides/language/bun/_index.md +++ b/content/guides/language/bun/_index.md @@ -13,11 +13,23 @@ The Bun getting started guide teaches you how to create a containerized Bun appl > > Docker would like to thank [Pradumna Saraf](https://twitter.com/pradumna_saraf) for his contribution to this guide. +Like Node.js, Bun is a JavaScript runtime that is designed to run on the server. Bun is a comparatively lightweight runtime that is designed to be fast and efficient. Now we have a options in the JavaScript ecosystem to choose from like Node.js, Deno, and Bun. + +## Why develop with Bun and Docker? + +It's great to have multiple options in the JavaScript ecosystem to choose from. But as the number of runtimes increases, it becomes challenging to manage the different runtimes and their dependencies. This is where Docker comes in. Creating and destroying containers on demand is a great way to manage the different runtimes and their dependencies. Also, as it's fairly a new runtime, getting a consistent development environment for Bun can be challenging. Docker can help you set up a consistent development environment for Bun. + +## What will you learn? + * Containerize and run a Bun application using Docker * Set up a local environment to develop a Bun application using containers * Configure a CI/CD pipeline for a containerized Bun application using GitHub Actions * Deploy your containerized application locally to Kubernetes to test and debug your deployment +## Prerequisites + +Some basic understanding of Bun and JavaScript is assumed. If you are new to the runtime, the [Bun website](https://bun.sh/) is a great place to explore. You must have familiarity with Docker concepts like containers, images, and Dockerfiles. If you are new to Docker, you can start with the [Docker basics](/get-started/docker-concepts/the-basics/what-is-a-container.md) guide. + After completing the Bun getting started modules, you should be able to containerize your own Bun application based on the examples and instructions provided in this guide. Start by containerizing an existing Bun application. diff --git a/content/guides/language/bun/containerize.md b/content/guides/language/bun/containerize.md index 72513232385b..0a3621e15e5a 100644 --- a/content/guides/language/bun/containerize.md +++ b/content/guides/language/bun/containerize.md @@ -21,7 +21,7 @@ This section walks you through containerizing and running a Bun application. Clone the sample application to use with this guide. Open a terminal, change directory to a directory that you want to work in, and run the following command to clone the repository: ```console -$ git clone https://github.com/PradumnaSaraf/bun-docker.git +$ git clone https://github.com/Pradumnasaraf/bun-docker.git ``` You should now have the following contents in your `bun-docker` @@ -34,9 +34,29 @@ directory. │ ├── LICENSE │ ├── server.js │ └── README.md +``` + +In the Dockerfile if you look closely, you will see in `FROM` instruction, we are using `oven/bun` as the base image instead of `bun`. This is because the official DOCKER image for Bun is not available yet, unlike Node. So, we are using the `oven/bun` image which is a custom image created by the company itself. This image is available on the Docker Hub. You can find the image [here](https://hub.docker.com/r/oven/bun). + +```dockerfile +# Use the Bun image as the base image +FROM oven/bun:latest + +# Set the working directory in the container +WORKDIR /app +# Copy the current directory contents into the container at /app +COPY . . + +# Expose the port on which the API will listen +EXPOSE 3000 + +# Run the server when the container launches +CMD ["bun", "server.js"] ``` +To give you a brief overview of Dockerfile apart from the `FROM` instruction, we are setting the working directory in the container to `/app`, copying the contents of the current directory to the `/app` directory in the container, exposing the port 3000, so that the API can be accessed from outside the container, and finally running the server when the container launches. + To learn more about the files in the repository, see the following: - [Dockerfile](/reference/dockerfile.md) - [.dockerignore](/reference/dockerfile.md#dockerignore-file) diff --git a/content/guides/language/bun/develop.md b/content/guides/language/bun/develop.md index a02220636141..0b917a401cae 100644 --- a/content/guides/language/bun/develop.md +++ b/content/guides/language/bun/develop.md @@ -57,7 +57,7 @@ $ docker compose watch Now, if you modify your `server.js` you will see the changes in real time without re-building the image. -To test it out, open the `server.js` file in your favorite text editor and change the message from `{"Status" : "OK"}` to `{"Status" : "Updated"}`. Save the file and refresh your browser at [http://localhost:3000](http://localhost:3000). You should see the updated message. +To test it out, open the `server.js` file in your favorite text editor and change the message from `{"Status" : "OK"}` to `{"Status" : "Updated"}`. Save the file and refresh your browser at `http://localhost:3000`. You should see the updated message. Press `ctrl+c` in the terminal to stop your application.