8000 feat: add support for `.symfony.local.dist.yaml` and `.symfony.local.… · symfony-cli/symfony-cli@d95bfd2 · GitHub
[go: up one dir, main page]

Skip to content

Commit d95bfd2

Browse files
committed
feat: add support for .symfony.local.dist.yaml and .symfony.local.override.yaml config files
1 parent 046851b commit d95bfd2

8 files changed

+437
-140
lines changed

commands/local_server_start.go

Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -60,32 +60,11 @@ var localServerStartCmd = &console.Command{
6060
Aliases: []*console.Alias{{Name: "server:start"}, {Name: "serve"}},
6161
Usage: "Run a local web server",
6262
Description: localWebServerProdWarningMsg,
63-
Flags: []console.Flag{
63+
Flags: append(
64+
project.ConfigurationFlags,
6465
dirFlag,
65-
&console.BoolFlag{Name: "allow-http", Usage: "Prevent auto-redirection from HTTP to HTTPS"},
66-
&console.StringFlag{Name: "document-root", Usage: "Project document root (auto-configured by default)"},
67-
&console.StringFlag{Name: "passthru", Usage: "Project passthru index (auto-configured by default)"},
68-
&console.IntFlag{Name: "port", DefaultValue: 8000, Usage: "Preferred HTTP port"},
69-
&console.StringFlag{Name: "listen-ip", DefaultValue: "127.0.0.1", Usage: "The IP on which the CLI should listen"},
70-
&console.BoolFlag{Name: "allow-all-ip", Usage: "Listen on all the available interfaces"},
71-
&console.BoolFlag{Name: "daemon", Aliases: []string{"d"}, Usage: "Run the server in the background"},
7266
&console.BoolFlag{Name: "no-humanize", Usage: "Do not format JSON logs"},
73-
&console.StringFlag{Name: "p12", Usage: "Name of the file containing the TLS certificate to use in p12 format"},
74-
&console.BoolFlag{Name: "no-tls", Usage: "Use HTTP instead of HTTPS"},
75-
&console.BoolFlag{Name: "use-gzip", Usage: "Use GZIP"},
76-
&console.StringFlag{
77-
Name: "tls-key-log-file",
78-
Usage: "Destination for TLS master secrets in NSS key log format",
79-
// If 'SSLKEYLOGFILE' environment variable is set, uses this as a
80-
// destination of TLS key log. In this context, the name
81-
// 'SSLKEYLOGFILE' is common, so using 'SSL' instead of 'TLS' name.
82-
// This environment variable is preferred than the key log file
83-
// from the console argument.
84-
EnvVars: []string{"SSLKEYLOGFILE"},
85-
},
86-
&console.BoolFlag{Name: "no-workers", Usage: "Do not start workers"},
87-
&console.BoolFlag{Name: "allow-cors", Usage: "Allow Cross-origin resource sharing (CORS) requests"},
88-
},
67+
),
8968
Action: func(c *console.Context) error {
9069
ui := terminal.SymfonyStyle(terminal.Stdout, terminal.Stdin)
9170
projectDir, err := getProjectDir(c.String("dir"))
@@ -109,12 +88,21 @@ var localServerStartCmd = &console.Command{
10988
return console.Exit("", 1)
11089
}
11190

91+
lw, err := pidFile.LogWriter()
92+
if err != nil {
93+
return err
94+
}
95+
11296
reexec.NotifyForeground("config")
113-
config, fileConfig, err := project.NewConfigFromContext(c, projectDir)
97+
config, err := project.NewConfigFromContext(
98+
c,
99+
zerolog.New(lw).With().Str("source", "server").Timestamp().Logger(),
100+
homeDir,
101+
projectDir,
102+
)
114103
if err != nil {
115104
return errors.WithStack(err)
116105
}
117-
config.HomeDir = homeDir
118106

119107
if config.Daemon && !reexec.IsChild() {
120108
varDir := filepath.Join(homeDir, "var")
@@ -148,20 +136,20 @@ var localServerStartCmd = &console.Command{
148136
if err != nil {
149137
return errors.WithStack(err)
150138
}
151-
if fileConfig != nil && fileConfig.Proxy != nil {
152-
if err := proxyConfig.ReplaceDirDomains(projectDir, fileConfig.Proxy.Domains); err != nil {
139+
if len(config.Proxy.Domains) > 0 {
140+
if err := proxyConfig.ReplaceDirDomains(projectDir, config.Proxy.Domains); err != nil {
153141
return errors.WithStack(err)
154142
}
155143
}
156144

157145
reexec.NotifyForeground("tls")
158-
if !config.NoTLS && config.PKCS12 == "" {
146+
if !config.HTTP.NoTLS && config.HTTP.PKCS12 == "" {
159147
ca, err := cert.NewCA(filepath.Join(homeDir, "certs"))
160148
if err != nil {
161149
return errors.WithStack(err)
162150
} else if !ca.HasCA() {
163151
ui.Warning(fmt.Sprintf(`run "%s server:ca:install" first if you want to run the web server with TLS support, or use "--p12" or "--no-tls" to avoid this warning`, c.App.HelpName))
164-
config.NoTLS = true
152+
config.HTTP.NoTLS = true
165153
} else {
166154
p12 := filepath.Join(homeDir, "certs", "default.p12")
167155
if _, err := os.Stat(p12); os.IsNotExist(err) {
@@ -182,24 +170,19 @@ var localServerStartCmd = &console.Command{
182170
ui.Warning(fmt.Sprintf(`Your local CA must be regenerated, run "%s %s --renew" first to renew it`, c.App.HelpName, localServerCAInstallCmd.FullName()))
183171
}
184172
}
185-
config.PKCS12 = p12
173+
config.HTTP.PKCS12 = p12
186174
}
187175
}
188176

189-
if config.TlsKeyLogFile != "" {
177+
if config.HTTP.TlsKeyLogFile != "" {
190178
ui.Warning(localWebServerTlsKeyLogWarningMsg)
191179
}
192180

193-
if config.AllowCORS {
181+
if config.HTTP.AllowCORS {
194182
ui.Warning(localWebServerAllowsCORSLogWarningMsg)
195183
}
196184

197-
lw, err := pidFile.LogWriter()
198-
if err != nil {
199-
return err
200-
}
201-
config.Logger = zerolog.New(lw).With().Str("source", "server").Timestamp().Logger()
202-
p, err := project.New(config)
185+
p, err := project.New(config, c.App.Version)
203186
if err != nil {
204187
return err
205188
}
@@ -283,7 +266,7 @@ var localServerStartCmd = &console.Command{
283266
}
284267

285268
scheme := "https"
286-
if config.NoTLS {
269+
if config.HTTP.NoTLS {
287270
scheme = "http"
288271
}
289272

@@ -310,7 +293,7 @@ var localServerStartCmd = &console.Command{
310293

311294
reexec.NotifyForeground("listening")
312295
ui.Warning(localWebServerProdWarningMsg)
313-
if config.ListenIp == "127.0.0.1" {
296+
if config.HTTP.ListenIp == "127.0.0.1" {
314297
ui.Warning(`Please note that the Symfony CLI only listens on 127.0.0.1 by default since version 5.10.3.
315298
You can use the --allow-all-ip or --listen-ip flags to change this behavior.`)
316299
}
@@ -321,16 +304,16 @@ var localServerStartCmd = &console.Command{
321304
go tailer.Tail(terminal.Stderr)
322305
}
323306

324-
if fileConfig != nil && !config.NoWorkers {
307+
if !config.NoWorkers {
325308
reexec.NotifyForeground("workers")
326309

327-
_, isDockerComposeWorkerConfigured := fileConfig.Workers[project.DockerComposeWorkerKey]
310+
_, isDockerComposeWorkerConfigured := config.Workers[project.DockerComposeWorkerKey]
328311
var dockerWg sync.WaitGroup
329312
if isDockerComposeWorkerConfigured {
330313
dockerWg.Add(1)
331314
}
332315

333-
for name, worker := range fileConfig.Workers {
316+
for name, worker := range config.Workers {
334317
pidFile := pid.New(projectDir, worker.Cmd)
335318
if pidFile.IsRunning() {
336319
terminal.Eprintfln("<warning>WARNING</> Unable to start worker \"%s\": it is already running for this project as PID %d", name, pidFile.Pid)

0 commit comments

Comments
 (0)
0