Skip to content

Commit 569a9f8

Browse files
committed
Refactor config into kernel, project, etc
1 parent 357b31c commit 569a9f8

20 files changed

+665
-769
lines changed

experimental/runme.yaml

+38-39
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,45 @@
66
# You can test it with the "runme beta" commands.
77
version: v1alpha1
88

9+
# config settings that often use default or a set at points of integration
10+
kernel:
11+
server:
12+
# Also unix:///path/to/file.sock is supported.
13+
address: localhost:7890
14+
tls:
15+
enabled: true
16+
# If not specified, default paths will be used.
17+
# cert_file: "/path/to/cert.pem"
18+
# key_file: "/path/to/key.pem"
19+
20+
log:
21+
enabled: true
22+
path: "/var/tmp/runme.log"
23+
verbose: true
24+
925
# config settings that apply at the repo-level
10-
repo:
26+
project:
27+
# Indicate the root of the runme project. "." means that
28+
# the project root directory will be used.
29+
root: "."
30+
# If true, the project root will be searched upwards starting from "dir".
31+
# If found, the repo root will be used as the project root.
32+
find_repo_upward: true
33+
ignore:
34+
- "node_modules"
35+
- ".venv"
36+
disable_gitignore: false
37+
38+
# It's possible to point at a single file as well.
39+
# filename: "README.md"
40+
41+
# List of dotenv files to load.
42+
env:
43+
use_system_env: true
44+
sources:
45+
- ".env"
46+
- ".env.local"
47+
1148
# The list of filters to apply to blocks.
1249
# "condition" must return a boolean value.
1350
# You can learn about the syntax at https://expr-lang.org/docs/language-definition.
@@ -22,41 +59,3 @@ repo:
2259
# Do not allow code blocks starting with "test".
2360
- type: "FILTER_TYPE_BLOCK"
2461
condition: "!hasPrefix(name, 'test')"
25-
26-
# config settings that often use default or a set at points of integration
27-
core:
28-
# Indicate the root of the runme project. "." means that
29-
# the project root directory will be used.
30-
project:
31-
dir: "."
32-
# If true, the project root will be searched upwards starting from "dir".
33-
# If found, the repo root will be used as the project root.
34-
find_repo_upward: true
35-
ignore:
36-
- "node_modules"
37-
- ".venv"
38-
disable_gitignore: false
39-
40-
# It's possible to point at a single file as well.
41-
# filename: "README.md"
42-
43-
# List of dotenv files to load.
44-
env:
45-
use_system_env: true
46-
sources:
47-
- ".env"
48-
- ".env.local"
49-
50-
server:
51-
# Also unix:///path/to/file.sock is supported.
52-
address: localhost:7890
53-
tls:
54-
enabled: true
55-
# If not specified, default paths will be used.
56-
# cert_file: "/path/to/cert.pem"
57-
# key_file: "/path/to/key.pem"
58-
59-
log:
60-
enabled: true
61-
path: "/var/tmp/runme.log"
62-
verbose: true

internal/api/runme/config/v1alpha1/config.proto

+46-48
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,12 @@ import "buf/validate/validate.proto";
66

77
option go_package = "github.com/stateful/runme/internal/gen/proto/go/runme/config/v1alpha1;configv1alpha1";
88

