Skip to content

Commit 8e3ce64

Browse files
authored
add container rebuild hotkey + dev cleanup tests (#9728)
* patch containerBuildId from hotkeys correctly * add interactivity tests * pr feedback
1 parent bb09e50 commit 8e3ce64

File tree

16 files changed

+333
-60
lines changed

16 files changed

+333
-60
lines changed

.github/workflows/test-and-check.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ jobs:
9494
description: macOS
9595
node_version: 20.19.1
9696
filter: '--filter="./packages/*" --filter="./fixtures/*" --filter="./packages/vite-plugin-cloudflare/playground" --summarize'
97-
- os: ubuntu-24.04-arm
97+
# needs to run on the amd runners to allow containers test to work in CI
98+
- os: ubuntu-24.04
9899
description: Linux
99100
node_version: 20.19.1
100101
# ./tools _only_ runs here because they're only intended to run in CI
@@ -104,11 +105,12 @@ jobs:
104105
description: Windows
105106
node_version: 20.19.1
106107
filter: '--filter="./packages/*" --filter="./fixtures/*" --filter="./packages/vite-plugin-cloudflare/playground"'
107-
- os: ubuntu-24.04-arm
108+
# needs to run on the amd runners to allow containers test to work in CI
109+
- os: ubuntu-24.04
108110
description: v22, Linux
109111
node_version: 22
110112
# Browser rendering is disabled here because of https://pptr.dev/troubleshooting#issues-with-apparmor-on-ubuntu
111-
filter: '--filter="./packages/*" --filter="./fixtures/*" --filter="./packages/vite-plugin-cloudflare/playground" --filter="!./packages/kv-asset-handler" --filter="!./fixtures/interactive-dev-tests" --filter="!./fixtures/browser-rendering"'
113+
filter: '--filter="./packages/*" --filter="./fixtures/*" --filter="./packages/vite-plugin-cloudflare/playground" --filter="!./packages/kv-asset-handler" --filter="!./fixtures/browser-rendering"'
112114
# Skipped until we upgrade to undici v7, because of https://github.com/nodejs/undici/issues/4285
113115
# - os: ubuntu-24.04-arm
114116
# label: v24, Linux

fixtures/container-app/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ RUN npm install
66

77
COPY ./container/simple-node-app.js app.js
88
EXPOSE 8080
9-
CMD [ "node", "app.js" ]

fixtures/container-app/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# HTTP fetch to a container
22

3-
This example shows a simple HTTP request passthrough the DO to the container.
3+
This example shows a simple container setup where a DO passes requests through to a node server.

fixtures/container-app/container/simple-node-app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const server = createServer(function (req, res) {
1010
}
1111

1212
res.writeHead(200, { "Content-Type": "text/plain" });
13-
res.write("Hello World!");
13+
res.write("Hello World! Have an env var! " + process.env.MESSAGE);
1414
res.end();
1515
});
1616

fixtures/container-app/src/index.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { DurableObject } from "cloudflare:workers";
22

3-
export class Container extends DurableObject<Env> {
3+
export class FixtureTestContainer extends DurableObject<Env> {
44
container: globalThis.Container;
55
monitor?: Promise<unknown>;
66

77
constructor(ctx: DurableObjectState, env: Env) {
88
super(ctx, env);
9-
this.container = ctx.container!;
9+
this.container = ctx.container;
1010
}
1111

1212
async fetch(req: Request) {
@@ -25,7 +25,7 @@ export class Container extends DurableObject<Env> {
2525
case "/start":
2626
this.container.start({
2727
entrypoint: ["node", "app.js"],
28-
env: { A: "B", C: "D", L: "F" },
28+
env: { MESSAGE: "I'm an env var!" },
2929
enableInternet: false,
3030
});
3131
// this doesn't instantly start, so we will need to poll /fetch
@@ -39,9 +39,6 @@ export class Container extends DurableObject<Env> {
3939
return new Response(await res.text());
4040

4141
case "/destroy-with-monitor":
42-
// if (!this.container.running) {
43-
// throw new Error("Container is not running.");
44-
// }
4542
const monitor = this.container.monitor();
4643
await this.container.destroy();
4744
await monitor;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
declare namespace Cloudflare {
22
interface Env {
3-
CONTAINER: DurableObjectNamespace<import("./src/index").Container>;
3+
CONTAINER: DurableObjectNamespace<import("./src").Container>;
44
}
55
}
66
interface Env extends Cloudflare.Env {}

fixtures/container-app/wrangler.jsonc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,24 @@
44
"compatibility_date": "2025-04-03",
55
"containers": [
66
{
7-
"configuration": {
8-
"image": "./Dockerfile",
9-
},
10-
"class_name": "Container",
11-
"name": "http2",
7+
"image": "./Dockerfile",
8+
"class_name": "FixtureTestContainer",
9+
"name": "container",
1210
"max_instances": 2,
1311
},
1412
],
1513
"durable_objects": {
1614
"bindings": [
1715
{
18-
"class_name": "Container",
16+
"class_name": "FixtureTestContainer",
1917
"name": "CONTAINER",
2018
},
2119
],
2220
},
2321
"migrations": [
2422
{
2523
"tag": "v1",
26-
"new_sqlite_classes": ["Container"],
24+
"new_sqlite_classes": ["FixtureTestContainer"],
2725
},
2826
],
2927
}

fixtures/container-app/wrangler.registry.jsonc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,25 @@
44
"compatibility_date": "2025-04-03",
55
"containers": [
66
{
7-
"configuration": {
8-
"image": "registry.cloudflare.com/8d783f274e1f82dc46744c297b015a2f/ci-container-dont-delete:latest",
9-
},
10-
"class_name": "Container",
11-
"name": "http2",
7+
// This is the same container as built by the dockerfile except it is pulled from the registry
8+
"image": "registry.cloudflare.com/8d783f274e1f82dc46744c297b015a2f/ci-container-dont-delete:latest",
9+
"class_name": "FixtureTestContainer",
10+
"name": "container",
1211
"max_instances": 2,
1312
},
1413
],
1514
"durable_objects": {
1615
"bindings": [
1716
{
18-
"class_name": "Container",
17+
"class_name": "FixtureTestContainer",
1918
"name": "CONTAINER",
2019
},
2120
],
2221
},
2322
"migrations": [
2423
{
2524
"tag": "v1",
26-
"new_sqlite_classes": ["Container"],
25+
"new_sqlite_classes": ["FixtureTestContainer"],
2726
},
2827
],
2928
}

fixtures/interactive-dev-tests/Dockerfile

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM node:22-alpine
2+
3+
WORKDIR /usr/src/app
4+
RUN echo '{"name": "simple-node-app", "version": "1.0.0", "dependencies": {"ws": "^8.0.0"}}' > package.json
5+
RUN npm install
6+
7+
COPY ./container/simple-node-app.js app.js
8+
EXPOSE 8080

0 commit comments

Comments
 (0)