Skip to content

Commit 0c0365a

Browse files
committed
wrangler containers: wrangler deploy should be able to deploy container
applications We are adding a new step into wrangler deploy that allows the user to deploy container applications through wrangler deploy. The main changes on this commit allow: 1. cloudchamber/build.ts to accomodate the needs of the new deploy path of containers. 2. cloudchamber/apply.ts to create a Cloudchamber rollout. 3. deploy.ts to call a method when containers option is defined. This method in cloudchamber/deploy.ts does the following: 1. Call fetchVersion to know what's the namespace_id of the target DOs. 2. Deploy each container application. Each container application might specify a Dockerfile or an image URI. If it's a Dockerfile, we will read it and build it.
1 parent f007751 commit 0c0365a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1525
-88
lines changed

.changeset/sad-taxis-kick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
wrangler deploy is able to deploy new container versions

packages/wrangler/src/__tests__/cloudchamber/apply.test.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,25 @@ function mockModifyApplication(
6565
response = res;
6666
});
6767

68+
// Add when we start creating rollouts in `apply.ts`
69+
//
70+
// msw.use(
71+
// http.post(
72+
// "*/applications/:id/rollouts",
73+
// async ({ request }) => {
74+
// const json = await request.json();
75+
// if (expectedRollout !== undefined) {
76+
// expect(json).toMatchObject(expectedRollout);
77+
// }
78+
//
79+
// expect((json as CreateApplicationRequest).name).toBeUndefined();
80+
// response(json as ModifyApplicationRequestBody);
81+
// return HttpResponse.json(json);
82+
// },
83+
// { once: true }
84+
// )
85+
// );
86+
6887
msw.use(
6988
http.patch(
7089
"*/applications/:id",
@@ -73,7 +92,7 @@ function mockModifyApplication(
7392
if (expected !== undefined) {
7493
expect(json).toEqual(expected);
7594
}
76-
console.log(json);
95+
7796
expect((json as CreateApplicationRequest).name).toBeUndefined();
7897
response(json as ModifyApplicationRequestBody);
7998
return HttpResponse.json(json);
@@ -166,6 +185,7 @@ describe("cloudchamber apply", () => {
166185
name: "my-container-app",
167186
instances: 3,
168187
created_at: new Date().toString(),
188+
version: 1,
169189
account_id: "1",
170190
scheduling_policy: SchedulingPolicy.REGIONAL,
171191
configuration: {
@@ -198,6 +218,8 @@ describe("cloudchamber apply", () => {
198218
├ Do you want to apply these changes?
199219
│ yes
200220
221+
├ Loading
222+
201223
202224
│  SUCCESS  Modified application my-container-app
203225
@@ -239,6 +261,7 @@ describe("cloudchamber apply", () => {
239261
instances: 3,
240262
created_at: new Date().toString(),
241263
account_id: "1",
264+
version: 1,
242265
scheduling_policy: SchedulingPolicy.REGIONAL,
243266
configuration: {
244267
image: "./Dockerfile",
@@ -281,6 +304,8 @@ describe("cloudchamber apply", () => {
281304
├ Do you want to apply these changes?
282305
│ yes
283306
307+
├ Loading
308+
284309
285310
│  SUCCESS  Modified application my-container-app
286311
@@ -336,6 +361,7 @@ describe("cloudchamber apply", () => {
336361
id: "abc",
337362
name: "my-container-app",
338363
instances: 3,
364+
version: 1,
339365
created_at: new Date().toString(),
340366
account_id: "1",
341367
scheduling_policy: SchedulingPolicy.REGIONAL,
@@ -408,6 +434,8 @@ describe("cloudchamber apply", () => {
408434
├ Do you want to apply these changes?
409435
│ yes
410436
437+
├ Loading
438+
411439
412440
│  SUCCESS  Modified application my-container-app
413441
@@ -461,6 +489,7 @@ describe("cloudchamber apply", () => {
461489
id: "abc",
462490
name: "my-container-app",
463491
instances: 3,
492+
version: 1,
464493
created_at: new Date().toString(),
465494
account_id: "1",
466495
scheduling_policy: SchedulingPolicy.REGIONAL,
@@ -601,8 +630,8 @@ describe("cloudchamber apply", () => {
601630
};
602631

603632
mockGetApplications([
604-
completeApp,
605-
{ ...completeApp, name: "my-container-app-2", id: "abc2" },
633+
{ ...completeApp, version: 1 },
634+
{ ...completeApp, version: 1, name: "my-container-app-2", id: "abc2" },
606635
]);
607636
await runWrangler("cloudchamber apply --json");
608637
/* eslint-disable */

packages/wrangler/src/__tests__/containers/list.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe("containers list", () => {
6363
\\"created_at\\": \\"123\\",
6464
\\"account_id\\": \\"test-account\\",
6565
\\"name\\": \\"Test-app\\",
66+
\\"version\\": 1,
6667
\\"configuration\\": {
6768
\\"image\\": \\"test-registry.cfdata.org/test-app:v1\\",
6869
\\"network\\": {
@@ -81,6 +82,7 @@ describe("containers list", () => {
8182
\\"created_at\\": \\"123\\",
8283
\\"account_id\\": \\"test-account\\",
8384
\\"name\\": \\"Test-app\\",
85+
\\"version\\": 1,
8486
\\"configuration\\": {
8587
\\"image\\": \\"test-registry.cfdata.org/test-app:v10\\",
8688
\\"network\\": {
@@ -99,6 +101,7 @@ describe("containers list", () => {
99101
\\"created_at\\": \\"123\\",
100102
\\"account_id\\": \\"test-account\\",
101103
\\"name\\": \\"Test-app\\",
104+
\\"version\\": 1,
102105
\\"configuration\\": {
103106
\\"image\\": \\"test-registry.cfdata.org/test-app:v2\\",
104107
\\"network\\": {

packages/wrangler/src/__tests__/deploy.test.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import { http, HttpResponse } from "msw";
1010
import dedent from "ts-dedent";
1111
import { File } from "undici";
1212
import { vi } from "vitest";
13+
import { type Application } from "../cloudchamber/client";
1314
import {
1415
printBundleSize,
1516
printOffendingDependencies,
1617
} from "../deployment-bundle/bundle-reporter";
1718
import { clearOutputFilePath } from "../output";
1819
import { sniffUserAgent } from "../package-manager";
1920
import { writeAuthConfigFile } from "../user";
21+
import { mockAccount as mockContainersAccount } from "./cloudchamber/utils";
2022
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
2123
import { mockAuthDomain } from "./helpers/mock-auth-domain";
2224
import { mockConsoleMethods } from "./helpers/mock-console";
@@ -8602,6 +8604,48 @@ addEventListener('fetch', event => {});`
86028604
});
86038605

86048606
it("should support durable object bindings to SQLite classes with containers", async () => {
8607+
function mockGetVersion(versionId: string) {
8608+
msw.use(
8609+
http.get(
8610+
`*/accounts/:accountId/workers/scripts/:scriptName/versions/${versionId}`,
8611+
async () => {
8612+
return HttpResponse.json(
8613+
createFetchResult({
8614+
id: versionId,
8615+
metadata: {},
8616+
number: 2,
8617+
resources: {
8618+
bindings: [
8619+
{
8620+
type: "durable_object_namespace",
8621+
namespace_id: "1",
8622+
class_name: "ExampleDurableObject",
8623+
},
8624+
],
8625+
},
8626+
})
8627+
);
8628+
},
8629+
{ once: true }
8630+
)
8631+
);
8632+
}
8633+
8634+
function mockGetApplications(applications: Application[]) {
8635+
msw.use(
8636+
http.get(
8637+
"*/applications",
8638+
async () => {
8639+
return HttpResponse.json(applications);
8640+
},
8641+
{ once: true }
8642+
)
8643+
);
8644+
}
8645+
8646+
mockGetVersion("Galaxy-Class");
8647+
8648+
mockContainersAccount();
86058649
writeWranglerConfig({
86068650
durable_objects: {
86078651
bindings: [
@@ -8625,6 +8669,31 @@ addEventListener('fetch', event => {});`
86258669
{ tag: "v1", new_sqlite_classes: ["ExampleDurableObject"] },
86268670
],
86278671
});
8672+
8673+
mockGetApplications([]);
8674+
function mockCreateApplication(expected?: Partial<Application>) {
8675+
msw.use(
8676+
http.post(
8677+
"*/applications",
8678+
async ({ request }) => {
8679+
const json = await request.json();
8680+
if (expected !== undefined) {
8681+
expect(json).toMatchObject(expected);
8682+
}
8683+
8684+
return HttpResponse.json(json);
8685+
},
8686+
{ once: true }
8687+
)
8688+
);
8689+
}
8690+
8691+
mockCreateApplication({
8692+
name: "my-container",
8693+
instances: 10,
8694+
durable_objects: { namespace_id: "1" },
8695+
});
8696+
86288697
fs.writeFileSync(
86298698
"index.js",
86308699
`export class ExampleDurableObject {}; export default{};`

packages/wrangler/src/__tests__/helpers/mock-cloudchamber.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export const MOCK_APPLICATIONS: Application[] = [
191191
created_at: "123",
192192
account_id: "test-account",
193193
name: "Test-app",
194+
version: 1,
194195
configuration: {
195196
image: "test-registry.cfdata.org/test-app:v1",
196197
network: {
@@ -207,6 +208,7 @@ export const MOCK_APPLICATIONS: Application[] = [
207208
created_at: "123",
208209
account_id: "test-account",
209210
name: "Test-app",
211+
version: 1,
210212
configuration: {
211213
image: "test-registry.cfdata.org/test-app:v10",
212214
network: {
@@ -223,6 +225,7 @@ export const MOCK_APPLICATIONS: Application[] = [
223225
created_at: "123",
224226
account_id: "test-account",
225227
name: "Test-app",
228+
version: 1,
226229
configuration: {
227230
image: "test-registry.cfdata.org/test-app:v2",
228231
network: {

0 commit comments

Comments
 (0)