[PR #732] [MERGED] Add RunStackService API implementing docker compose run #768

Closed
opened 2025-10-31 15:21:18 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/moghtech/komodo/pull/732
Author: @bpbradley
Created: 8/15/2025
Status: Merged
Merged: 8/21/2025
Merged by: @mbecker20

Base: 1.19.1Head: RunCommand


📝 Commits (5)

  • a8f3f43 Add RunStackService API implementing docker compose run
  • 4891138 Add working Procedure configuration
  • 48be4e9 Remove km execute run alias. Remove redundant ``#[serde(default)]onOption`.
  • b3f346e Refactor command from String to Vec<String>
  • c77d74c Implement proper shell escaping

📊 Changes

24 files changed (+712 additions, -8 deletions)

View changed files

📝 Cargo.toml (+1 -0)
📝 bin/cli/src/command/execute.rs (+7 -0)
📝 bin/core/src/api/execute/mod.rs (+1 -0)
📝 bin/core/src/api/execute/stack.rs (+90 -0)
📝 bin/core/src/helpers/procedure.rs (+17 -0)
📝 bin/core/src/helpers/update.rs (+7 -0)
📝 bin/core/src/resource/procedure.rs (+9 -0)
📝 bin/core/src/sync/resources.rs (+7 -0)
📝 bin/core/src/sync/toml.rs (+7 -0)
📝 bin/periphery/Cargo.toml (+2 -1)
📝 bin/periphery/src/api/compose.rs (+152 -2)
📝 bin/periphery/src/api/mod.rs (+1 -0)
📝 bin/periphery/src/compose/write.rs (+7 -1)
📝 client/core/rs/src/api/execute/mod.rs (+1 -0)
📝 client/core/rs/src/api/execute/stack.rs (+58 -1)
📝 client/core/rs/src/entities/mod.rs (+1 -0)
📝 client/core/ts/src/responses.ts (+2 -1)
📝 client/core/ts/src/types.ts (+29 -0)
📝 client/periphery/rs/src/api/compose.rs (+59 -0)
📝 frontend/package.json (+2 -1)

...and 4 more files

📄 Description

Adds backend support for docker compose run targeting a service defined within a komodo managed stack.

Here is a resource TOML that can be used to create a stack, action, and procedure for testing / validation. Each test is intended to run the same command, which prints hello, world! to stdout in a roundabout way (just to demonstrate usage of most of the features -- I also added a random TZ to demonstrate secrets interpolation was working).

[[stack]]
name = "helloworld"
tags = ["example"]
[stack.config]
server = "server-E1m5R"
post_deploy.command = """
  # Add multiple commands on new lines. Supports comments.
"""
file_contents = """
services:
  hello_world:
    image: alpine:3.19
    environment:
      - TZ=${TZ}
"""
environment = """
  # VARIABLE = value
TZ=[[TZ]]
"""

##

[[procedure]]
name = "RunStackProcedure"
tags = ["example"]

[[procedure.config.stage]]
name = "Stage 1"
enabled = true
executions = [
  { execution.type = "RunStackService", execution.params.stack = "helloworld", execution.params.service = "hello_world", execution.params.command = ["-lc", "echo \"$ENV1\", \"$ENV2\"!"], execution.params.no_deps = true, execution.params.env.ENV2 = "world", execution.params.env.ENV1 = "hello", execution.params.user = "1000:1000", execution.params.entrypoint = "/bin/sh", enabled = true }
]

##

[[action]]
name = "TestRunStack"
tags = ["example"]
[action.config]
file_contents = """
const update = (await komodo.execute_and_poll("RunStackService", {
  stack: "helloworld",
  service: "hello_world",
  command: [
    "-lc",
    'echo "$ENV1", "$ENV2"!'
  ],
  no_deps: true,
  entrypoint: "/bin/sh",
  env: { 
    ENV1: "hello",
    ENV2: "world"
  },
})) as Types.Update;

const runLog = update.logs.find(log => log.stage === "Compose Run");
if (runLog) {
  if (runLog.success) {
    console.log(runLog.stdout);
  } else {
    console.error(runLog.stderr);
  }
} else {
  console.error("No 'Compose Run' stage found in logs.");
}
"""

And km cli implementation

❯ km execute run-stack-service --help
Runs a one-time command against a service using `docker compose run`. Response: [Update]

Usage: km execute run-stack-service [OPTIONS] <STACK> <SERVICE> [COMMAND]...

Arguments:
  <STACK>       Id or name
  <SERVICE>     Service to run
  [COMMAND]...  Command and args to pass to the service container

Options:
      --no-tty                   Do not allocate TTY
      --no-deps                  Do not start linked services
      --service-ports            Map service ports to the host
  -e, --env <ENV>                Extra environment variables for the run
      --workdir <WORKDIR>        Working directory inside the container
      --user <USER>              User to run as inside the container
      --entrypoint <ENTRYPOINT>  Override the default entrypoint
      --pull                     Pull the image before running
  -h, --help                     Print help

Sample:

km execute run-stack-service \
  --no-deps \
  --entrypoint /bin/sh \
  -e 'ENV1=hello&ENV2=world' \
  helloworld hello_world \
  -lc 'echo "$ENV1", "$ENV2"!'

Screenshots

image image

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/moghtech/komodo/pull/732 **Author:** [@bpbradley](https://github.com/bpbradley) **Created:** 8/15/2025 **Status:** ✅ Merged **Merged:** 8/21/2025 **Merged by:** [@mbecker20](https://github.com/mbecker20) **Base:** `1.19.1` ← **Head:** `RunCommand` --- ### 📝 Commits (5) - [`a8f3f43`](https://github.com/moghtech/komodo/commit/a8f3f4372e0abbf62a405dc530a9201d2dfe7da5) Add RunStackService API implementing `docker compose run` - [`4891138`](https://github.com/moghtech/komodo/commit/4891138674ce9fa055b19ba0399b437a37703e2e) Add working Procedure configuration - [`48be4e9`](https://github.com/moghtech/komodo/commit/48be4e930ce5f69f603fcf843e1657d22e5260f4) Remove `km execute run` alias. Remove redundant ``#[serde(default)]` on `Option`. - [`b3f346e`](https://github.com/moghtech/komodo/commit/b3f346e5788b8c1a3dd4ae583d8220a288bb5277) Refactor command from `String` to `Vec<String>` - [`c77d74c`](https://github.com/moghtech/komodo/commit/c77d74c75b3026ea70d3cfd183d7c12be97e07dd) Implement proper shell escaping ### 📊 Changes **24 files changed** (+712 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.toml` (+1 -0) 📝 `bin/cli/src/command/execute.rs` (+7 -0) 📝 `bin/core/src/api/execute/mod.rs` (+1 -0) 📝 `bin/core/src/api/execute/stack.rs` (+90 -0) 📝 `bin/core/src/helpers/procedure.rs` (+17 -0) 📝 `bin/core/src/helpers/update.rs` (+7 -0) 📝 `bin/core/src/resource/procedure.rs` (+9 -0) 📝 `bin/core/src/sync/resources.rs` (+7 -0) 📝 `bin/core/src/sync/toml.rs` (+7 -0) 📝 `bin/periphery/Cargo.toml` (+2 -1) 📝 `bin/periphery/src/api/compose.rs` (+152 -2) 📝 `bin/periphery/src/api/mod.rs` (+1 -0) 📝 `bin/periphery/src/compose/write.rs` (+7 -1) 📝 `client/core/rs/src/api/execute/mod.rs` (+1 -0) 📝 `client/core/rs/src/api/execute/stack.rs` (+58 -1) 📝 `client/core/rs/src/entities/mod.rs` (+1 -0) 📝 `client/core/ts/src/responses.ts` (+2 -1) 📝 `client/core/ts/src/types.ts` (+29 -0) 📝 `client/periphery/rs/src/api/compose.rs` (+59 -0) 📝 `frontend/package.json` (+2 -1) _...and 4 more files_ </details> ### 📄 Description Adds backend support for `docker compose run` targeting a service defined within a komodo managed stack. Here is a resource TOML that can be used to create a stack, action, and procedure for testing / validation. Each test is intended to run the same command, which prints `hello, world!` to stdout in a roundabout way (just to demonstrate usage of most of the features -- I also added a random [[TZ]] to demonstrate secrets interpolation was working). ```toml [[stack]] name = "helloworld" tags = ["example"] [stack.config] server = "server-E1m5R" post_deploy.command = """ # Add multiple commands on new lines. Supports comments. """ file_contents = """ services: hello_world: image: alpine:3.19 environment: - TZ=${TZ} """ environment = """ # VARIABLE = value TZ=[[TZ]] """ ## [[procedure]] name = "RunStackProcedure" tags = ["example"] [[procedure.config.stage]] name = "Stage 1" enabled = true executions = [ { execution.type = "RunStackService", execution.params.stack = "helloworld", execution.params.service = "hello_world", execution.params.command = ["-lc", "echo \"$ENV1\", \"$ENV2\"!"], execution.params.no_deps = true, execution.params.env.ENV2 = "world", execution.params.env.ENV1 = "hello", execution.params.user = "1000:1000", execution.params.entrypoint = "/bin/sh", enabled = true } ] ## [[action]] name = "TestRunStack" tags = ["example"] [action.config] file_contents = """ const update = (await komodo.execute_and_poll("RunStackService", { stack: "helloworld", service: "hello_world", command: [ "-lc", 'echo "$ENV1", "$ENV2"!' ], no_deps: true, entrypoint: "/bin/sh", env: { ENV1: "hello", ENV2: "world" }, })) as Types.Update; const runLog = update.logs.find(log => log.stage === "Compose Run"); if (runLog) { if (runLog.success) { console.log(runLog.stdout); } else { console.error(runLog.stderr); } } else { console.error("No 'Compose Run' stage found in logs."); } """ ``` And km cli implementation ``` ❯ km execute run-stack-service --help Runs a one-time command against a service using `docker compose run`. Response: [Update] Usage: km execute run-stack-service [OPTIONS] <STACK> <SERVICE> [COMMAND]... Arguments: <STACK> Id or name <SERVICE> Service to run [COMMAND]... Command and args to pass to the service container Options: --no-tty Do not allocate TTY --no-deps Do not start linked services --service-ports Map service ports to the host -e, --env <ENV> Extra environment variables for the run --workdir <WORKDIR> Working directory inside the container --user <USER> User to run as inside the container --entrypoint <ENTRYPOINT> Override the default entrypoint --pull Pull the image before running -h, --help Print help ``` Sample: ```sh km execute run-stack-service \ --no-deps \ --entrypoint /bin/sh \ -e 'ENV1=hello&ENV2=world' \ helloworld hello_world \ -lc 'echo "$ENV1", "$ENV2"!' ``` ### Screenshots <img width="1175" height="679" alt="image" src="https://github.com/user-attachments/assets/dfc4e4e2-aa7c-484b-9f12-25295e6b381a" /> <img width="615" height="416" alt="image" src="https://github.com/user-attachments/assets/dd35bcf1-2ed7-4e6f-a313-d76e1b5e990a" /> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2025-10-31 15:21:18 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/komodo#768