Skip to content

Commit 153d977

Browse files
authored
[plugins] Move conf files out of .devbox and more DEV-1259 DEV-1258 (#362)
## Summary This changes how some plugins work (FKA package configuration) and makes a few related improvements. Specifically: * conf files are moved out of `.devbox/conf` and moved to `./devbox.d`. (or `.DevboxDir`) * Files created outside of `.devbox` directory are never overridden. * Hidden files are now saved in `.devbox/virtenv` (or `.Virtenv`) * mariadb plugin has been disabled (not yet ready for prime time, it's the only plugin that requires shims) * Added service to postgresql (I forget it in previous PR) * Only files stored in `bin` get file mode 755 and sym links. Everything else gets 644 and no link. * Updated all plugins to use new variables. * Added `web/index.html` example file to nginx and apache plugins. Everything is still hidden behind flag so no user change. TODO (in follow up): * Only create non-`.devbox` files when doing `devbox add` (vs now they get created on `shell`, `run`, `generate` etc) (DEV-1260) ## How was it tested? Added: `postgresql`, `nginx`, and `php`. * Inspected configs in `./devbox.d` directory. * Inspected .devbox/virtenv directory. * Started all services. * Created simple `web/index.html` for nginx and curled it. All working.
1 parent 9ca32cb commit 153d977

File tree

18 files changed

+123
-66
lines changed

18 files changed

+123
-66
lines changed

devbox.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"golangci-lint"
55
],
66
"shell": {
7-
"init_hook": "export \"GOROOT=$(go env GOROOT)\""
7+
"init_hook": "export \"GOROOT=$(go env GOROOT)\"",
8+
"scripts": {
9+
"build": "go build -o dist/devbox cmd/devbox/main.go"
10+
}
811
},
912
"nixpkgs": {
1013
"commit": "d01cb18be494e3d860fcfe6be4ad63614360333c"

internal/boxcli/usererr/usererr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (c *combined) Error() string {
5959
if c.source == nil {
6060
return c.userMessage
6161
}
62-
return c.userMessage + ": " + c.source.Error()
62+
return c.userMessage + "\nsource: " + c.source.Error()
6363
}
6464

6565
// Is uses the source error for comparisons

internal/impl/devbox.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (d *Devbox) Shell() error {
211211
opts = append(
212212
opts,
213213
nix.WithEnvVariables(env),
214-
nix.WithPKGConfigDir(filepath.Join(d.configDir, ".devbox/conf/bin")),
214+
nix.WithPKGConfigDir(filepath.Join(d.configDir, pkgcfg.VirtenvBinPath)),
215215
)
216216
}
217217

@@ -299,7 +299,7 @@ func (d *Devbox) RunScript(scriptName string) error {
299299
opts = append(
300300
opts,
301301
nix.WithEnvVariables(env),
302-
nix.WithPKGConfigDir(filepath.Join(d.configDir, ".devbox/conf/bin")),
302+
nix.WithPKGConfigDir(filepath.Join(d.configDir, pkgcfg.VirtenvBinPath)),
303303
)
304304
}
305305

@@ -335,7 +335,7 @@ func (d *Devbox) Exec(cmds ...string) error {
335335
}
336336

337337
env := []string{}
338-
confBinPath := ""
338+
virtenvBinPath := ""
339339
if featureflag.PKGConfig.Enabled() {
340340
envMap, err := pkgcfg.Env(d.cfg.Packages, d.configDir)
341341
if err != nil {
@@ -344,9 +344,9 @@ func (d *Devbox) Exec(cmds ...string) error {
344344
for k, v := range envMap {
345345
env = append(env, fmt.Sprintf("%s=%s", k, v))
346346
}
347-
confBinPath = filepath.Join(d.configDir, ".devbox/conf/bin") + ":"
347+
virtenvBinPath = filepath.Join(d.configDir, pkgcfg.VirtenvBinPath) + ":"
348348
}
349-
pathWithProfileBin := fmt.Sprintf("PATH=%s%s:$PATH", confBinPath, profileBinDir)
349+
pathWithProfileBin := fmt.Sprintf("PATH=%s%s:$PATH", virtenvBinPath, profileBinDir)
350350
cmds = append([]string{pathWithProfileBin}, cmds...)
351351

352352
nixDir := filepath.Join(d.configDir, ".devbox/gen/shell.nix")

internal/pkgcfg/files.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func getConfig(pkg, rootDir string) (*config, error) {
3131
if err != nil {
3232
return nil, errors.WithStack(err)
3333
}
34-
cfg, err := buildConfig(&config{}, pkg, rootDir, string(content))
34+
cfg, err := buildConfig(pkg, rootDir, string(content))
3535
if err != nil {
3636
return nil, errors.WithStack(err)
3737
}

internal/pkgcfg/info.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func printCreateFiles(cfg *config, w io.Writer, markdown bool) error {
9393

9494
_, err := fmt.Fprintf(
9595
w,
96-
"%sThis configuration creates the following helper files:\n%s\n",
96+
"%sThis plugin creates the following helper files:\n%s\n",
9797
lo.Ternary(markdown, "### ", ""),
9898
shims,
9999
)
@@ -112,7 +112,7 @@ func printEnv(cfg *config, w io.Writer, markdown bool) error {
112112

113113
_, err := fmt.Fprintf(
114114
w,
115-
"%sThis configuration sets the following environment variables:\n%s\n",
115+
"%sThis plugin sets the following environment variables:\n%s\n",
116116
lo.Ternary(markdown, "### ", ""),
117117
envVars,
118118
)
@@ -137,7 +137,7 @@ func printSourceEnvMessage(pkg, rootDir string, w io.Writer) error {
137137
_, err = fmt.Fprintf(
138138
w,
139139
"To ensure environment is set, run `source %s/%s/env`\n\n",
140-
confPath,
140+
VirtenvPath,
141141
pkg,
142142
)
143143
}

internal/pkgcfg/package-configuration/apache/httpd.conf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ LoadModule alias_module modules/mod_alias.so
2626
Require all denied
2727
</Directory>
2828

29-
DocumentRoot "${PWD}/web"
30-
<Directory "${PWD}/web">
29+
DocumentRoot "{{ .DevboxDirRoot }}/web"
30+
<Directory "{{ .DevboxDirRoot }}/web">
3131
Options Indexes FollowSymLinks
3232
AllowOverride None
3333
Require all granted
@@ -46,9 +46,9 @@ ErrorLog "${HTTPD_CONFDIR}/error.log"
4646
ServerName php_localhost
4747

4848
UseCanonicalName Off
49-
DocumentRoot "${PWD}/web"
49+
DocumentRoot "{{ .DevboxDirRoot }}/web"
5050

51-
<Directory "${PWD}/web">
51+
<Directory "{{ .DevboxDirRoot }}/web">
5252
Options All
5353
AllowOverride All
5454
<IfModule mod_authz_host.c>
@@ -57,7 +57,7 @@ ErrorLog "${HTTPD_CONFDIR}/error.log"
5757
</Directory>
5858

5959
## Added for php-fpm
60-
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:8082/${PWD}/web/$1
60+
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:8082/{{ .DevboxDirRoot }}/web/$1
6161
DirectoryIndex index.html
6262

6363
</VirtualHost>

internal/pkgcfg/package-configuration/apacheHttpd.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
"version": "0.0.1",
44
"readme": "If you with to edit the config file, please copy it out of the .devbox directory.",
55
"env": {
6-
"HTTPD_CONFDIR": "{{ .DevboxRoot }}/conf/apache",
6+
"HTTPD_CONFDIR": "{{ .DevboxDir }}",
77
"HTTPD_PORT": "8080"
88
},
99
"create_files": {
10-
".devbox/conf/apache/httpd.conf": "apache/httpd.conf"
10+
"{{ .DevboxDir }}/httpd.conf": "apache/httpd.conf",
11+
"{{ .DevboxDirRoot }}/web/index.html": "web/index.html"
1112
},
1213
"services": {
1314
"apache": {
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
{
22
"name": "mariadb",
33
"version": "0.0.1",
4-
"readme": "* This package creates shims and stores them in .devbox/conf/mariadb/bin\n* Use mysql_install_db to initialize data directory\n* Use mysqld to start the server",
4+
"match": "disabled",
5+
"readme": "* This package creates shims and stores them in .devbox/virtenv/mariadb/bin\n* Use mysql_install_db to initialize data directory\n* Use mysqld to start the server",
56
"env": {
67
"MYSQL_BASEDIR": "{{ .DevboxProfileDefault }}",
7-
"MYSQL_HOME": "{{ .DevboxRoot }}/conf/mariadb/run",
8-
"MYSQL_DATADIR": "{{ .DevboxRoot }}/conf/mariadb/data",
9-
"MYSQL_UNIX_PORT": "{{ .DevboxRoot }}/conf/mariadb/run/mysql.sock",
10-
"MYSQL_PID_FILE": "{{ .DevboxRoot }}/conf/mariadb/run/mysql.pid"
8+
"MYSQL_HOME": "{{ .Virtenv }}/run",
9+
"MYSQL_DATADIR": "{{ .Virtenv }}/data",
10+
"MYSQL_UNIX_PORT": "{{ .Virtenv }}/run/mysql.sock",
11+
"MYSQL_PID_FILE": "{{ .Virtenv }}/run/mysql.pid"
1112
},
1213
"create_files": {
13-
".devbox/conf/mariadb/data": "",
14-
".devbox/conf/mariadb/run": "",
15-
".devbox/conf/mariadb/bin/mysql": "mariadb/mysql",
16-
".devbox/conf/mariadb/bin/mysql_install_db": "mariadb/mysql_install_db",
17-
".devbox/conf/mariadb/bin/mysqladmin": "mariadb/mysqladmin",
18-
".devbox/conf/mariadb/bin/mysqld": "mariadb/mysqld"
14+
"{{ .Virtenv }}/data": "",
15+
"{{ .Virtenv }}/run": "",
16+
"{{ .Virtenv }}/bin/mysql": "mariadb/mysql",
17+
"{{ .Virtenv }}/bin/mysql_install_db": "mariadb/mysql_install_db",
18+
"{{ .Virtenv }}/bin/mysqladmin": "mariadb/mysqladmin",
19+
"{{ .Virtenv }}/bin/mysqld": "mariadb/mysqld"
1920
}
2021
}

internal/pkgcfg/package-configuration/nginx.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
{
22
"name": "nginx",
33
"version": "0.0.1",
4-
"readme": "nginx is configured to use .devbox/conf/nginx.conf\n\nTo customize:\n* Use $NGINX_CONFDIR to change the configuration directory\n* Use $NGINX_LOGDIR to change the log directory\n* Use $NGINX_PIDDIR to change the pid directory\n* Use $NGINX_RUNDIR to change the run directory\n* Use $NGINX_SITESDIR to change the sites directory\n* Use $NGINX_TMPDIR to change the tmp directory. Use $NGINX_USER to change the user\n* Use $NGINX_GROUP to customize.",
4+
"readme": "nginx can be configured with env variables\n\nTo customize:\n* Use $NGINX_CONFDIR to change the configuration directory\n* Use $NGINX_LOGDIR to change the log directory\n* Use $NGINX_PIDDIR to change the pid directory\n* Use $NGINX_RUNDIR to change the run directory\n* Use $NGINX_SITESDIR to change the sites directory\n* Use $NGINX_TMPDIR to change the tmp directory. Use $NGINX_USER to change the user\n* Use $NGINX_GROUP to customize.",
55
"env": {
6-
"NGINX_CONFDIR": "{{ .DevboxRoot }}/conf/nginx"
6+
"NGINX_CONFDIR": "{{ .DevboxDir }}/nginx.conf",
7+
"NGINX_PATH_PREFIX": "{{ .Virtenv }}",
8+
"NGINX_TMPDIR": "{{ .Virtenv }}/temp"
79
},
810
"create_files": {
9-
".devbox/conf/nginx/temp": "",
10-
".devbox/conf/nginx/nginx.conf": "nginx/nginx.conf",
11-
".devbox/conf/nginx/fastcgi.conf": "nginx/fastcgi.conf"
11+
"{{ .Virtenv }}/temp": "",
12+
"{{ .DevboxDir }}/nginx.conf": "nginx/nginx.conf",
13+
"{{ .DevboxDir }}/fastcgi.conf": "nginx/fastcgi.conf",
14+
"{{ .DevboxDirRoot }}/web/index.html": "web/index.html"
1215
},
1316
"services": {
1417
"nginx": {
15-
"start": "nginx -p $NGINX_CONFDIR -c nginx.conf -e error.log -g \"pid nginx.pid;\"",
18+
"start": "nginx -p $NGINX_PATH_PREFIX -c $NGINX_CONFDIR -e error.log -g \"pid nginx.pid;\"",
1619
"stop": "pkill nginx"
1720
}
1821
}

internal/pkgcfg/package-configuration/nginx/nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ server {
44
listen 80;
55
listen [::]:80;
66
server_name localhost;
7-
root {{ .UserRoot }}/web;
7+
root {{ .DevboxDirRoot }}/web;
88

99
error_log error.log error;
1010
access_log access.log;

0 commit comments

Comments
 (0)