Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/container.md
Original file line number Diff line number Diff line change
Expand Up @@ -512,10 +512,12 @@ ARGUMENTS
FLAGS
-P, --publish-all publish all ports that are defined in the image
-e, --env=<value>... set environment variables in the container
-m, --memory=<value> set memory limit for the container
-p, --project-id=<value> ID or short ID of a project; this flag is optional if a default project is set in the
context
-q, --quiet suppress process output and only display a machine-readable summary
-v, --volume=<value>... bind mount a volume to the container
--cpus=<value> set CPU limit for the container
--create-volumes automatically create named volumes that do not exist
--description=<value> add a descriptive label to the container
--entrypoint=<value> override the default entrypoint of the container image
Expand All @@ -536,6 +538,11 @@ FLAG DESCRIPTIONS

Format: KEY=VALUE. Multiple environment variables can be specified with multiple --env flags.

-m, --memory=<value> set memory limit for the container

Specify the maximum amount of memory the container can use (e.g., '512m', '1g', '2g'). This is equivalent to the
docker run --memory flag or the deploy.resources.limits.memory field in docker-compose.

-p, --project-id=<value> ID or short ID of a project; this flag is optional if a default project is set in the context

May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=<VALUE>" command
Expand All @@ -553,6 +560,11 @@ FLAG DESCRIPTIONS
mount a path from your hosting environment's file system (NOT your local file system) into the container. You can
also specify a named volume, which needs to be created beforehand.

--cpus=<value> set CPU limit for the container

Specify the number of CPUs available to the container (e.g., '0.5', '1', '2'). This is equivalent to the docker run
--cpus flag or the deploy.resources.limits.cpus field in docker-compose.

--create-volumes automatically create named volumes that do not exist

When enabled, any named volumes referenced in --volume flags that do not already exist will be automatically created
Expand Down
47 changes: 47 additions & 0 deletions src/commands/container/run.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ export class Run extends ExecRenderBaseCommand<typeof Run, Result> {
required: false,
default: false,
}),
cpus: Flags.string({
summary: "set CPU limit for the container",
description:
"Specify the number of CPUs available to the container (e.g., '0.5', '1', '2'). " +
"This is equivalent to the docker run --cpus flag or the deploy.resources.limits.cpus field in docker-compose.",
required: false,
}),
memory: Flags.string({
summary: "set memory limit for the container",
description:
"Specify the maximum amount of memory the container can use (e.g., '512m', '1g', '2g'). " +
"This is equivalent to the docker run --memory flag or the deploy.resources.limits.memory field in docker-compose.",
required: false,
char: "m",
}),
};
static args = {
image: Args.string({
Expand Down Expand Up @@ -268,6 +283,36 @@ export class Run extends ExecRenderBaseCommand<typeof Run, Result> {
return command;
}

/**
* Builds the deploy.resources structure from command line flags
*
* @returns The deploy configuration with resource limits, or undefined if no
* limits are specified
*/
private buildDeployResources():
| { resources: { limits: { cpus?: string; memory?: string } } }
| undefined {
if (!this.flags.cpus && !this.flags.memory) {
return undefined;
}

const limits: { cpus?: string; memory?: string } = {};

if (this.flags.cpus) {
limits.cpus = this.flags.cpus;
}

if (this.flags.memory) {
limits.memory = this.flags.memory;
}

return {
resources: {
limits,
},
};
}

/**
* Builds a container service request from command line arguments and image
* metadata
Expand Down Expand Up @@ -297,6 +342,7 @@ export class Run extends ExecRenderBaseCommand<typeof Run, Result> {
this.flags.publish,
);
const volumes = this.flags.volume;
const deploy = this.buildDeployResources();

return {
image,
Expand All @@ -306,6 +352,7 @@ export class Run extends ExecRenderBaseCommand<typeof Run, Result> {
environment,
ports,
volumes,
deploy,
};
}

Expand Down