Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor of experimental config aka config+ #553

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 42 additions & 39 deletions experimental/runme.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,27 @@
# You can test it with the "runme beta" commands.
version: v1alpha1

# Indicate the root of the runme project. "." means that
# the project root directory will be used.
# config settings that often use default or a set at points of integration
kernel:
server:
# Also unix:///path/to/file.sock is supported.
address: localhost:7890
tls:
enabled: true
# If not specified, default paths will be used.
# cert_file: "/path/to/cert.pem"
# key_file: "/path/to/key.pem"

log:
enabled: true
path: "/var/tmp/runme.log"
verbose: true

# config settings that apply at the repo-level
project:
dir: "."
# Indicate the root of the runme project. "." means that
# the project root directory will be used.
root: "."
# If true, the project root will be searched upwards starting from "dir".
# If found, the repo root will be used as the project root.
find_repo_upward: true
Expand All @@ -18,41 +35,27 @@ project:
- ".venv"
disable_gitignore: false

# It's possible to point at a single file as well.
# filename: "README.md"
# It's possible to point at a single file as well.
# filename: "README.md"

# List of dotenv files to load.
env:
use_system_env: true
sources:
- ".env"
- ".env.local"

# The list of filters to apply to blocks.
# "condition" must return a boolean value.
# You can learn about the syntax at https://expr-lang.org/docs/language-definition.
# Available fields are defined in [config.FilterDocumentEnv] and [config.FilterBlockEnv].
filters:
# Do not allow unnamed code blocks.
- type: "FILTER_TYPE_BLOCK"
condition: "is_named"
# Do not allow code blocks without a language.
- type: "FILTER_TYPE_BLOCK"
condition: "language != ''"
# Do not allow code blocks starting with "test".
- type: "FILTER_TYPE_BLOCK"
condition: "!hasPrefix(name, 'test')"

server:
# Also unix:///path/to/file.sock is supported.
address: localhost:7890
tls:
enabled: true
# If not specified, default paths will be used.
# cert_file: "/path/to/cert.pem"
# key_file: "/path/to/key.pem"
# List of dotenv files to load.
env:
use_system_env: true
sources:
- ".env"
- ".env.local"

log:
enabled: true
path: "/var/tmp/runme.log"
verbose: true
# The list of filters to apply to blocks.
# "condition" must return a boolean value.
# You can learn about the syntax at https://expr-lang.org/docs/language-definition.
# Available fields are defined in [config.FilterDocumentEnv] and [config.FilterBlockEnv].
filters:
# Do not allow unnamed code blocks.
- type: "FILTER_TYPE_BLOCK"
condition: "is_named"
# Do not allow code blocks without a language.
- type: "FILTER_TYPE_BLOCK"
condition: "language != ''"
# Do not allow code blocks starting with "test".
- type: "FILTER_TYPE_BLOCK"
condition: "!hasPrefix(name, 'test')"
110 changes: 60 additions & 50 deletions internal/api/runme/config/v1alpha1/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,45 @@ import "buf/validate/validate.proto";

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

