@@ -29,6 +29,138 @@ TRex is a Go-based REST API template for Red Hat TAP (Trusted Application Pipeli
2929- ` make db/teardown ` - Stop and remove PostgreSQL container
3030- ` ./trex migrate ` - Run database migrations
3131
32+ ### TRex CLI Commands
33+
34+ The ` trex ` binary provides three main subcommands for different operational tasks:
35+
36+ #### ` trex serve ` - Start the API Server
37+ Serves the rh-trex REST API with full authentication, database connectivity, and monitoring capabilities.
38+
39+ ** Basic Usage:**
40+ ``` bash
41+ ./trex serve # Start server on localhost:8000
42+ ./trex serve --api-server-bindaddress :8080 # Custom bind address
43+ ```
44+
45+ ** Key Configuration Options:**
46+ - ** Server Binding:**
47+ - ` --api-server-bindaddress ` - API server bind address (default: "localhost:8000")
48+ - ` --api-server-hostname ` - Server's public hostname
49+ - ` --enable-https ` - Enable HTTPS rather than HTTP
50+ - ` --https-cert-file ` / ` --https-key-file ` - TLS certificate files
51+
52+ - ** Database Configuration:**
53+ - ` --db-host-file ` - Database host file (default: "secrets/db.host")
54+ - ` --db-name-file ` - Database name file (default: "secrets/db.name")
55+ - ` --db-user-file ` - Database username file (default: "secrets/db.user")
56+ - ` --db-password-file ` - Database password file (default: "secrets/db.password")
57+ - ` --db-port-file ` - Database port file (default: "secrets/db.port")
58+ - ` --db-sslmode ` - Database SSL mode: disable | require | verify-ca | verify-full (default: "disable")
59+ - ` --db-max-open-connections ` - Maximum open DB connections (default: 50)
60+ - ` --enable-db-debug ` - Enable database debug mode
61+
62+ - ** Authentication & Authorization:**
63+ - ` --enable-jwt ` - Enable JWT authentication validation (default: true)
64+ - ` --enable-authz ` - Enable authorization on endpoints (default: true)
65+ - ` --jwk-cert-url ` - JWK Certificate URL for JWT validation (default: Red Hat SSO)
66+ - ` --jwk-cert-file ` - Local JWK Certificate file
67+ - ` --acl-file ` - Access control list file
68+
69+ - ** OCM Integration:**
70+ - ` --enable-ocm-mock ` - Enable mock OCM clients (default: true)
71+ - ` --ocm-base-url ` - OCM API base URL (default: integration environment)
72+ - ` --ocm-token-url ` - OCM token endpoint URL (default: Red Hat SSO)
73+ - ` --ocm-client-id-file ` - OCM API client ID file (default: "secrets/ocm-service.clientId")
74+ - ` --ocm-client-secret-file ` - OCM API client secret file (default: "secrets/ocm-service.clientSecret")
75+ - ` --self-token-file ` - OCM API privileged offline SSO token file
76+ - ` --ocm-debug ` - Enable OCM API debug logging
77+
78+ - ** Monitoring & Health Checks:**
79+ - ` --health-check-server-bindaddress ` - Health check server address (default: "localhost:8083")
80+ - ` --enable-health-check-https ` - Enable HTTPS for health check server
81+ - ` --metrics-server-bindaddress ` - Metrics server address (default: "localhost:8080")
82+ - ` --enable-metrics-https ` - Enable HTTPS for metrics server
83+
84+ - ** Error Monitoring:**
85+ - ` --enable-sentry ` - Enable Sentry error monitoring
86+ - ` --enable-sentry-debug ` - Enable Sentry debug mode
87+ - ` --sentry-url ` - Sentry instance base URL (default: "glitchtip.devshift.net")
88+ - ` --sentry-key-file ` - Sentry key file (default: "secrets/sentry.key")
89+ - ` --sentry-project ` - Sentry project ID (default: "53")
90+ - ` --sentry-timeout ` - Sentry request timeout (default: 5s)
91+
92+ - ** Performance Tuning:**
93+ - ` --http-read-timeout ` - HTTP server read timeout (default: 5s)
94+ - ` --http-write-timeout ` - HTTP server write timeout (default: 30s)
95+ - ` --label-metrics-inclusion-duration ` - Telemetry collection timeframe (default: 168h)
96+
97+ #### ` trex migrate ` - Run Database Migrations
98+ Executes database schema migrations to set up or update the database structure.
99+
100+ ** Basic Usage:**
101+ ``` bash
102+ ./trex migrate # Run all pending migrations
103+ ./trex migrate --enable-db-debug # Run with database debug logging
104+ ```
105+
106+ ** Configuration Options:**
107+ - ** Database Connection:** (same as serve command)
108+ - ` --db-host-file ` , ` --db-name-file ` , ` --db-user-file ` , ` --db-password-file `
109+ - ` --db-port-file ` , ` --db-sslmode ` , ` --db-rootcert `
110+ - ` --db-max-open-connections ` - Maximum DB connections (default: 50)
111+ - ` --enable-db-debug ` - Enable database debug mode
112+
113+ ** Migration Process:**
114+ - Applies all pending migrations in order
115+ - Creates migration tracking table if needed
116+ - Idempotent - safe to run multiple times
117+ - Logs each migration applied
118+
119+ #### ` trex clone ` - Clone New TRex Instance
120+ Creates a new microservice project based on the TRex template, replacing template content with new service details.
121+
122+ ** Basic Usage:**
123+ ``` bash
124+ ./trex clone --name my-service # Clone with custom name
125+ ./trex clone --name my-service --destination ./my-proj # Custom destination
126+ ./trex clone --repo github.com/myorg --name my-service # Custom git repo
127+ ```
128+
129+ ** Configuration Options:**
130+ - ` --name ` - Name of the new service (default: "rh-trex")
131+ - ` --destination ` - Target directory for new instance (default: "/tmp/clone-test")
132+ - ` --repo ` - Git repository path (default: "github.com/openshift-online")
133+
134+ ** Clone Process:**
135+ - Creates new directory structure
136+ - Replaces template strings throughout codebase
137+ - Updates Go module paths and imports
138+ - Renames files and directories as needed
139+ - Maintains Git history and structure
140+
141+ #### Common Global Flags
142+ All subcommands support these logging flags:
143+ - ` --logtostderr ` - Log to stderr instead of files (default: true)
144+ - ` --alsologtostderr ` - Log to both stderr and files
145+ - ` --log_dir ` - Directory for log files
146+ - ` --stderrthreshold ` - Minimum log level for stderr (default: 2)
147+ - ` -v, --v ` - Log level for verbose logs
148+ - ` --vmodule ` - Module-specific log levels
149+ - ` --log_backtrace_at ` - Emit stack trace at specific file: line
150+
151+ ** Example Production Server Startup:**
152+ ``` bash
153+ ./trex serve \
154+ --api-server-bindaddress " :8000" \
155+ --enable-https \
156+ --https-cert-file /etc/certs/tls.crt \
157+ --https-key-file /etc/certs/tls.key \
158+ --db-sslmode verify-full \
159+ --enable-sentry \
160+ --ocm-base-url https://api.openshift.com \
161+ --disable-ocm-mock
162+ ```
163+
32164### Development Workflow
33165- ` make generate ` - Regenerate OpenAPI client and models
34166- ` make clean ` - Remove temporary generated files
0 commit comments