Commit 3942708
committed
allow for workflows that export all env vars
when developing locally, I really like the following flow:
- launch a new postgres db with `./run-postgres-latest.sh`
- be able to *programmatically* set the necessary env vars so that
Metabase connects to that new postgres DB
- later, being able to *programmatically* switch to a different
AppDB (e.g. back and forth between postgres and mariadb)
I've been using a hacky version of these dev tools for a while to
accomplish that and figured I'd fix things up and push to see if this
workflow appealed to anyone else.
The following scripts have changed in the exact same way for mariadb,
mysql, and postgres:
First, `./run-$db-latest.sh` now sets one additional context variable:
`[DATABASE]_BROAD_VERSION`. This allows us to figure out the right container
for, e.g. `oldest` postgres, without worrying about whether the oldest
version when you started the DB was v1 and now it's v2
Second, `./_run-$db.sh` now:
- starts the container, then
- runs `source ./env-$db.sh`, before
- spitting out a human-readable message about how to connect to the
database.
Finally, `./env-$db.sh` now:
- takes a "broad version" (latest or oldest)
- is an *output*, not an *input*, to the process of starting an
instance (i.e. before you would run it before running the container, now
you run it *after* running the container)
- pulls data *from the container itself*, reducing duplication (e.g. it
figures out what the `MYSQL_DATABASE` you launched mysql with was,
rather than making sure it's in sync)
- `export`s all relevant env vars required to set up metabase with that
database, e.g. `MB_DB_HOST` or `MB_DB_PORT`.
One other change: the `docker run` commands no longer explicitly set a
host port. Instead we just expose a public port, and the `./env-$db.sh`
scripts use `port=$(docker port ${container} 3306/tcp | cut -d: -f2)` to
figure out the appropriate host port.
Personally, I use this like so:
```
(defun metabase-mariadb-jack-in! ()
(interactive)
(shell-command "/Users/jds/src/dev-scripts/run-mariadb-latest.sh")
(metabase-mariadb-jack-in "latest"))
(defun metabase-mariadb-oldest-jack-in! ()
(interactive)
(shell-command "/Users/jds/src/dev-scripts/run-mariadb-oldest.sh")
(metabase-mariadb-jack-in "oldest"))
(defun metabase-mariadb-jack-in (version)
"Connect to MariaDB and start metabase"
(interactive)
(ignore-errors (cider-quit))
(metabase-reset-env!)
(set-env-from-shell "/Users/jds/src/dev-scripts/env-mariadb.sh" version)
(metabase-jack-in))
```
This way, in emacs, I can run `metabase-mariadb-oldest-jack-in!` and
automatically:
- blow away the old `mariadb` DB and launch a new one
- set the env up to connect to the new container
- and restart cider to actually connect to it
Similarly, `(metabase-mariadb-jack-in "latest")` kills cider, sets up
the env to connect to the *existing* latest mariadb container I have
running, and then relaunches cider.1 parent dbeb200 commit 3942708
13 files changed
+157
-69
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | 5 | | |
| 6 | + | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
11 | | - | |
12 | | - | |
13 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
19 | | - | |
20 | | - | |
21 | | - | |
| 18 | + | |
22 | 19 | | |
23 | | - | |
24 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
25 | 24 | | |
26 | | - | |
| 25 | + | |
| 26 | + | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
28 | 30 | | |
| 31 | + | |
29 | 32 | | |
30 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | 5 | | |
| 6 | + | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
11 | | - | |
12 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
| 20 | + | |
18 | 21 | | |
19 | 22 | | |
20 | | - | |
| 23 | + | |
21 | 24 | | |
22 | 25 | | |
23 | | - | |
| 26 | + | |
24 | 27 | | |
25 | | - | |
| 28 | + | |
26 | 29 | | |
27 | 30 | | |
28 | | - | |
29 | | - | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
5 | | - | |
6 | | - | |
7 | 6 | | |
8 | | - | |
| 7 | + | |
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
16 | | - | |
17 | 15 | | |
18 | | - | |
| 16 | + | |
19 | 17 | | |
20 | | - | |
21 | | - | |
22 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
23 | 21 | | |
24 | 22 | | |
25 | 23 | | |
26 | 24 | | |
27 | 25 | | |
28 | | - | |
| 26 | + | |
29 | 27 | | |
30 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | | - | |
| 34 | + | |
| 35 | + | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
2 | 8 | | |
3 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
4 | 23 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
9 | 29 | | |
10 | 30 | | |
11 | 31 | | |
12 | 32 | | |
13 | | - | |
| 33 | + | |
14 | 34 | | |
15 | 35 | | |
16 | | - | |
| 36 | + | |
17 | 37 | | |
18 | 38 | | |
19 | | - | |
| 39 | + | |
20 | 40 | | |
21 | 41 | | |
22 | 42 | | |
23 | 43 | | |
24 | 44 | | |
25 | 45 | | |
26 | | - | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
2 | 16 | | |
3 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
4 | 23 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
9 | 29 | | |
10 | 30 | | |
11 | 31 | | |
12 | 32 | | |
13 | | - | |
| 33 | + | |
14 | 34 | | |
15 | 35 | | |
16 | | - | |
| 36 | + | |
17 | 37 | | |
18 | 38 | | |
19 | | - | |
| 39 | + | |
20 | 40 | | |
21 | 41 | | |
22 | 42 | | |
23 | 43 | | |
24 | 44 | | |
25 | 45 | | |
26 | | - | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
2 | 23 | | |
3 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
4 | 29 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
10 | 35 | | |
11 | 36 | | |
12 | 37 | | |
13 | 38 | | |
14 | | - | |
| 39 | + | |
15 | 40 | | |
16 | 41 | | |
17 | | - | |
| 42 | + | |
18 | 43 | | |
19 | 44 | | |
20 | | - | |
| 45 | + | |
21 | 46 | | |
22 | 47 | | |
23 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
0 commit comments