// Config describes the configuration of the runme tools, including CLI, server, and clients like VS Code extension.
message Config {
// Kernel describes system-level configuration of the runme toolchain.
message Kernel {
// log contains the log configuration.
Log log = 1;

Server server = 2;

message Log {
// enabled indicates whether to enable logging.
bool enabled = 1;

// path is the path to the log output file.
string path = 2;

// verbose is the verbosity level of the log.
bool verbose = 3;
}

message Server {
string address = 1;

TLS tls = 2;

message TLS {
bool enabled = 1;
string cert_file = 2;
string key_file = 3;
}
}
}

// Project describes repo-level configuration of the runme toolchain.
message Project {
// source is a source of Markdown files to look into.
oneof source {
option (buf.validate.oneof).required = true;

// project indicates a dir-based source typically including multiple Markdown files.
Project project = 1;
// root indicates a dir-based source typically including multiple Markdown files.
string root = 1;

// filename indicates a single Markdown file.
string filename = 2;
Expand All @@ -22,29 +53,27 @@ message Config {
// env is the environment variables configuration.
Env env = 3;

// filters is a list of filters to apply.
// Filters can be applied to documents or
// individual code blocks.
repeated Filter filters = 5;
// find_repo_upward indicates whether to find the nearest Git repository upward.
// This is useful to, for example, recognize .gitignore files.
bool find_repo_upward = 4;

// log contains the log configuration.
Log log = 7;
// ignore_paths is a list of paths to ignore relative to dir.
repeated string ignore_paths = 5 [json_name = "ignore"];

Server server = 8;
// disable_gitignore indicates whether to disable the .gitignore file.
bool disable_gitignore = 6;

message Project {
// dir is the directory to look for Markdown files.
string dir = 1;

// find_repo_upward indicates whether to find the nearest Git repository upward.
// This is useful to, for example, recognize .gitignore files.
bool find_repo_upward = 2;
// filters is a list of filters to apply.
// Filters can be applied to documents or
// individual code blocks.
repeated Filter filters = 7;

// ignore_paths is a list of paths to ignore relative to dir.
repeated string ignore_paths = 3 [json_name = "ignore"];
message Env {
// use_system_env indicates whether to use the system environment variables.
bool use_system_env = 1;

// disable_gitignore indicates whether to disable the .gitignore file.
bool disable_gitignore = 4;
// sources is a list of files with env.
repeated string sources = 2;
}

message Filter {
Expand All @@ -67,35 +96,16 @@ message Config {
FILTER_TYPE_BLOCK = 1;
FILTER_TYPE_DOCUMENT = 2;
}
}

message Env {
// use_system_env indicates whether to use the system environment variables.
bool use_system_env = 1;

// sources is a list of files with env.
repeated string sources = 2;
}

message Log {
// enabled indicates whether to enable logging.
bool enabled = 1;

// path is the path to the log output file.
string path = 2;

// verbose is the verbosity level of the log.
bool verbose = 3;
}

message Server {
string address = 1;
// Config describes the configuration of the runme toolchain, including CLI, server, and clients like VS Code extension.
message Config {
// kernel is the system-level configuration and config that's not specific to one single client
Kernel kernel = 1;

TLS tls = 2;
// project contains configuration applicable to the project inside a repo.
Project project = 2;

message TLS {
bool enabled = 1;
string cert_file = 2;
string key_file = 3;
}
}
// will likely add document to overwrite frontmatter in documents per dir when nested
// Document document = 3;
}
4 changes: 2 additions & 2 deletions internal/cmd/beta/beta_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ All commands use the runme.yaml configuration file.`,
return autoconfig.Invoke(func(cfg *config.Config) error {
// Override the filename if provided.
if cFlags.filename != "" {
cfg.Filename = cFlags.filename
cfg.Kernel.Filename = cFlags.filename
}

// Add a filter to run only tasks from the specified categories.
if len(cFlags.categories) > 0 {
cfg.Filters = append(cfg.Filters, &config.Filter{
cfg.Repo.Filters = append(cfg.Repo.Filters, &config.Filter{
Type: config.FilterTypeBlock,
Condition: `len(intersection(categories, extra.categories)) > 0`,
Extra: map[string]interface{}{"categories": cFlags.categories},
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/beta/server/grpcurl_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ func getDescriptorSource(ctx context.Context, cfg *config.Config) (grpcurl.Descr
}

func dialServer(ctx context.Context, cfg *config.Config) (*grpc.ClientConn, error) {
tlsConf, err := runmetls.LoadClientConfig(cfg.ServerTLSCertFile, cfg.ServerTLSKeyFile)
tlsConf, err := runmetls.LoadClientConfig(cfg.Kernel.ServerTLSCertFile, cfg.Kernel.ServerTLSKeyFile)
if err != nil {
return nil, err
}

creds := credentials.NewTLS(tlsConf)

network, addr := "tcp", cfg.ServerAddress
network, addr := "tcp", cfg.Kernel.ServerAddress
if strings.HasPrefix(addr, "unix://") {
network, addr = "unix", strings.TrimPrefix(addr, "unix://")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/beta/server/server_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func Cmd() *cobra.Command {
) error {
// For the server commands, we want to always log to stdout.
// TODO(adamb): there might be a need to separate client and server logs.
cfg.LogPath = ""
cfg.Kernel.LogPath = ""
return nil
},
)
Expand Down
12 changes: 6 additions & 6 deletions internal/cmd/beta/server/server_start_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ func serverStartCmd() *cobra.Command {
defer logger.Sync()

serverCfg := &server.Config{
Address: cfg.ServerAddress,
CertFile: cfg.ServerTLSCertFile,
KeyFile: cfg.ServerTLSKeyFile,
TLSEnabled: cfg.ServerTLSEnabled,
Address: cfg.Kernel.ServerAddress,
CertFile: cfg.Kernel.ServerTLSCertFile,
KeyFile: cfg.Kernel.ServerTLSKeyFile,
TLSEnabled: cfg.Kernel.ServerTLSEnabled,
}

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

// When using a unix socket, we want to create a file with server's PID.
if path := pidFileNameFromAddr(cfg.ServerAddress); path != "" {
if path := pidFileNameFromAddr(cfg.Kernel.ServerAddress); path != "" {
logger.Debug("creating PID file", zap.String("path", path))
if err := createFileWithPID(path); err != nil {
return errors.WithStack(err)
}
defer os.Remove(cfg.ServerAddress)
defer os.Remove(cfg.Kernel.ServerAddress)
}

return errors.WithStack(s.Serve())
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/beta/server/server_stop_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func serverStopCmd() *cobra.Command {

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

path := pidFileNameFromAddr(cfg.ServerAddress)
path := pidFileNameFromAddr(cfg.Kernel.ServerAddress)
if path == "" {
return errors.New("server address is not a unix socket")
}
Expand Down
Loading
Loading