Skip to content

Commit 152b9a3

Browse files
committed
miscellaneous fixes
1 parent 22f6208 commit 152b9a3

File tree

15 files changed

+175
-137
lines changed

15 files changed

+175
-137
lines changed

public/__redirects

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2421,4 +2421,9 @@
24212421
/ai-gateway/guardrails/* /ai-gateway/features/guardrails/:splat 301
24222422
/ai-gateway/websockets-api/* /ai-gateway/usage/websockets-api/:splat 301
24232423

2424-
2424+
# Containers
2425+
/containers/image-management /containers/platform-details/image-management 301
2426+
/containers/scaling-and-routing /containers/platform-details/scaling-and-routing 301
2427+
/containers/architecture /containers/platform-details/architecture 301
2428+
/containers/durable-object-methods /containers/platform-details/durable-object-methods 301
2429+
/containers/platform-details /containers/platform-details/architecture 301

src/content/docs/containers/beta-info.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ by calling `get()` on their binding with a unique ID.
2424
We plan to add official support for utilization-based autoscaling and latency-aware load balancing
2525
in the future.
2626

27-
See the [Autoscaling documentation](/containers/scaling-and-routing) for more information.
27+
See the [Autoscaling documentation](/containers/platform-details/scaling-and-routing) for more information.
2828

2929
### Reduction of log noise
3030

@@ -38,7 +38,6 @@ We plan to automatically reduce log noise in the future.
3838

3939
The dashboard will be updated to show:
4040

41-
- the status of Container rollouts
4241
- links from Workers to their associated Containers
4342

4443
### Co-locating Durable Objects and Containers
@@ -71,6 +70,6 @@ There are several areas where we wish to gather feedback from users:
7170
- Do you want to integrate Containers with any other Cloudflare services? If so, which ones and how?
7271
- Do you want more ways to interact with a Container via Workers? If so, how?
7372
- Do you need different mechanisms for routing requests to containers?
74-
- Do you need different mechanisms for scaling containers? (see [scaling documentation](/containers/scaling-and-routing) for information on autoscaling plans)
73+
- Do you need different mechanisms for scaling containers? (see [scaling documentation](/containers/platform-details/scaling-and-routing) for information on autoscaling plans)
7574

7675
At any point during the Beta, feel free to [give feedback using this form](https://forms.gle/CscdaEGuw5Hb6H2s7).

src/content/docs/containers/container-package.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sidebar:
66
---
77

88
When writing code that interacts with a container instance, you can either use a
9-
Durable Object directly or use the [`Container` module](https://github.com/cloudflare/containers)
9+
[Durable Object directly](/containers/platform-details/durable-object-methods) or use the [`Container` module](https://github.com/cloudflare/containers)
1010
importable from [`@cloudflare/containers`](https://www.npmjs.com/package/@cloudflare/containers).
1111

1212
```javascript

src/content/docs/containers/examples/container-backend.mdx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
32
summary: A simple frontend app with a containerized backend
43
pcx_content_type: example
54
title: Static Frontend, Container Backend
@@ -166,7 +165,7 @@ select of of N instances of a Container to route requests to.
166165
In the future, we will provide improved latency-aware load balancing and autoscaling.
167166

168167
This will make scaling stateless instances simple and routing more efficient. See the
169-
[autoscaling documentation](/containers/scaling-and-routing) for more details.
168+
[autoscaling documentation](/containers/platform-details/scaling-and-routing) for more details.
170169
:::
171170

172171
## Define a backend container
@@ -186,11 +185,11 @@ import (
186185
)
187186

188187
func handler(w http.ResponseWriter, r \*http.Request) {
189-
widgets := []map[string]interface{}{
190-
{"id": 1, "name": "Widget A"},
191-
{"id": 2, "name": "Sprocket B"},
192-
{"id": 3, "name": "Gear C"},
193-
}
188+
widgets := []map[string]interface{}{
189+
{"id": 1, "name": "Widget A"},
190+
{"id": 2, "name": "Sprocket B"},
191+
{"id": 3, "name": "Gear C"},
192+
}
194193

195194
w.Header().Set("Content-Type", "application/json")
196195
w.Header().Set("Access-Control-Allow-Origin", "*")
@@ -199,9 +198,10 @@ func handler(w http.ResponseWriter, r \*http.Request) {
199198
}
200199

201200
func main() {
202-
http.HandleFunc("/api/widgets", handler)
203-
log.Fatal(http.ListenAndServe(":8080", nil))
201+
http.HandleFunc("/api/widgets", handler)
202+
log.Fatal(http.ListenAndServe(":8080", nil))
204203
}
205204

206205
```
207206
</Details>
207+
```

src/content/docs/containers/examples/cron.mdx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
32
summary: Running a container on a schedule using Cron Triggers
43
pcx_content_type: example
54
title: Cron Container
@@ -43,9 +42,7 @@ Use a cron expression in your Wrangler config to specify the schedule:
4342
},
4443
"migrations": [
4544
{
46-
"new_sqlite_classes": [
47-
"CronContainer"
48-
],
45+
"new_sqlite_classes": ["CronContainer"],
4946
"tag": "v1"
5047
}
5148
]
@@ -61,7 +58,6 @@ import { Container, getContainer } from "@cloudflare/containers";
6158

6259
export class CronContainer extends Container {
6360
sleepAfter = "5m";
64-
manualStart = true;
6561
}
6662

6763
export default {
@@ -71,13 +67,16 @@ export default {
7167
);
7268
},
7369

70+
// scheduled is called when a cron trigger fires
7471
async scheduled(
7572
_controller: any,
7673
env: { CRON_CONTAINER: DurableObjectNamespace<CronContainer> },
7774
) {
78-
await getContainer(env.CRON_CONTAINER).startContainer({
79-
envVars: {
80-
MESSAGE: "Start Time: " + new Date().toISOString(),
75+
await getContainer(env.CRON_CONTAINER).startAndWaitForPorts({
76+
startOptions: {
77+
envVars: {
78+
MESSAGE: "Start Time: " + new Date().toISOString(),
79+
},
8180
},
8281
});
8382
},

src/content/docs/containers/examples/env-vars-and-secrets.mdx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ description: Pass in environment variables and secrets to your container
1010
import { WranglerConfig, PackageManagers } from "~/components";
1111

1212
Environment variables can be passed into a Container using the `envVars` field
13-
in the `Container` class, or by setting manually when the Container starts.
13+
in the [`Container`](/containers/container-package) class, or by setting manually when the Container starts.
1414

1515
Secrets can be passed into a Container by using [Worker Secrets](/workers/configuration/secrets/)
1616
or the [Secret Store](/secrets-store/integrations/workers/), then passing them into the Container
@@ -111,14 +111,13 @@ set as environment variables when it launches.
111111

112112
But what if you want to set environment variables on a per-instance basis?
113113

114-
In this case, set `manualStart` then use the `start` method to pass in environment variables for each instance.
114+
In this case, use the `startAndWaitForPorts()` method to pass in environment variables for each instance.
115115
We'll assume that we've set additional secrets in the Secret Store.
116116

117117
```js
118118
export class MyContainer extends Container {
119119
defaultPort = 8080;
120120
sleepAfter = "10s";
121-
manualStart = true;
122121
}
123122

124123
export default {
@@ -129,19 +128,23 @@ export default {
129128

130129
// Each instance gets a different set of environment variables
131130

132-
await instanceOne.start({
133-
envVars: {
134-
ACCOUNT_NAME: env.ACCOUNT_NAME + "-1",
135-
ACCOUNT_API_KEY: env.SECRET_STORE.ACCOUNT_API_KEY_ONE,
136-
CONTAINER_SECRET_KEY: env.CONTAINER_SECRET_KEY_TWO,
131+
await instanceOne.startAndWaitForPorts({
132+
startOptions: {
133+
envVars: {
134+
ACCOUNT_NAME: env.ACCOUNT_NAME + "-1",
135+
ACCOUNT_API_KEY: env.SECRET_STORE.ACCOUNT_API_KEY_ONE,
136+
CONTAINER_SECRET_KEY: env.CONTAINER_SECRET_KEY_TWO,
137+
},
137138
},
138139
});
139140

140-
await instanceTwo.start({
141-
envVars: {
142-
ACCOUNT_NAME: env.ACCOUNT_NAME + "-2",
143-
ACCOUNT_API_KEY: env.SECRET_STORE.ACCOUNT_API_KEY_TWO,
144-
CONTAINER_SECRET_KEY: env.CONTAINER_SECRET_KEY_TWO,
141+
await instanceTwo.startAndWaitForPorts({
142+
startOptions: {
143+
envVars: {
144+
ACCOUNT_NAME: env.ACCOUNT_NAME + "-2",
145+
ACCOUNT_API_KEY: env.SECRET_STORE.ACCOUNT_API_KEY_TWO,
146+
CONTAINER_SECRET_KEY: env.CONTAINER_SECRET_KEY_TWO,
147+
},
145148
},
146149
});
147150
return new Response("Container instances launched");
@@ -151,3 +154,7 @@ export default {
151154
},
152155
};
153156
```
157+
158+
## Build-time environment variables
159+
160+
Finally, you can also set build-time environment variables that are only available when building the container image via the `image_vars` field in the Wrangler configuration.

src/content/docs/containers/examples/stateless.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
32
summary: Run multiple instances across Cloudflare's network
43
pcx_content_type: example
54
title: Stateless Instances
@@ -36,5 +35,5 @@ select of of N instances of a Container to route requests to.
3635
In the future, we will provide improved latency-aware load balancing and autoscaling.
3736

3837
This will make scaling stateless instances simple and routing more efficient. See the
39-
[autoscaling documentation](/containers/scaling-and-routing) for more details.
38+
[autoscaling documentation](/containers/platform-details/scaling-and-routing) for more details.
4039
:::

src/content/docs/containers/faq.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ See [rollout documentation](/containers/platform-details/rollouts/) for details.
6868

6969
## How does scaling work?
7070

71-
See [scaling & routing documentation](/containers/scaling-and-routing/) for details.
71+
See [scaling & routing documentation](/containers/platform-details/scaling-and-routing/) for details.
7272

7373
## What are cold starts? How fast are they?
7474

@@ -85,7 +85,7 @@ on image size and code execution time, among other factors.
8585

8686
## How do I use an existing container image?
8787

88-
See [image management documentation](/containers/image-management/#using-existing-images) for details.
88+
See [image management documentation](/containers/platform-details/image-management/#using-existing-images) for details.
8989

9090
## Is disk persistent? What happens to my disk when my container sleeps?
9191

src/content/docs/containers/get-started.mdx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This example Worker should give you a sense for simple Container use, and provid
1717
### Ensure Docker is running locally
1818

1919
In this guide, we will build and push a container image alongside your Worker code. By default, this process uses
20-
[Docker](https://www.docker.com/) to do so. You must have Docker running locally when you run `wrangler deploy`. For most people, the best way to install Docker is to follow the [docs for installing Docker Desktop](https://docs.docker.com/desktop/).
20+
[Docker](https://www.docker.com/) to do so. You must have Docker running locally when you run `wrangler deploy`. For most people, the best way to install Docker is to follow the [docs for installing Docker Desktop](https://docs.docker.com/desktop/). Other tools like [Colima](https://github.com/abiosoft/colima) may also work.
2121

2222
You can check that Docker is running properly by running the `docker info` command in your terminal. If Docker is running, the command will succeed. If Docker is not running,
2323
the `docker info` command will hang or return an error including the message "Cannot connect to the Docker daemon".
@@ -29,9 +29,11 @@ the `docker info` command will hang or return an error including the message "Ca
2929

3030
Run the following command to create and deploy a new Worker with a container, from the starter template:
3131

32-
```sh
33-
npm create cloudflare@latest -- --template=cloudflare/templates/containers-template
34-
```
32+
<PackageManagers
33+
type="create"
34+
pkg="cloudflare@latest"
35+
args={"--template=cloudflare/templates/containers-template"}
36+
/>
3537

3638
When you want to deploy a code change to either the Worker or Container code, you can run the following command using [Wrangler CLI](/workers/wrangler/):
3739

@@ -40,7 +42,7 @@ When you want to deploy a code change to either the Worker or Container code, yo
4042
When you run `wrangler deploy`, the following things happen:
4143

4244
- Wrangler builds your container image using Docker.
43-
- Wrangler pushes your image to a [Container Image Registry](/containers/image-management/) that is automatically
45+
- Wrangler pushes your image to a [Container Image Registry](/containers/platform-details/image-management/) that is automatically
4446
integrated with your Cloudflare account.
4547
- Wrangler deploys your Worker, and configures Cloudflare's network to be ready to spawn instances of your container
4648

@@ -67,7 +69,7 @@ And see images deployed to the Cloudflare Registry with the following command:
6769

6870
Now, open the URL for your Worker. It should look something like `https://hello-containers.YOUR_ACCOUNT_NAME.workers.dev`.
6971

70-
If you make requests to the paths `/container/1` or `/container/2`, these requests are routed to specific containers.
72+
If you make requests to the paths `/container/1` or `/container/2`, your Worker routes requests to specific containers.
7173
Each different path after "/container/" routes to a unique container.
7274

7375
If you make requests to `/lb`, you will load balanace requests to one of 3 containers chosen at random.

0 commit comments

Comments
 (0)