TIL about just and justfiles
⋅ 2 minute read ⋅ 328 words
just is just a command runner that I recently started using to define aliases for commands in my projects, e.g. build, test, or deploy commands.
§Installation
just can be installed via homebrew:
brew install just§Example
I want to create alias commands for my dbt project to build my dbt models in production vs. development environments. At the moment, I need to run the commands:
# prod warehouse
poetry run dbt run --target prod
# dev warehouse
poetry run dbt run --target devTo define shorter just commands for this project I add a justfile into the project folder.
# justfile
run-prod *ARGS:
poetry run dbt run --target prod {{ARGS}}
run-dev *ARGS:
poetry run dbt run --target dev {{ARGS}}If I am inside the project folder I can now run just run-prod and just run-dev. Moreover, I can pass in any dbt keyword arguments, e.g.
just run-dev --select mymodelwill resolve to
poetry run dbt run --target dev --select mymodel
§Is this not just make?
just is inspired by the Unix build tool
make
from 1978. However, just is not a build system and focuses solely on command running. This avoids having to deal with things like .PHONY that can catch you out in make recipes. I also like two additional features of just:
-
I can run my
justcommands from any subfolder of the project folder that contains thejustfile. This is useful when I work on this blog. I have to runhugo servefrom the top-level project folder and Jupyter-to-markdown converternb2hugofrom thenotebooks/project_x/subfolder. Withjustcommand aliases it doesn’t matter from which folder I run the command. -
justallows you to load environment variables from an.envfile.Example
.env:DATABASE=localhost:1111 USERACCOUNT=rob1234Add
set dotenv-loadto yourjustfileand the environment variables will be available in your shell:set dotenv-load check-vars: @echo "Env vars are DATABASE:$DATABASE and USER:$USERACCOUNT"Running
just check-varswill output:Env vars are DATABASE:localhost:1111 and USER:rob1234
If you have any thoughts, questions, or feedback about this post, I would love to hear it. Please reach out to me via email.
#dbt