Skip to content

Commit 706ca1a

Browse files
authored
Remove virtualenv data xdg directory symlinks (#1148)
## Summary Remove virtualenv data xdg directory symlinks. The current state is quite hard to reason about for the following reason: ### Diverging source of truth We have `.devbox/virtualenv` which supposedly should be the source of truth for plugins. However, upon inspection, it looks like the paths and variables set for `{{ .Virtualenv }}` is pointing at my XDG directory. Because of such divergence, any operations that directly modifies the XDG directory is not reflected in the `.devbox/virtualenv` directory. However, the rest of the devbox CLI regards `.devbox/virtualenv` as the source of truth. This is the root cause of quite a few plugin errors such as mariadb, drupal, and python venv. ### Obscure XDG path The reason we have a hash directory in our XDG path is to avoid path collision. But since I use devbox so often, my XDG paths become a clown show: <img width="920" alt="Screenshot 2023-06-13 at 12 18 10 PM" src="https://github.com/jetpack-io/devbox/assets/2292093/b539362e-bfd7-4594-a7da-6bf76ad2e11c"> This makes it impossible to debug plugins. To get around the paths too long error described in #874, I override the env variable that points to the `.sock` path in our `run_test` scripts. ### TODO - [x] Clean up symlink creation functions - [x] Remove symlink tests ## How was it tested? ``` devbox run build cd examples/databases/mariadb devbox install devbox services up ```
1 parent b6299e0 commit 706ca1a

File tree

18 files changed

+110
-202
lines changed

18 files changed

+110
-202
lines changed

docs/app/docs/devbox_examples/databases/mariadb.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,10 @@ These files are used to setup your database and service, and should not be modif
6060
* This plugin wraps mysqld and mysql_install_db to work in your local project. For more information, see the `flake.nix` created in your `.devbox/virtenv/mariadb` folder.
6161
* This plugin will create a new database for your project in MYSQL_DATADIR if one doesn't exist on shell init.
6262
* You can use `mysqld` to manually start the server, and `mysqladmin -u root shutdown` to manually stop it
63+
* `.sock` filepath can only be maximum 100 characters long. You can point to a different path by setting the `MYSQL_UNIX_PORT` env variable in your `devbox.json` as follows:
64+
65+
```json
66+
"env": {
67+
"MYSQL_UNIX_PORT": "/<some-other-path>/mysql.sock"
68+
}
69+
```

docs/app/docs/devbox_examples/stacks/lapp.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ This example shows how to build a simple application using Apache, PHP, and Post
2121
1. Add the packages using the command below. Installing the packages with `devbox add` will ensure that the plugins are activated:
2222

2323
```bash
24-
devbox add postgres php81 php81Extensions.pgsql apacheHttpd
24+
devbox add postgresql@14 [email protected] php81Extensions.pgsql@latest [email protected]
2525
```
2626

27-
1. Update `devbox.d/apacheHttpd/httpd.conf` to point to the directory with your PHP files. You'll need to update the `DocumentRoot` and `Directory` directives.
27+
1. Update `devbox.d/apache/httpd.conf` to point to the directory with your PHP files. You'll need to update the `DocumentRoot` and `Directory` directives.
2828
1. Follow the instructions above in the How to Run section to initialize your project

docs/app/docs/devbox_examples/stacks/lepp.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ In this directory, run:
1919

2020
This will run `initdb` automatically on initialization. To start the Servers + Postgres service, run:
2121

22-
`devbox services start`
22+
`devbox services up`
2323

2424
### Creating the DB
2525

@@ -35,8 +35,16 @@ You can query Nginx on port 80, which will route to the PHP example.
3535
1. Add the packages using the command below. Installing the packages with `devbox add` will ensure that the plugins are activated:
3636

3737
```bash
38-
devbox add postgres php81 php81Extensions.pgsql nginx
38+
devbox add postgresql@14 [email protected] php81Extensions.pgsql@latest nginx@1.24
3939
```
4040

4141
1. Update `devbox.d/nginx/httpd.conf` to point to the directory with your PHP files. You'll need to update the `root` directive to point to your project folder
4242
2. Follow the instructions above in the How to Run section to initialize your project.
43+
44+
Note that the `.sock` filepath can only be maximum 100 characters long. You can point to a different path by setting the `PGHOST` env variable in your `devbox.json` as follows:
45+
46+
```json
47+
"env": {
48+
"PGHOST": "/<some-shorter-path>"
49+
}
50+
```
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# mariadb
2+
3+
## mariadb Notes
4+
5+
1. Start the mariadb server using `devbox services up`
6+
1. Create a database using `"mysql -u root < setup_db.sql"`
7+
1. You can now connect to the database from the command line by running `devbox run connect_db`
8+
9+
## Services
10+
11+
* mariadb
12+
13+
Use `devbox services start|stop [service]` to interact with services
14+
15+
## This plugin sets the following environment variables
16+
17+
* MYSQL_BASEDIR=/<projectDir>/.devbox/nix/profile/default
18+
* MYSQL_HOME=/<projectDir>/.devbox/virtenv/mariadb/run
19+
* MYSQL_DATADIR=/<projectDir>/.devbox/virtenv/mariadb/data
20+
* MYSQL_UNIX_PORT=/<projectDir>/.devbox/virtenv/mariadb/run/mysql.sock
21+
* MYSQL_PID_FILE=/<projectDir>/.devbox/virtenv/mariadb/run/mysql.pid
22+
23+
To show this information, run `devbox info mariadb`
24+
25+
Note that the `.sock` filepath can only be maximum 100 characters long. You can point to a different path by setting the `MYSQL_UNIX_PORT` env variable in your `devbox.json` as follows:
26+
27+
```
28+
"env": {
29+
"MYSQL_UNIX_PORT": "/<some-other-path>/mysql.sock"
30+
}
31+
```

examples/databases/mariadb/devbox.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
"mysql -u devbox_user -p -D devbox_lamp"
1010
],
1111
"test_db_setup": [
12+
"mkdir -p /tmp/devbox/mariadb/run",
13+
"export MYSQL_UNIX_PORT=/tmp/devbox/mariadb/run/mysql.sock",
1214
"devbox services up -b",
1315
"sleep 5",
1416
"mysql -u root < setup_db.sql",

examples/databases/mariadb/devbox.lock

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
{
22
"lockfile_version": "1",
33
"packages": {
4-
"mariadb": {
5-
"resolved": "github:NixOS/nixpkgs/f80ac848e3d6f0c12c52758c0f25c10c97ca3b62#mariadb"
6-
},
74
"mariadb@latest": {
85
"last_modified": "2023-05-01T16:53:22Z",
96
"plugin_version": "0.0.1",

examples/databases/postgres/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
You need to initialize and create a database as part of your setup.
66

77
1. Initialize a DB by running `initdb`
8-
2. Start the Postgres server using `devbox services start`
9-
3. Create a database using `createdb <name_of_db>`
10-
4. You can now connect to the database from the command line by running `psql <name_of_db>`
8+
1. Start the Postgres server using `devbox services up`
9+
1. Create a database using `createdb <name_of_db>`
10+
1. You can now connect to the database from the command line by running `psql <name_of_db>`
1111

1212
To start the database manually run `pg_ctl -l .devbox/conf/postgresql/logfile start`.
1313
To stop use `pg_ctl stop`.
@@ -18,9 +18,9 @@ To stop use `pg_ctl stop`.
1818

1919
Use `devbox services start|stop [service]` to interact with services
2020

21-
## This configuration sets the following environment variables
21+
## This plugin sets the following environment variables
2222

23-
* PGDATA=/Users/johnlago/src/devbox-examples/databases/postgres/.devbox/conf/postgresql/data
24-
* PGHOST=/Users/johnlago/src/devbox-examples/databases/postgres/.devbox/virtenv/postgresql
23+
* PGDATA=/<projectDir>/.devbox/conf/postgresql/data
24+
* PGHOST=/<projectDir>/.devbox/virtenv/postgresql
2525

26-
To show this information, run `devbox info postgresql`
26+
To show this information, run `devbox info postgresql`
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"packages": [
3-
"postgresql"
3+
"postgresql@latest"
44
],
55
"shell": {
66
"init_hook": null
77
}
8-
}
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"lockfile_version": "1",
3+
"packages": {
4+
"postgresql@latest": {
5+
"last_modified": "2023-05-01T16:53:22Z",
6+
"resolved": "github:NixOS/nixpkgs/8670e496ffd093b60e74e7fa53526aa5920d09eb#postgresql",
7+
"version": "14.7"
8+
}
9+
}
10+
}

examples/stacks/drupal/devbox.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"init_hook": [],
1111
"scripts": {
1212
"run_test": [
13+
"mkdir -p /tmp/devbox/mariadb/run",
14+
"export MYSQL_UNIX_PORT=/tmp/devbox/mariadb/run/mysql.sock",
1315
"devbox services up -b",
1416
"echo 'Waiting for services to start' && sleep 2",
1517
"./install-drupal.sh",
@@ -18,4 +20,4 @@
1820
]
1921
}
2022
}
21-
}
23+
}

0 commit comments

Comments
 (0)