Skip to content

Commit

Permalink
docs: add Bun language-specific guide
Browse files Browse the repository at this point in the history
  • Loading branch information
Pradumnasaraf committed Sep 19, 2024
1 parent 71c4fe8 commit e4246ad
Show file tree
Hide file tree
Showing 8 changed files with 475 additions and 2 deletions.
5 changes: 4 additions & 1 deletion content/guides/language/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description: Language-specific guides overview
linkTitle: Language-specific guides
weight: 10
keywords: guides, docker, language, node, java, python, R, go, golang, .net, c++
keywords: guides, docker, language, node, java, python, R, go, golang, .net, c++, bun
title: Language-specific guides overview
toc_min: 1
toc_max: 2
Expand All @@ -29,6 +29,9 @@ Learn how to containerize your applications and start developing using Docker. C
<div class="grid grid-cols-2 md:grid-cols-3 h-auto gap-4">
<div class="flex items-center flex-1 shadow p-4">
<a href="/guides/language/nodejs/"><img class="m-auto rounded" src="/guides/language/images/nodejs.webp" alt="Develop with Node"></a>
</div>
<div class="flex items-center flex-1 shadow p-4">
<a href="/guides/language/bun/"><img class="m-auto rounded" src="/guides/language/images/bun.webp" alt="Develop with Bun"></a>
</div>
<div class="flex items-center flex-1 shadow p-4">
<a href="/guides/language/python/"><img class="m-auto rounded" src="/guides/language/images/python.webp" alt="Develop with Python"></a>
Expand Down
27 changes: 27 additions & 0 deletions content/guides/language/bun/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
description: Containerize and develop Bun applications using Docker.
keywords: getting started, bun
title: Bun language-specific guide
linkTitle: Bun
toc_min: 1
toc_max: 2
aliases:
- /language/bun/
---

The Bun getting started guide teaches you how to create a containerized Bun application using Docker. In this guide, you'll learn how to:

> **Acknowledgment**
>
> Docker would like to thank [Pradumna Saraf](https://twitter.com/pradumna_saraf) for his contribution to this guide.

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 'Pradumna'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'Pradumna'?", "location": {"path": "content/guides/language/bun/_index.md", "range": {"start": {"line": 16, "column": 31}}}, "severity": "ERROR"}

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

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.

{{< button text="Containerize a Bun app" url="containerize.md" >}}

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

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Docker.RecommendedWords] Consider using 'URL' instead of 'url' Raw Output: {"message": "[Docker.RecommendedWords] Consider using 'URL' instead of 'url'", "location": {"path": "content/guides/language/bun/_index.md", "range": {"start": {"line": 27, "column": 42}}}, "severity": "INFO"}
133 changes: 133 additions & 0 deletions content/guides/language/bun/configure-ci-cd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
---
title: Configure CI/CD for your Bun application
linkTitle: Configure CI/CD
weight: 40
keywords: ci/cd, github actions, bun, shiny
description: Learn how to configure CI/CD using GitHub Actions for your Bun application.
aliases:
- /language/dotnet/configure-ci-cd/
---

## Prerequisites

