allow for workflows that export all env vars#35
Closed
johnswanson wants to merge 1 commit intomasterfrom
Closed
Conversation
acf731d to
4a53ee0
Compare
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.
4a53ee0 to
3942708
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
loom here: https://www.loom.com/share/761bb56d52c6424d93d5cb4ea924bb53?sid=96faa314-71b6-40bb-b3d6-c7eefe798f0d
when developing locally, I really like the following flow:
launch a new postgres db with
./run-postgres-latest.shbe 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.shnow sets one additional context variable:[DATABASE]_BROAD_VERSION. This allows us to figure out the right container for, e.g.oldestpostgres, without worrying about whether the oldest version when you started the DB was v1 and now it's v2Second,
./_run-$db.shnow:source ./env-$db.sh, beforeFinally,
./env-$db.shnow:takes a "broad version" (latest or oldest)
pulls data from the container itself, reducing duplication (e.g. it figures out what the
MYSQL_DATABASEyou launched mysql with was, rather than making sure it's in sync)can be run two ways:
./env-postgres.sh latestspits out the old user-readable message about how to connect to postgressource ./env-postgres.sh latestdoesn't output anything - it sets env vars likeMB_DB_HOST,MB_DB_USER, etc. so that your metabase backend will automatically use this AppDB.psqlwithout any args and connect to the app DB)One other change: the
docker runcommands no longer explicitly set a host port. Instead we just expose a public port, and the./env-$db.shscripts useport=$(docker port ${container} 3306/tcp | cut -d: -f2)to figure out the appropriate host port.Personally, I use this like so:
This way, in emacs, I can run
metabase-mariadb-oldest-jack-in!and automatically:mariadbDB and launch a new oneSimilarly,
(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.