9-
// ConfigCore describes system-level configuration of the runme toolchain.
10-
message ConfigCore {
11-
// source is a source of Markdown files to look into.
12-
oneof source {
13-
option (buf.validate.oneof).required = true;
14-
15-
// project indicates a dir-based source typically including multiple Markdown files.
16-
Project project = 1;
17-
18-
// filename indicates a single Markdown file.
19-
string filename = 2;
20-
}
21-
22-
// env is the environment variables configuration.
23-
Env env = 3;
24-
9+
// Kernel describes system-level configuration of the runme toolchain.
10+
message Kernel {
2511
// log contains the log configuration.
26-
Log log = 7;
27-
28-
Server server = 8;
12+
Log log = 1;
2913

30-
message Project {
31-
// dir is the directory to look for Markdown files.
32-
string dir = 1;
33-
34-
// find_repo_upward indicates whether to find the nearest Git repository upward.
35-
// This is useful to, for example, recognize .gitignore files.
36-
bool find_repo_upward = 2;
37-
38-
// ignore_paths is a list of paths to ignore relative to dir.
39-
repeated string ignore_paths = 3 [json_name = "ignore"];
40-
41-
// disable_gitignore indicates whether to disable the .gitignore file.
42-
bool disable_gitignore = 4;
43-
}
44-
45-
message Env {
46-
// use_system_env indicates whether to use the system environment variables.
47-
bool use_system_env = 1;
48-
49-
// sources is a list of files with env.
50-
repeated string sources = 2;
51-
}
14+
Server server = 2;
5215

5316
message Log {
5417
// enabled indicates whether to enable logging.
@@ -74,12 +37,44 @@ message ConfigCore {
7437
}
7538
}
7639

77-
// ConfigRepo describes repo-level configuration of the runme toolchain.
78-
message ConfigRepo {
40+
// Project describes repo-level configuration of the runme toolchain.
41+
message Project {
42+
// source is a source of Markdown files to look into.
43+
oneof source {
44+
option (buf.validate.oneof).required = true;
45+
46+
// root indicates a dir-based source typically including multiple Markdown files.
47+
string root = 1;
48+
49+
// filename indicates a single Markdown file.
50+
string filename = 2;
51+
}
52+
53+
// env is the environment variables configuration.
54+
Env env = 3;
55+
56+
// find_repo_upward indicates whether to find the nearest Git repository upward.
57+
// This is useful to, for example, recognize .gitignore files.
58+
bool find_repo_upward = 4;
59+
60+
// ignore_paths is a list of paths to ignore relative to dir.
61+
repeated string ignore_paths = 5 [json_name = "ignore"];
62+
63+
// disable_gitignore indicates whether to disable the .gitignore file.
64+
bool disable_gitignore = 6;
65+
7966
// filters is a list of filters to apply.
8067
// Filters can be applied to documents or
8168
// individual code blocks.
82-
repeated Filter filters = 5;
69+
repeated Filter filters = 7;
70+
71+
message Env {
72+
// use_system_env indicates whether to use the system environment variables.
73+
bool use_system_env = 1;
74+
75+
// sources is a list of files with env.
76+
repeated string sources = 2;
77+
}
8378

8479
message Filter {
8580
// type is the type of the filter.
@@ -105,9 +100,12 @@ message ConfigRepo {
105100

106101
// Config describes the configuration of the runme toolchain, including CLI, server, and clients like VS Code extension.
107102
message Config {
108-
// core is the system-level configuration.
109-
ConfigCore core = 1;
103+
// kernel is the system-level configuration and config that's not specific to one single client
104+
Kernel kernel = 1;
105+
106+
// project contains configuration applicable to the project inside a repo.
107+
Project project = 2;
110108

111-
// repo is the repo-level configuration.
112-
ConfigRepo repo = 2;
109+
// will likely add document to overwrite frontmatter in documents per dir when nested
110+
// Document document = 3;
113111
}

internal/cmd/beta/beta_cmd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ All commands use the runme.yaml configuration file.`,
3030
return autoconfig.Invoke(func(cfg *config.Config) error {
3131
// Override the filename if provided.
3232
if cFlags.filename != "" {
33-
cfg.Core.Filename = cFlags.filename
33+
cfg.Kernel.Filename = cFlags.filename
3434
}
3535

3636
// Add a filter to run only tasks from the specified categories.

internal/cmd/beta/server/grpcurl_utils.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ func getDescriptorSource(ctx context.Context, cfg *config.Config) (grpcurl.Descr
2727
}
2828

2929
func dialServer(ctx context.Context, cfg *config.Config) (*grpc.ClientConn, error) {
30-
tlsConf, err := runmetls.LoadClientConfig(cfg.Core.ServerTLSCertFile, cfg.Core.ServerTLSKeyFile)
30+
tlsConf, err := runmetls.LoadClientConfig(cfg.Kernel.ServerTLSCertFile, cfg.Kernel.ServerTLSKeyFile)
3131
if err != nil {
3232
return nil, err
3333
}
3434

3535
creds := credentials.NewTLS(tlsConf)
3636

37-
network, addr := "tcp", cfg.Core.ServerAddress
37+
network, addr := "tcp", cfg.Kernel.ServerAddress
3838
if strings.HasPrefix(addr, "unix://") {
3939
network, addr = "unix", strings.TrimPrefix(addr, "unix://")
4040
}

internal/cmd/beta/server/server_cmd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func Cmd() *cobra.Command {
1919
) error {
2020
// For the server commands, we want to always log to stdout.
2121
// TODO(adamb): there might be a need to separate client and server logs.
22-
cfg.Core.LogPath = ""
22+
cfg.Kernel.LogPath = ""
2323
return nil
2424
},
2525
)

internal/cmd/beta/server/server_start_cmd.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ func serverStartCmd() *cobra.Command {
2525
defer logger.Sync()
2626

2727
serverCfg := &server.Config{
28-
Address: cfg.Core.ServerAddress,
29-
CertFile: cfg.Core.ServerTLSCertFile,
30-
KeyFile: cfg.Core.ServerTLSKeyFile,
31-
TLSEnabled: cfg.Core.ServerTLSEnabled,
28+
Address: cfg.Kernel.ServerAddress,
29+
CertFile: cfg.Kernel.ServerTLSCertFile,
30+
KeyFile: cfg.Kernel.ServerTLSKeyFile,
31+
TLSEnabled: cfg.Kernel.ServerTLSEnabled,
3232
}
3333

3434
logger.Debug("server config", zap.Any("config", serverCfg))
@@ -39,12 +39,12 @@ func serverStartCmd() *cobra.Command {
3939
}
4040

4141
// When using a unix socket, we want to create a file with server's PID.
42-
if path := pidFileNameFromAddr(cfg.Core.ServerAddress); path != "" {
42+
if path := pidFileNameFromAddr(cfg.Kernel.ServerAddress); path != "" {
4343
logger.Debug("creating PID file", zap.String("path", path))
4444
if err := createFileWithPID(path); err != nil {
4545
return errors.WithStack(err)
4646
}
47-
defer os.Remove(cfg.Core.ServerAddress)
47+
defer os.Remove(cfg.Kernel.ServerAddress)
4848
}
4949

5050
return errors.WithStack(s.Serve())

internal/cmd/beta/server/server_stop_cmd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func serverStopCmd() *cobra.Command {
2626

2727
logger.Debug("stopping the server by looking for runme.pid")
2828

29-
path := pidFileNameFromAddr(cfg.Core.ServerAddress)
29+
path := pidFileNameFromAddr(cfg.Kernel.ServerAddress)
3030
if path == "" {
3131
return errors.New("server address is not a unix socket")
3232
}

internal/config/autoconfig/autoconfig.go

+18-18
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,20 @@ func getConfig(userCfgDir UserConfigDir, viper *viper.Viper) (*config.Config, er
102102
return nil, err
103103
}
104104

105-
if cfg.Core.ServerTLSEnabled {
106-
if cfg.Core.ServerTLSCertFile == "" {
107-
cfg.Core.ServerTLSCertFile = filepath.Join(string(userCfgDir), "cert.pem")
105+
if cfg.Kernel.ServerTLSEnabled {
106+
if cfg.Kernel.ServerTLSCertFile == "" {
107+
cfg.Kernel.ServerTLSCertFile = filepath.Join(string(userCfgDir), "cert.pem")
108108
}
109-
if cfg.Core.ServerTLSKeyFile == "" {
110-
cfg.Core.ServerTLSKeyFile = filepath.Join(string(userCfgDir), "key.pem")
109+
if cfg.Kernel.ServerTLSKeyFile == "" {
110+
cfg.Kernel.ServerTLSKeyFile = filepath.Join(string(userCfgDir), "key.pem")
111111
}
112112
}
113113

114114
return cfg, nil
115115
}
116116

117117
func getLogger(c *config.Config) (*zap.Logger, error) {
118-
if c == nil || !c.Core.LogEnabled {
118+
if c == nil || !c.Kernel.LogEnabled {
119119
return zap.NewNop(), nil
120120
}
121121

@@ -132,16 +132,16 @@ func getLogger(c *config.Config) (*zap.Logger, error) {
132132
ErrorOutputPaths: []string{"stderr"},
133133
}
134134

135-
if c.Core.LogVerbose {
135+
if c.Kernel.LogVerbose {
136136
zapConfig.Level = zap.NewAtomicLevelAt(zap.DebugLevel)
137137
zapConfig.Development = true
138138
zapConfig.Encoding = "console"
139139
zapConfig.EncoderConfig = zap.NewDevelopmentEncoderConfig()
140140
}
141141

142-
if c.Core.LogPath != "" {
143-
zapConfig.OutputPaths = []string{c.Core.LogPath}
144-
zapConfig.ErrorOutputPaths = []string{c.Core.LogPath}
142+
if c.Kernel.LogPath != "" {
143+
zapConfig.OutputPaths = []string{c.Kernel.LogPath}
144+
zapConfig.ErrorOutputPaths = []string{c.Kernel.LogPath}
145145
}
146146

147147
l, err := zapConfig.Build()
@@ -153,24 +153,24 @@ func getProject(c *config.Config, logger *zap.Logger) (*project.Project, error)
153153
project.WithLogger(logger),
154154
}
155155

156-
if c.Core.Filename != "" {
157-
return project.NewFileProject(c.Core.Filename, opts...)
156+
if c.Kernel.Filename != "" {
157+
return project.NewFileProject(c.Kernel.Filename, opts...)
158158
}
159159

160-
projDir := c.Core.ProjectDir
160+
projDir := c.Kernel.ProjectDir
161161
// If no project directory is specified, use the current directory.
162162
if projDir == "" {
163163
projDir = "."
164164
}
165165

166166
opts = append(
167167
opts,
168-
project.WithIgnoreFilePatterns(c.Core.IgnorePaths...),
169-
project.WithRespectGitignore(!c.Core.DisableGitignore),
170-
project.WithEnvFilesReadOrder(c.Core.EnvSourceFiles),
168+
project.WithIgnoreFilePatterns(c.Kernel.IgnorePaths...),
169+
project.WithRespectGitignore(!c.Kernel.DisableGitignore),
170+
project.WithEnvFilesReadOrder(c.Kernel.EnvSourceFiles),
171171
)
172172

173-
if c.Core.FindRepoUpward {
173+
if c.Kernel.FindRepoUpward {
174174
opts = append(opts, project.WithFindRepoUpward())
175175
}
176176

@@ -228,7 +228,7 @@ func getProjectFilters(c *config.Config) ([]project.Filter, error) {
228228
func getSession(cfg *config.Config, proj *project.Project) (*command.Session, error) {
229229
sess := command.NewSession()
230230

231-
if cfg.Core.UseSystemEnv {
231+
if cfg.Kernel.UseSystemEnv {
232232
if err := sess.SetEnv(os.Environ()...); err != nil {
233233
return nil, err
234234
}

internal/config/autoconfig/autoconfig_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ func TestInvokeAll(t *testing.T) {
2626
// Create a runme.yaml using the README.md file from above.
2727
// This won't work with the project as it requires the project
2828
// to be a subdirectory of the current working directory.
29-
configYAML := fmt.Sprintf("version: v1alpha1\ncore:\n filename: %s\n", readmeFilePath)
30-
31-
fmt.Println(string(configYAML))
29+
configYAML := fmt.Sprintf("version: v1alpha1\nproject:\n filename: %s\n", readmeFilePath)
3230

3331
// Create a runme.yaml file in the temp directory.
3432
err = os.WriteFile(filepath.Join(tempDir, "/runme.yaml"), []byte(configYAML), 0o600)

0 commit comments

Comments
 (0)