Skip to content

Commit ea27e92

Browse files
Feature/improve doc and cli (#24)
* feat: Add option to disable reload in web server and update navigation accordingly * feat: Enhance CLI with production mode and logging options; update web application configuration * feat: Update README with production mode and logging options for CLI
1 parent c8708ae commit ea27e92

6 files changed

Lines changed: 71 additions & 9 deletions

File tree

README.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Access at: <http://localhost:4567>
4444
# Run web server (default)
4545
docker run -p 4567:4567 -v "/path/to/resources:/resources" ghcr.io/ionos-cloud/archsight
4646

47+
# Run in production mode with logging
48+
docker run -p 4567:4567 -v "/path/to/resources:/resources" ghcr.io/ionos-cloud/archsight web --production
49+
4750
# Run lint
4851
docker run -v "/path/to/resources:/resources" ghcr.io/ionos-cloud/archsight lint -r /resources
4952

@@ -62,13 +65,31 @@ Access web interface at: <http://localhost:4567>
6265
## CLI Commands
6366

6467
```bash
65-
archsight web [--resources PATH] [--port PORT] # Start web server
66-
archsight lint [--resources PATH] # Validate YAML and relations
67-
archsight template KIND # Generate YAML template for a resource type
68-
archsight console [--resources PATH] # Interactive Ruby console
69-
archsight version # Show version
68+
archsight web [OPTIONS] # Start web server
69+
archsight lint # Validate YAML and relations
70+
archsight import # Execute pending imports
71+
archsight analyze # Execute analysis scripts
72+
archsight template KIND # Generate YAML template for a resource type
73+
archsight console # Interactive Ruby console
74+
archsight version # Show version
75+
```
76+
77+
### Web Server Options
78+
79+
```bash
80+
archsight web [--resources PATH] [--port PORT] [--host HOST]
81+
[--production] [--disable-reload] [--enable-logging]
7082
```
7183

84+
| Option | Description |
85+
|--------|-------------|
86+
| `-r, --resources PATH` | Path to resources directory |
87+
| `-p, --port PORT` | Port to listen on (default: 4567) |
88+
| `-H, --host HOST` | Host to bind to (default: localhost) |
89+
| `--production` | Run in production mode (quiet startup) |
90+
| `--disable-reload` | Disable the reload button in the UI |
91+
| `--enable-logging` | Enable request logging (default: false in dev, true in prod) |
92+
7293
## Features
7394

7495
### MCP Server

lib/archsight/cli.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@ def self.exit_on_failure?
1616
desc "web", "Start the web server"
1717
option :port, aliases: "-p", type: :numeric, default: 4567, desc: "Port to listen on"
1818
option :host, aliases: "-H", type: :string, default: "localhost", desc: "Host to bind to"
19+
option :production, type: :boolean, default: false, desc: "Run in production mode"
20+
option :disable_reload, type: :boolean, default: false, desc: "Disable the reload button in the UI"
21+
option :enable_logging, type: :boolean, default: nil, desc: "Enable request logging (default: false in dev, true in prod)"
1922
def web
2023
configure_resources
2124
require "archsight/web/application"
25+
26+
env = options[:production] ? :production : :development
27+
Archsight::Web::Application.configure_environment!(env, logging: options[:enable_logging])
28+
Archsight::Web::Application.set :reload_enabled, !options[:disable_reload]
2229
Archsight::Web::Application.setup_mcp!
2330
Archsight::Web::Application.run!(port: options[:port], bind: options[:host])
2431
rescue Archsight::ResourceError => e

lib/archsight/web/application.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,30 @@ def reload!
3535
dur = (Time.new - start) * 1000
3636
puts format("== done %0.2f ms", dur) if database.verbose
3737
end
38+
39+
# Configure application for the given environment
40+
# @param env [Symbol] :development or :production
41+
# @param logging [Boolean, nil] Override default logging setting
42+
def configure_environment!(env, logging: nil)
43+
set :environment, env
44+
45+
if env == :production
46+
set :quiet, true
47+
set :server_settings, { Silent: true }
48+
end
49+
50+
# Determine logging: CLI override > env default (prod=true, dev=false)
51+
enable_logging = logging.nil? ? (env == :production) : logging
52+
use Rack::CommonLogger, $stdout if enable_logging
53+
end
3854
end
3955

4056
configure do
4157
set :views, File.join(__dir__, "views")
4258
set :public_folder, File.join(__dir__, "public")
4359
set :haml, format: :html5
4460
set :server, :puma
61+
set :reload_enabled, true
4562
end
4663

4764
# MCP Server setup
@@ -74,6 +91,18 @@ def db
7491
Archsight::Web::Application.database
7592
end
7693

94+
def reload_enabled?
95+
settings.reload_enabled
96+
end
97+
98+
def production?
99+
settings.environment == :production
100+
end
101+
102+
def development?
103+
settings.environment == :development
104+
end
105+
77106
# Render markdown to HTML with optional URL resolution for repository content
78107
# @param data [String] Markdown content
79108
# @param git_url [String, nil] Git URL for resolving relative paths (e.g., for README images)
@@ -126,6 +155,8 @@ def render_analysis_section(section)
126155
end
127156

128157
get "/reload" do
158+
halt 404, "Reload is disabled" unless settings.reload_enabled
159+
129160
Archsight::Web::Application.reload!
130161
if params["redirect"]&.start_with?("/")
131162
redirect params["redirect"]

lib/archsight/web/views/partials/layout/_navigation.haml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
%a{href: "/"}
66
%i.iconoir-home
77
Archsight
8-
%li
9-
%a{href: "/reload?redirect=#{request.path_info}"}
10-
%i.iconoir-reload-window
11-
Reload
8+
- if reload_enabled?
9+
%li
10+
%a{href: "/reload?redirect=#{request.path_info}"}
11+
%i.iconoir-reload-window
12+
Reload
1213
%ul
1314
%li.search-container
1415
%a.search-help{ href: "/doc/index", "hx-get": "/doc/index", "hx-target": ".content", "hx-swap": "innerHTML", "hx-push-url": "true", title: "Help" }

test/import/progress_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require "test_helper"
4+
require "archsight/import"
45
require "archsight/import/progress"
56
require "stringio"
67

test/import/shared_file_writer_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require "test_helper"
4+
require "archsight/import"
45
require "archsight/import/shared_file_writer"
56
require "tmpdir"
67
require "fileutils"

0 commit comments

Comments
 (0)