Skip to content

Commit

Permalink
docs: Update Bun language-specific guides
Browse files Browse the repository at this point in the history
  • Loading branch information
Pradumnasaraf committed Sep 30, 2024
1 parent 4ac5008 commit 2b92340
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
12 changes: 12 additions & 0 deletions content/guides/language/bun/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Check failure on line 14 in content/guides/language/bun/_index.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'Pradumna'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'Pradumna'?", "location": {"path": "content/guides/language/bun/_index.md", "range": {"start": {"line": 14, "column": 31}}}, "severity": "ERROR"}

Check failure on line 14 in content/guides/language/bun/_index.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'Saraf'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'Saraf'?", "location": {"path": "content/guides/language/bun/_index.md", "range": {"start": {"line": 14, "column": 40}}}, "severity": "ERROR"}
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.

Check warning on line 16 in content/guides/language/bun/_index.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Docker.We] Avoid using first-person plural like 'we'. Raw Output: {"message": "[Docker.We] Avoid using first-person plural like 'we'.", "location": {"path": "content/guides/language/bun/_index.md", "range": {"start": {"line": 16, "column": 172}}}, "severity": "WARNING"}

Check failure on line 16 in content/guides/language/bun/_index.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'Deno'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'Deno'?", "location": {"path": "content/guides/language/bun/_index.md", "range": {"start": {"line": 16, "column": 247}}}, "severity": "ERROR"}

## 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.
Expand Down
22 changes: 21 additions & 1 deletion content/guides/language/bun/containerize.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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).

Check warning on line 39 in content/guides/language/bun/containerize.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Docker.We] Avoid using first-person plural like 'we'. Raw Output: {"message": "[Docker.We] Avoid using first-person plural like 'we'.", "location": {"path": "content/guides/language/bun/containerize.md", "range": {"start": {"line": 39, "column": 76}}}, "severity": "WARNING"}

Check warning on line 39 in content/guides/language/bun/containerize.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Docker.We] Avoid using first-person plural like 'we'. Raw Output: {"message": "[Docker.We] Avoid using first-person plural like 'we'.", "location": {"path": "content/guides/language/bun/containerize.md", "range": {"start": {"line": 39, "column": 225}}}, "severity": "WARNING"}

```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.

Check warning on line 58 in content/guides/language/bun/containerize.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Docker.SentenceLength] Write short, concise sentences. (<=40 words) Raw Output: {"message": "[Docker.SentenceLength] Write short, concise sentences. (\u003c=40 words)", "location": {"path": "content/guides/language/bun/containerize.md", "range": {"start": {"line": 58, "column": 1}}}, "severity": "WARNING"}

Check warning on line 58 in content/guides/language/bun/containerize.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Docker.We] Avoid using first-person plural like 'we'. Raw Output: {"message": "[Docker.We] Avoid using first-person plural like 'we'.", "location": {"path": "content/guides/language/bun/containerize.md", "range": {"start": {"line": 58, "column": 79}}}, "severity": "WARNING"}

To learn more about the files in the repository, see the following:
- [Dockerfile](/reference/dockerfile.md)
- [.dockerignore](/reference/dockerfile.md#dockerignore-file)
Expand Down
2 changes: 1 addition & 1 deletion content/guides/language/bun/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 2b92340

Please sign in to comment.