Skip to content

Commit 8e633b3

Browse files
committed
Adds none as option to containers rollout flag for skipping container deploy
1 parent 8672321 commit 8e633b3

6 files changed

Lines changed: 91 additions & 12 deletions

File tree

packages/containers-shared/src/utils.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,17 @@ export const verifyDockerInstalled = async (
9191
) => {
9292
const dockerIsRunning = await isDockerRunning(dockerPath);
9393
if (!dockerIsRunning) {
94-
throw new UserError(
94+
let message =
9595
`The Docker CLI could not be launched. Please ensure that the Docker CLI is installed and the daemon is running.\n` +
96-
`Other container tooling that is compatible with the Docker CLI and engine may work, but is not yet guaranteed to do so. You can specify an executable with the environment variable WRANGLER_DOCKER_BIN and a socket with DOCKER_HOST.` +
97-
`${isDev ? "\nTo suppress this error if you do not intend on triggering any container instances, set dev.enable_containers to false in your Wrangler config or passing in --enable-containers=false." : ""}`
98-
);
96+
`Other container tooling that is compatible with the Docker CLI and engine may work, but is not yet guaranteed to do so. You can specify an executable with the environment variable WRANGLER_DOCKER_BIN and a socket with DOCKER_HOST.`;
97+
if (isDev) {
98+
message +=
99+
"\nTo suppress this error if you do not intend on triggering any container instances, set dev.enable_containers to false in your Wrangler config or passing in --enable-containers=false.";
100+
} else {
101+
message +=
102+
"\nIf you cannot run Docker locally, you can still deploy your Worker by passing --containers-rollout=none. This will not deploy or update your Container.";
103+
}
104+
throw new UserError(message);
99105
}
100106
};
101107

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,38 @@ describe("getNormalizedContainerOptions", () => {
651651
expect(result[0].rollout_step_percentage).toBe(100);
652652
});
653653

