Skip to content

Commit

Permalink
nevi edits to anni's builds PR (#16962)
Browse files Browse the repository at this point in the history
* nevi edits to anni's builds PR

* 9-20 changes
  • Loading branch information
nevikashah authored Sep 20, 2024
1 parent f352b67 commit 2a9515e
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 201 deletions.
64 changes: 64 additions & 0 deletions src/content/docs/workers/ci-cd/builds/advanced-setups.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
pcx_content_type: reference
title: Advanced Setups
description: Learn how to use Workers Builds with more advanced setups
sidebar:
order: 5
---

## Monorepos
While the Workers Builds beta has limited support for monorepos, it is still possible to set up a monorepo workflow. In the dashboard, you must connect your monorepo to each of the existing Worker projects. When a new commit is detected in the monorepo, a new build/deploy will trigger for each Worker.

### Example

In the example `ecommerce-monorepo`, a Workers project should be created for `product-service`, `auth-service`, `order-service`, and `notification-service`.

A git connection to `ecommerce-monorepo` should be added in all of the Workers projects. If you are using a monorepo tool (e.g. [Turborepo](https://turbo.build/)), you can configure a different deploy command for each Worker (e.g. `turbo deploy -F product-service`). When a new commit is made to `ecommerce-monorepo`, a build and deploy will be triggered for each of the Workers (i.e. `product-service`, `auth-service`, `order-service`, `notification-service`) and respect the configured commands for that Worker.

```
ecommerce-monorepo/
├── workers/
│ ├── product-service/
│ │ ├── src/
│ │ └── wrangler.toml
│ ├── auth-service/
│ │ ├── src/
│ │ └── wrangler.toml
│ ├── order-service/
│ │ ├── src/
│ │ └── wrangler.toml
│ └── notification-service/
│ ├── src/
│ └── wrangler.toml
├── shared/
│ └── utils/
└── README.md
```

## Wrangler environments
If you are using [Wrangler Environments](/workers/wrangler/environments/), you can choose to continue using with Workers Builds with a bit of set up:

1. [Deploy via Wrangler](/workers/wrangler/commands/deploy) to create the Workers for your environments in the Dashboard, if you don't already have them.
2. Find the Workers for your environments. They are typically named `[name of Worker] - [environment name]`.
3. Connect your repository to each of the Workers for your environment.
4. In each of the Workers, edit your Wrangler deploy command to include the flag `--env: <environment name>` in the build configurations.

When a new commit is detected in the repository, a new build/deploy will trigger for each associated Worker.

### Example

Imagine you have a Worker named `my-worker`, and you want to set up two environments `staging` and `production` set in the `wrangler.toml`. If you haven't already, you can deploy `my-worker` for each environment using the commands `wrangler deploy --env staging` and `wrangler deploy --env production`.

In your Cloudflare Dashboard, you should find two Workers `my-worker-staging` and `my-worker-production`. A git connection to a `my-worker` git repository should be added to both of the environment Workers. In the build configurations of each environment Worker, edit the deploy commands to be `npx wrangler deploy --env staging` and `npx wrangler deploy --env production` respectively.

```mermaid
graph TD
A[Git Repo for my-worker] --> |Connect| B[my-worker-staging]
A --> |Connect| C[my-worker-production]
subgraph Cloudflare Dashboard
B
C
end
```
43 changes: 19 additions & 24 deletions src/content/docs/workers/ci-cd/builds/build-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,28 @@ sidebar:
order: 2
---

You may tell Workers Builds how your application needs to be built and deployed.
When connecting your repository, you can configure how to build and deploy your Worker.

## Build Settings

Build settings can be found on the **Settings > Builds** section of your Worker. The following options are available:

| **Field** | **Description** |
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Git account** | Set the Git account you would like to choose your repository from. |
| **Git repository** | Select the Git repository you would like to connect to your Worker. |
| **Git branch** | Select the branch you would like Cloudflare to listen to for new commits. This will be defaulted to `main`. |
| **Build command** (Optional) | Add a build command if your project requires a build step. This is necessary, for example, when building with assets. |
| **Deploy command** | The deploy command lets you choose the specific Wrangler command you would like to use to deploy your Worker. |
| **Root Directory** (Optional) | Specify the root directory of your Worker. The root directory describes where the build command will run. |
| **API Key** | By default, Cloudflare will generate an API token for your account. Alternatively, you can create and select an existing API token from a previous build in the API token dropdown. |
| **Build variable** (Optional) | Add variables and secrets accessible only to your build. |

### Deploy Command

After your Workers project is built, the Wrangler command you specify will be ran to deploy your project to Cloudflare's Global Network.

Your deploy command is defaulted to `npx wrangler deploy`. However, you can [customize the command](/workers/wrangler/commands/#deploy) based on your deployment needs. Alternatively, you can also upload the build as a version and use [gradual deployments](/workers/configuration/versions-and-deployments/gradual-deployments/).

### Default API Token

Note the default API Token created will contain the following permissions:

Build settings can be found by navigating to **Settings** > **Build** within your Worker. The following configurations are available:

| Setting | Description |
| -------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Git account** | Select the git account you would like to use. After initial connection,, you can continue to use this git account for future projects. |
| **Git repository** | Choose the git repository you would like to connect your Worker to. |
| **Git branch** | Select the branch you would like Cloudflare to listen to for new commits. This will be defaulted to `main`. |
| **Build command** _(Optional)_ | Set a build command if your project requires a build step. This is necessary, for example, is using a front-end framework (e.g. Astro, Remix). |
| **Deploy command** | The deploy command lets you set the **specific** Wrangler command to deploy your Worker. Your deploy command will default to `npx wrangler deploy` but you may customize this command if for example you want to create a [version](/workers/configuration/versions-and-deployments/gradual-deployments/) of your Worker or just run `npm run deploy`. Workers Builds will use the Wrangler version set in your `package json`. |
| **Root directory** _(Optional)_ | Specify the root directory of your repository. The root directory describes where the build command will be run. |
| **API token** _(Optional)_ | By default, Cloudflare will automatically generate an API token for your account when using Workers Builds for the first time. Workers Builds will continue to use this API token for all subsequent projects and builds. You can also generate and use new API tokens if you choose. These API tokens will be created with the following permissions for your account: |
| **Build variables and secrets** _(Optional)_ | Add environment variables and secrets accessible only to your build. Build variables will not be accessible at runtime. If you would like to configure runtime variables you can do so in **Setting**s > **Variables & Secrets** |

:::note[API Token Permissions]
The Workers Builds API token will be created automatically with the following permissions:
- **Account:** Account Settings (read), Workers Scripts (edit), Workers KV Storage (edit), Workers R2 Storage (edit)
- **Zone:** Workers Routes (edit) for all zones on the account
- **User:** User Details (read), Memberships (read)
:::

Please note, any updates to your build settings will be applied on the next build once saved.
64 changes: 18 additions & 46 deletions src/content/docs/workers/ci-cd/builds/build-image.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,38 @@ sidebar:
order: 3
---

The build environment has broad support for a variety of languages, such as Ruby, Node.js, Python, PHP, and Go.

If you need to use a [specific version](/workers/ci-cd/builds/build-image/#overriding-default-versions) of a language, (for example, Node.js or Ruby) you can specify it by providing an associated environment variable in your build configuration, or setting the relevant file in your source code.
Workers Builds uses a build image with support for a variety of languages and tools such as Node.js, Python, PHP, Ruby, and Go.

## Supported Languages and Tools

In the following table, review the preinstalled versions for languages and tools included in the Cloudflare Workers' build image, and the environment variables and/or files available for [overriding the preinstalled version](/workers/ci-cd/builds/build-image/#overriding-default-versions):

| Tool | Default version | Supported versions | Environment variable | File |
| ----------- | ---------------- | ------------------ | -------------------- | ---------------------------- |
| **Go** | 1.22.0 | Any version | `GO_VERSION` | |
| **Node.js** | 20.16.0 | Any version | `NODE_VERSION` | .nvmrc, .node-version |
| **Python** | 3.12.5 | Any version | `PYTHON_VERSION` | .python-version, runtime.txt |
| **Ruby** | 3.3.4 | Any version | `RUBY_VERSION` | .ruby-version |
| **Bun** | 1.1.22 | Any version | `BUN_VERSION` | |
| **Hugo** | extended_0.130.0 | Any version | `HUGO_VERSION` | |
| Tool | Default version | Environment variable | File |
| ----------- | ---------------- | -------------------- | ---------------------------- |
| **Go** | 1.22.0 | `GO_VERSION` | |
| **Node.js** | 22 | `NODE_VERSION` | .nvmrc, .node-version |
| **Python** | 3.12.5 | `PYTHON_VERSION` | .python-version, runtime.txt |
| **Ruby** | 3.3.4 | `RUBY_VERSION` | .ruby-version |
| **Bun** | 1.1.22 | `BUN_VERSION` | |
| **Hugo** | extended_0.130.0 | `HUGO_VERSION` | |

:::note[Any version]
Under Supported versions, "Any version" refers to support for all versions of the language or tool including versions newer than the Default version.
:::
The default versions will be updated regularly to the latest minor version. No major version updates will be made without notice. If you need a specific minor version, please specify it by overriding the default version.

The default versions will be updated regularly to the latest minor version. No major version updates will be made without notice. If you need a specific minor version, please specify it by overriding the default version.

### Overriding Default Versions

To override default versions of languages and tools in the build system, you can either set the desired version through environment variables or by adding files to your project.
If you need to override a [specific version](/workers/ci-cd/builds/build-image/#overriding-default-versions) of a language or tool within the image, you can specify it as a [build environment variable](/workers/ci-cd/builds/build-configuration/#build-settings), or set the relevant file in your source code as shown above.

To set the version using environment variables, you can:
To set the version using a build environment variables, you can:

1. Find the environment variable name for the language or tool.
2. Add the environment variable on the dashboard by going to **Settings** > **Environmnet variables** in your Workers project, or [add the environment variable via Wrangler](/workers/configuration/environment-variables/#add-environment-variables-via-wrangler).
1. Find the environment variable name for the language or tool and desired version (e.g. `NODE_VERSION = 22`)
2. Add and save the environment variable on the dashboard by going to **Settings** > **Build** > **Build Variables and Secrets* in your Workers project

Or, to set the version by adding a file to your project, you can:

1. Find the file name for the language or tool.
2. Add the specified file name to the root directory of your project and add the desired version number as the contents of the file.

For example, if you were previously relying on the default version of Node.js in the v1 build system, to migrate to v2, you must specify that you need Node.js `12.18.0` by setting a `NODE_VERSION = 12.18.0` environment variable or by adding a `.node-version` or `.nvmrc` file to your project with `12.18.0` added as the contents to the file.
1. Find the filename for the language or tool (e.g. `.nvmrc`)
2. Add the specified file name to the root directory and add the desired version number as the contents of the file (e.g. 22)

## Pre-installed Packages

Expand All @@ -61,34 +55,12 @@ In the following table, review the pre-installed packages in the build image. Th
| `gnupg` | `liblzma-dev` | `zstd` |
| `libffi-dev` | `libncurses5-dev` | |

## Framework Support

To use a specific version of a framework, specify it in the project's package manager configuration file.
For example, if you use Gatsby, your `package.json` should include the following:

```
"dependencies": {
"gatsby": "^5.13.7",
}
```

When your build starts, version 5.13.7 of Gatsby will be installed using `npm install`.

## Build Environment

Cloudflare Workers builds are run in the following environment:
Workers Builds are run in the following environment:

| | |
| --------------------- | ------------ |
| **Build Enviornment** | Ubuntu 24.04 |
| **Build Environment** | Ubuntu 24.04 |
| **Architecture** | x86_64 |

## Container Resources

Each build will have the following resources:

| Resource | Allocation |
| -------------- | ---------- |
| **CPU** | 2 CPUs |
| **Disk Space** | 8 GB |
| **Memory** | 8 GB |
Loading

0 comments on commit 2a9515e

Please sign in to comment.