Complete all the previous sections of this guide, starting with [Containerize a Bun application](containerize.md). You must have a [GitHub](https://github.com/signup) account and a [Docker](https://hub.docker.com/signup) account to complete this section.

## Overview

In this section, you'll learn how to set up and use GitHub Actions to build and test your Docker image as well as push it to Docker Hub. You will complete the following steps:

1. Create a new repository on GitHub.
2. Define the GitHub Actions workflow.
3. Run the workflow.

## Step one: Create the repository

Create a GitHub repository, configure the Docker Hub credentials, and push your source code.

1. [Create a new repository](https://github.com/new) on GitHub.

2. Open the repository **Settings**, and go to **Secrets and variables** >
**Actions**.

3. Create a new **Repository variable** named `DOCKER_USERNAME` and your Docker ID as value.

4. Create a new [Personal Access Token (PAT)](/manuals/security/for-developers/access-tokens.md#create-an-access-token)for Docker Hub. You can name this token `docker-tutorial`. Make sure access permissions include Read and Write.

5. Add the PAT as a **Repository secret** in your GitHub repository, with the name

Check warning on line 36 in content/guides/language/bun/configure-ci-cd.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Docker.Acronyms] ' PAT' has no definition. Raw Output: {"message": "[Docker.Acronyms] ' PAT' has no definition.", "location": {"path": "content/guides/language/bun/configure-ci-cd.md", "range": {"start": {"line": 36, "column": 11}}}, "severity": "WARNING"}
`DOCKERHUB_TOKEN`.

6. In your local repository on your machine, run the following command to change
the origin to the repository you just created. Make sure you change
`your-username` to your GitHub username and `your-repository` to the name of
the repository you created.

```console
$ git remote set-url origin https://github.com/your-username/your-repository.git
```

7. Run the following commands to stage, commit, and push your local repository to GitHub.

```console
$ git add -A
$ git commit -m "my commit"
$ git push -u origin main
```

## Step two: Set up the workflow

Set up your GitHub Actions workflow for building, testing, and pushing the image
to Docker Hub.

1. Go to your repository on GitHub and then select the **Actions** tab.

2. Select **set up a workflow yourself**.

This takes you to a page for creating a new GitHub actions workflow file in
your repository, under `.github/workflows/main.yml` by default.

3. In the editor window, copy and paste the following YAML configuration and commit the changes.

```yaml
name: ci
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Build and push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ vars.DOCKER_USERNAME }}/${{ github.event.repository.name }}:latest
```

For more information about the YAML syntax for `docker/build-push-action`,
refer to the [GitHub Action README](https://github.com/docker/build-push-action/blob/master/README.md).

Check warning on line 101 in content/guides/language/bun/configure-ci-cd.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Docker.Acronyms] 'README' has no definition. Raw Output: {"message": "[Docker.Acronyms] 'README' has no definition.", "location": {"path": "content/guides/language/bun/configure-ci-cd.md", "range": {"start": {"line": 101, "column": 32}}}, "severity": "WARNING"}

## Step three: Run the workflow

Save the workflow file and run the job.

1. Select **Commit changes...** and push the changes to the `main` branch.

After pushing the commit, the workflow starts automatically.

2. Go to the **Actions** tab. It displays the workflow.

Selecting the workflow shows you the breakdown of all the steps.

3. When the workflow is complete, go to your
[repositories on Docker Hub](https://hub.docker.com/repositories).

If you see the new repository in that list, it means the GitHub Actions
successfully pushed the image to Docker Hub.

## Summary

In this section, you learned how to set up a GitHub Actions workflow for your Bun application.

Related information:
- [Introduction to GitHub Actions](/manuals/build/ci/github-actions/_index.md)
- [Workflow syntax for GitHub Actions](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions)

## Next steps

Next, learn how you can locally test and debug your workloads on Kubernetes before deploying.

{{< button text="Test your deployment" url="./deploy.md" >}}
93 changes: 93 additions & 0 deletions content/guides/language/bun/containerize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
title: Containerize a Bun application
linkTitle: Containerize your app
weight: 10
keywords: bun, containerize, initialize
description: Learn how to containerize a Bun application.
aliases:
- /language/bun/containerize/
---

## Prerequisites

* You have a [Git client](https://git-scm.com/downloads). The examples in this section use a command-line based Git client, but you can use any client.

## Overview

This section walks you through containerizing and running a Bun application.

## Get the sample 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
```

You should now have the following contents in your `bun-docker`
directory.

```text
├── bun-docker/
│ ├── compose.yml
│ ├── Dockerfile
│ ├── LICENSE
│ ├── server.js
│ └── README.md
```

To learn more about the files in the repository, see the following:
- [Dockerfile](/reference/dockerfile.md)
- [.dockerignore](/reference/dockerfile.md#dockerignore-file)
- [compose.yml](/reference/compose-file/_index.md)

## Run the application

Inside the `bun-docker` directory, run the following command in a
terminal.

```console
$ docker compose up --build
```

Open a browser and view the application at [http://localhost:3000](http://localhost:3000). You will see a message `{"Status" : "OK"}` in the browser.

In the terminal, press `ctrl`+`c` to stop the application.

### Run the application in the background

You can run the application detached from the terminal by adding the `-d`
option. Inside the `bun-docker` directory, run the following command
in a terminal.

```console
$ docker compose up --build -d
```

Open a browser and view the application at [http://localhost:8080](http://localhost:8080).


In the terminal, run the following command to stop the application.

```console
$ docker compose down
```

For more information about Compose commands, see the [Compose CLI
reference](/reference/cli/docker/compose/_index.md).

## Summary

In this section, you learned how you can containerize and run your Bun
application using Docker.

Related information:
- [Docker Compose overview](/manuals/compose/_index.md)

## Next steps

In the next section, you'll learn how you can develop your application using
containers.

{{< button text="Develop your application" url="develop.md" >}}
Loading

0 comments on commit e4246ad

Please sign in to comment.