654+
it("should set rollout_kind to none when containersRollout is none", async () => {
655+
const config: Config = {
656+
name: "test-worker",
657+
configPath: "/test/wrangler.toml",
658+
userConfigPath: "/test/wrangler.toml",
659+
topLevelName: "test-worker",
660+
containers: [
661+
{
662+
class_name: "TestContainer",
663+
image: `${getCloudflareContainerRegistry()}/test:latest`,
664+
name: "test-container",
665+
max_instances: 10,
666+
rollout_kind: "full_auto",
667+
},
668+
],
669+
durable_objects: {
670+
bindings: [
671+
{
672+
name: "TEST_DO",
673+
class_name: "TestContainer",
674+
},
675+
],
676+
},
677+
} as Partial<Config> as Config;
678+
679+
const result = await getNormalizedContainerOptions(config, {
680+
containersRollout: "none",
681+
});
682+
expect(result).toHaveLength(1);
683+
expect(result[0].rollout_kind).toBe("none");
684+
});
685+
654686
describe("image validation and resolution", async () => {
655687
it("should reject unsupported image registries", async () => {
656688
const config: Config = {

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ describe("wrangler deploy with containers", () => {
6767
).rejects.toThrowErrorMatchingInlineSnapshot(
6868
`
6969
[Error: The Docker CLI could not be launched. Please ensure that the Docker CLI is installed and the daemon is running.
70-
Other container tooling that is compatible with the Docker CLI and engine may work, but is not yet guaranteed to do so. You can specify an executable with the environment variable WRANGLER_DOCKER_BIN and a socket with DOCKER_HOST.]
70+
Other container tooling that is compatible with the Docker CLI and engine may work, but is not yet guaranteed to do so. You can specify an executable with the environment variable WRANGLER_DOCKER_BIN and a socket with DOCKER_HOST.
71+
If you cannot run Docker locally, you can still deploy your Worker by passing --containers-rollout=none. This will not deploy or update your Container.]
7172
`
7273
);
7374
});
@@ -1055,6 +1056,40 @@ describe("wrangler deploy with containers", () => {
10551056
});
10561057
});
10571058

1059+
it("should skip Docker check and container deploy when --containers-rollout=none", async () => {
1060+
vi.stubEnv("WRANGLER_DOCKER_BIN", "/usr/bin/bad-docker-path");
1061+
writeWranglerConfig({
1062+
...DEFAULT_DURABLE_OBJECTS,
1063+
containers: [DEFAULT_CONTAINER_FROM_DOCKERFILE],
1064+
});
1065+
1066+
fs.writeFileSync("./Dockerfile", "FROM scratch");
1067+
1068+
mockGetVersion("Galaxy-Class");
1069+
mockGetApplications([]);
1070+
mockCreateApplication();
1071+
1072+
fs.writeFileSync(
1073+
"index.js",
1074+
`export class ExampleDurableObject {}; export default{};`
1075+
);
1076+
1077+
// Without --containers-rollout=none, this would fail with a Docker error.
1078+
// With the flag, it should skip Docker verification entirely and proceed
1079+
// to deploy the Worker (the deploy itself may fail for unrelated mock reasons,
1080+
// but the key assertion is that no Docker error is thrown).
1081+
let thrownError: Error | undefined;
1082+
try {
1083+
await runWrangler("deploy index.js --containers-rollout=none");
1084+
} catch (e) {
1085+
thrownError = e as Error;
1086+
}
1087+
1088+
expect(thrownError?.message ?? "").not.toContain(
1089+
"The Docker CLI could not be launched"
1090+
);
1091+
});
1092+
10581093
describe("observability config resolution", () => {
10591094
const sharedGetApplicationResult = {
10601095
id: "abc",

packages/wrangler/src/containers/config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const getNormalizedContainerOptions = async (
5050
config: Config,
5151
args: {
5252
/** set by args.containersRollout */
53-
containersRollout?: "gradual" | "immediate";
53+
containersRollout?: "gradual" | "immediate" | "none";
5454
dryRun?: boolean;
5555
}
5656
): Promise<ContainerNormalizedConfig[]> => {
@@ -111,7 +111,10 @@ export const getNormalizedContainerOptions = async (
111111
args?.containersRollout === "immediate"
112112
? 100
113113
: container.rollout_step_percentage ?? rolloutStepPercentageFallback,
114-
rollout_kind: container.rollout_kind ?? "full_auto",
114+
rollout_kind:
115+
args?.containersRollout === "none"
116+
? "none"
117+
: container.rollout_kind ?? "full_auto",
115118
rollout_active_grace_period: container.rollout_active_grace_period ?? 0,
116119
observability: {
117120
logs_enabled:

packages/wrangler/src/deploy/deploy.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ type Props = {
127127
dispatchNamespace: string | undefined;
128128
experimentalAutoCreate: boolean;
129129
metafile: string | boolean | undefined;
130-
containersRollout: "immediate" | "gradual" | undefined;
130+
containersRollout: "immediate" | "gradual" | "none" | undefined;
131131
strict: boolean | undefined;
132132
};
133133

@@ -881,7 +881,10 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
881881
// and we have containers so that we don't get into a
882882
// disjointed state where the worker updates but the container
883883
// fails.
884-
if (normalisedContainerConfig.length) {
884+
if (
885+
normalisedContainerConfig.length &&
886+
props.containersRollout !== "none"
887+
) {
885888
// if you have a registry url specified, you don't need docker
886889
const hasDockerfiles = normalisedContainerConfig.some(
887890
(container) => "dockerfile" in container
@@ -1172,7 +1175,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
11721175
return { versionId, workerTag };
11731176
}
11741177

1175-
if (normalisedContainerConfig.length) {
1178+
if (normalisedContainerConfig.length && props.containersRollout !== "none") {
11761179
assert(versionId && accountId);
11771180
await deployContainers(config, normalisedContainerConfig, {
11781181
versionId,

packages/wrangler/src/deploy/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ export const deployCommand = createCommand({
227227
},
228228
"containers-rollout": {
229229
describe:
230-
"Rollout strategy for Containers changes. If set to immediate, it will override `rollout_percentage_steps` if configured and roll out to 100% of instances in one step. ",
231-
choices: ["immediate", "gradual"] as const,
230+
"Rollout strategy for Containers changes. If set to immediate, it will override `rollout_percentage_steps` if configured and roll out to 100% of instances in one step. If set to none, the Worker will be deployed without building or updating any Containers.",
231+
choices: ["immediate", "gradual", "none"] as const,
232232
},
233233
strict: {
234234
describe:

0 commit comments

Comments
 (0)