-
Notifications
You must be signed in to change notification settings - Fork 8k
docs: Add language-specific guide for Deno runtime #21893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
935c0d4
9e5c09a
aee0079
996ff65
139fce8
223d348
74e0931
1885626
79fd794
75a7f4e
f7014d3
62f8262
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| --- | ||
| description: Containerize and develop Deno applications using Docker. | ||
| keywords: getting started, deno | ||
| title: Deno language-specific guide | ||
| summary: | | ||
| Learn how to containerize JavaScript applications with the Deno runtime using Docker. | ||
| linkTitle: Deno | ||
| languages: [js] | ||
| params: | ||
| time: 10 minutes | ||
| --- | ||
|
|
||
| The Deno getting started guide teaches you how to create a containerized Deno application using Docker. In this guide, you'll learn how to: | ||
|
Check failure on line 13 in content/guides/deno/_index.md
|
||
|
|
||
| > **Acknowledgment** | ||
| > | ||
| > Docker would like to thank [Pradumna Saraf](https://twitter.com/pradumna_saraf) for his contribution to this guide. | ||
|
Check failure on line 17 in content/guides/deno/_index.md
|
||
| ## What will you learn? | ||
|
|
||
| * Containerize and run a Deno application using Docker | ||
|
Check failure on line 21 in content/guides/deno/_index.md
|
||
| * Set up a local environment to develop a Deno application using containers | ||
|
Check failure on line 22 in content/guides/deno/_index.md
|
||
| * Use Docker Compose to run the application. | ||
| * Configure a CI/CD pipeline for a containerized Deno application using GitHub Actions | ||
|
Check warning on line 24 in content/guides/deno/_index.md
|
||
| * Deploy your containerized application locally to Kubernetes to test and debug your deployment | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Basic understanding of JavaScript is assumed. | ||
| - 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 Deno getting started modules, you should be able to containerize your own Deno application based on the examples and instructions provided in this guide. | ||
|
Check failure on line 32 in content/guides/deno/_index.md
|
||
|
|
||
| Start by containerizing an existing Deno application. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| --- | ||
| title: Configure CI/CD for your Deno application | ||
| linkTitle: Configure CI/CD | ||
| weight: 40 | ||
| keywords: ci/cd, github actions, deno, shiny | ||
| description: Learn how to configure CI/CD using GitHub Actions for your Deno application. | ||
| aliases: | ||
| - /language/deno/configure-ci-cd/ | ||
| --- | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| Complete all the previous sections of this guide, starting with [Containerize a Deno 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 | ||
| `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). | ||
|
|
||
| ## 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 Deno 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. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| --- | ||
| title: Containerize a Deno application | ||
| linkTitle: Containerize your app | ||
| weight: 10 | ||
| keywords: deno, containerize, initialize | ||
| description: Learn how to containerize a Deno application. | ||
| aliases: | ||
| - /language/deno/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 | ||
|
|
||
| For a long time, Node.js has been the go-to runtime for server-side JavaScript applications. However, recent years have introduced new alternative runtimes, including [Deno](https://deno.land/). Like Node.js, Deno is a JavaScript and TypeScript runtime, but it takes a fresh approach with modern security features, a built-in standard library, and native support for TypeScript. | ||
|
|
||
| Why develop Deno applications with Docker? Having a choice of runtimes is exciting, but managing multiple runtimes and their dependencies consistently across environments can be tricky. This is where Docker proves invaluable. Using containers to create and destroy environments on demand simplifies runtime management and ensures consistency. Additionally, as Deno continues to grow and evolve, Docker helps establish a reliable and reproducible development environment, minimizing setup challenges and streamlining the workflow. | ||
|
|
||
| ## 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/dockersamples/deno-docker.git | ||
craig-osterhout marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| You should now have the following contents in your `deno-docker` directory. | ||
|
|
||
| ```text | ||
| ├── deno-docker/ | ||
| │ ├── compose.yml | ||
| │ ├── Dockerfile | ||
| │ ├── LICENSE | ||
| │ ├── server.ts | ||
| │ └── README.md | ||
| ``` | ||
|
|
||
| ## Understand the sample application | ||
|
|
||
| The sample application is a simple Deno application that uses the Oak framework to create a simple API that returns a JSON response. The application listens on port 8000 and returns a message `{"Status" : "OK"}` when you access the application in a browser. | ||
|
|
||
| ```typescript | ||
| // server.ts | ||
| import { Application, Router } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
|
||
| const app = new Application(); | ||
| const router = new Router(); | ||
|
|
||
| // Define a route that returns JSON | ||
| router.get("/", (context) => { | ||
| context.response.body = { Status: "OK" }; | ||
| context.response.type = "application/json"; | ||
| }); | ||
|
|
||
| app.use(router.routes()); | ||
| app.use(router.allowedMethods()); | ||
|
|
||
| console.log("Server running on http://localhost:8000"); | ||
| await app.listen({ port: 8000 }); | ||
| ``` | ||
|
|
||
| ## Create a Dockerfile | ||
|
|
||
| In the Dockerfile, you'll notice that the `FROM` instruction uses `denoland/deno:latest` | ||
| as the base image. This is the official image for Deno. This image is [available on the Docker Hub](https://hub.docker.com/r/denoland/deno). | ||
|
|
||
| ```dockerfile | ||
| # Use the official Deno image | ||
| FROM denoland/deno:latest | ||
|
|
||
| # Set the working directory | ||
| WORKDIR /app | ||
|
|
||
| # Copy server code into the container | ||
| COPY server.ts . | ||
|
|
||
| # Set permissions (optional but recommended for security) | ||
| USER deno | ||
|
|
||
| # Expose port 8000 | ||
| EXPOSE 8000 | ||
|
|
||
| # Run the Deno server | ||
| CMD ["run", "--allow-net", "server.ts"] | ||
| ``` | ||
|
|
||
| Aside from specifying `denoland/deno:latest` as the base image, the Dockerfile | ||
Pradumnasaraf marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - Sets the working directory in the container to `/app` | ||
Pradumnasaraf marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - Copies `server.ts` into the container. | ||
| - Sets the user to `deno` to run the application as a non-root user. | ||
| - Exposes port 8000 to allow traffic to the application. | ||
|
Check warning on line 96 in content/guides/deno/containerize.md
|
||
| - Runs the Deno server using the `CMD` instruction. | ||
| - The `--allow-net` flag is used to allow network access to the application. The `server.ts` file uses the Oak framework to create a simple API that listens on port 8000. | ||
|
Check warning on line 98 in content/guides/deno/containerize.md
|
||
Pradumnasaraf marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Run the application | ||
|
|
||
| Make sure you are in the `deno-docker` directory. Run the following command in a terminal to build and run the application. | ||
|
|
||
| ```console | ||
| $ docker compose up --build | ||
| ``` | ||
|
|
||
| Open a browser and view the application at [http://localhost:8000](http://localhost:8000). 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 `deno-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:8000](http://localhost:8000). | ||
|
|
||
|
|
||
| In the terminal, run the following command to stop the application. | ||
|
|
||
| ```console | ||
| $ docker compose down | ||
| ``` | ||
|
|
||
| ## Summary | ||
|
|
||
| In this section, you learned how you can containerize and run your Deno | ||
| application using Docker. | ||
|
|
||
| Related information: | ||
|
|
||
| - [Dockerfile reference](/reference/dockerfile.md) | ||
| - [.dockerignore file](/reference/dockerfile.md#dockerignore-file) | ||
| - [Docker Compose overview](/manuals/compose/_index.md) | ||
| - [Compose file reference](/reference/compose-file/_index.md) | ||
|
|
||
| ## Next steps | ||
|
|
||
| In the next section, you'll learn how you can develop your application using | ||
| containers. | ||
Uh oh!
There was an error while loading. Please reload this page.