Skip to content
GitHub

Service configuration

The select method allows you to create configurable parameters for your services, providing options that can be selected when running the service.

const env = s.select("environment", {
  options: ["development", "production"],
  default: "development",
});
  • name (string): The name/identifier for the configuration parameter
  • options (object):
    • options (array): Available values to choose from
    • default (string): Default value if none is selected
const rspack = ws.service("rspack", (s) => {
  s.autorun();
  s.cwd("client/ui");

  const env = s.select("environment", {
    options: ["development", "production"],
    default: "development",
  });

  const port = s.select("port", {
    options: ["3010", "3020"],
    default: "3010",
  });

  s.run(async (ctx) => {
    let envValue = ctx.get(env);
    let portValue = ctx.get(port);

    await ctx.process({
      alias: "rspack",
      cmd: "./node_modules/.bin/rsbuild",
      args: ["dev", "--port", portValue],
      env: {
        NODE_ENV: envValue,
        RSPACK_DEV_SERVER_PORT: portValue,
        RSPACK_DEV_SERVER_HOST: "localhost",
      },
    });
  });
});

Use ctx.get(configVariable) within the s.run() callback to retrieve the selected value:

s.run(async (ctx) => {
  let selectedEnv = ctx.get(env);
  let selectedPort = ctx.get(port);

  // Use the values in your process configuration
});

This allows for flexible service configuration without hardcoding values, making services adaptable to different environments and requirements.

The Runy service UI provides an interactive interface for editing service configurations. When you define configuration parameters using select, they become editable through the web interface.


Service Configuration UI

Configuration editor in the Runy service UI

Configuration changes made through the UI are automatically persisted to a JSON file. This ensures that your selected values are maintained across service restarts and system reboots.

The configuration file is stored in the workspace directory and contains all the selected values for your service parameters:

{
  "services": {
    "rspack": {
      "environment": "production",
      "port": "3020"
    }
  }
}

Changes made through the UI take effect immediately and override the default values specified in your service definition.