Chapter 3

The generator turns source declarations into profile YAML.

This page follows the explicit declaration path in the Go demo. It uses real files from the split Runtime Conditions repos and shows enough surrounding code to make each step clear.

1. The application imports declaration packages

The declarations are regular Go calls. They are intentionally no-op at runtime, but the generator can identify them in the AST.

apps/request-logger-http/conditions.go source
package main

import (
  common "github.com/runtimeconditions/extensions/common-integrations/go"
  env "github.com/runtimeconditions/extensions/env-configuration/go"
)

2. The app declares the runtime integrations it expects

The API declaration names the catalog entry, the HTTP operation the workload calls, the expected response shape, and the environment variable the app reads.

apps/request-logger-http/conditions.go source
func declaration() {
  common.API("todos-api",
    common.Spec("openapi", "catalog://api/default/todos-api", "1.0.0"),
    common.GET("/todos/{id}", common.Response[Todo]()),
    env.Env("baseUrl", "TODOS_API_URL"),
  )

  common.Cache("request-cache",
    common.KeyValue(common.Redis),
    env.EnvAlternative(env.Env("url", "REDIS_URL")),
    env.EnvAlternative(
      env.Env("hostname", "REDIS_HOST"),
      env.Env("port", "REDIS_PORT"),
    ),
  )
}

3. The app uses those env vars in normal runtime code

The profile records the names `TODOS_API_URL` and `REDIS_URL`; it does not provide their values. The adapter supplies those later.

apps/request-logger-http/main.go source
func checkTodosAPI(ctx context.Context) error {
  baseURL := strings.TrimRight(os.Getenv("TODOS_API_URL"), "/")
  if baseURL == "" {
    return errors.New("TODOS_API_URL is not set")
  }

  request, err := http.NewRequestWithContext(
    ctx,
    http.MethodGet,
    baseURL+"/todos/1",
    nil,
  )
  if err != nil {
    return err
  }
  response, err := http.DefaultClient.Do(request)
  if err != nil {
    return fmt.Errorf("todos-api request failed: %w", err)
  }
  defer response.Body.Close()
  return nil
}

4. The declaration helpers themselves do nothing at runtime

This keeps application behavior unchanged. The generator reads calls to these functions; the compiled service just receives inert values.

common-integrations/go/declarations.go source
// API declares an external API dependency.
func API(name string, options ...APIOption) Declaration {
  return Declaration{}
}

// Cache declares a cache dependency.
func Cache(name string, options ...CacheOption) Declaration {
  return Declaration{}
}
env-configuration/go/declarations.go source
type ConditionOption interface {
  common.APIOption
  common.DatastoreOption
  common.CacheOption
  envConfigurationConditionOption()
}

func Env(property, name string, options ...EnvOption) ConditionOption {
  return conditionOption{}
}

5. Run the generator against the app directory

The generator parses the Go AST, finds the declaration calls, resolves their arguments, and emits a Runtime Conditions Profile.

Command
cd go-rc-profiler
go run . \
  -dir ../rc-demos/apps/request-logger-http \
  -name request-logger-http \
  -workload-uri github.com/runtimeconditions/rc-demos/apps/request-logger-http \
  -workload-version v0.1.0

6. The generated profile contains the same requirements

Generated profile excerpt, with full document shape
apiVersion: runtimeconditions.io/v1alpha1
kind: RuntimeConditionsProfile

metadata:
  name: request-logger-http

workload:
  uri: github.com/runtimeconditions/rc-demos/apps/request-logger-http
  version: v0.1.0

extensions:
  - https://runtimeconditions.io/extensions/common-integrations/v1alpha1/runtimeconditions.extension.yaml
  - https://runtimeconditions.io/extensions/env-configuration/v1alpha1/runtimeconditions.extension.yaml

conditions:
  - name: todos-api
    kind: api
    interface:
      type: http
      spec:
        format: openapi
        uri: catalog://api/default/todos-api
        version: 1.0.0
      operations:
        - method: GET
          path: /todos/{id}
    configuration:
      env:
        - property: baseUrl
          name: TODOS_API_URL

  - name: request-cache
    kind: cache
    interface:
      type: key_value
      engine: redis
    configuration:
      alternatives:
        - env:
            - property: url
              name: REDIS_URL

7. Java starts from Maven and Gradle artifacts

The Java profiler discovers Runtime Conditions metadata from Maven and Gradle project layouts, resolved classpath directories, and JAR resources. It currently generates profiles from declarative Java binding packages; SDK/runtime package extraction is intentionally deferred.

Java artifact resource layout
META-INF/runtimeconditions/runtimeconditions.bindings.yaml
META-INF/runtimeconditions/runtimeconditions.package.yaml
META-INF/runtimeconditions/runtimeconditions.extension.yaml
Profile generation command
cd java-rc-profiler
mvn -q package

java -jar target/runtimeconditions-java-profiler-0.1.0-SNAPSHOT.jar generate \
  --project src/testdata/declarative-app \
  --classpath ../extensions/common-integrations/java:../extensions/env-configuration/java \
  --name java-declarative-app \
  --workload-uri example/java-declarative-app \
  --workload-version test