Local development setup
View SourceDirenv
We use direnv for simple local ENV management. See Use cases for the benefits of direnv.
- Use the installation docs to install onto your system, and hook into the shell that you use.
After installation you may need to "allow" the .envrc file.
direnv allow
Custom ENV configuration
You can create a local ENV file that is not part of our repo, allowing any of the default variables to be overridden with your own personal configs!
Example adding SQL debugs to your dev environment.
Note: you only need to run the cmd below once!
touch .envrc_local && echo export DEBUG_SQL="true" > .envrc_local && direnv allow
You'll now have an ENV var set for the custom variable.
printenv | grep DEBUG
Useful ENV vars for local dev
# disable browser tab auto opening
export BROWSER=none
# enable SQL logging
export DEBUG_SQL=true
# enable SSL for local development
export USE_SSL=true
Enabling SSL in Git Worktrees
To enable HTTPS/WSS in your worktree, add this to .envrc_local:
export USE_SSL=true
Then reload direnv:
direnv allow
Your worktree will now use:
https://localhost:4XXX(instead ofhttp://)wss://localhost:4XXX/socket(instead ofws://)
Where 4XXX is your worktree's isolated port (4000 + offset).
Note: Start the backend with USE_SSL=true for SSL to work:
USE_SSL=true iex -S mix phx.server
The self-signed certificates are located at:
api/apps/vetspire_web/priv/dev/samly_sp.pemapi/apps/vetspire_web/priv/dev/samly_sp_key.pem
Branch Databases
Set .envrc_local to use a branch-specific database name:
export DB_NAME="$(git rev-parse --abbrev-ref HEAD | sed "s/\//-/g" | cut -c1-50)"
export TEST_DB_NAME="vetspire_test_$(git rev-parse --abbrev-ref HEAD | sed 's/\//-/g' | cut -c1-36)"
Reload your environment and verify:
direnv allow
env | grep DB_NAME
your-branch-name
Note the dev database is named after the branch with no prefix, while the test
one is vetspire_test_your-branch-name.
Create the database (can only be run once per branch):
mix ecto.setup
Database Setup for Worktrees
For worktrees, run the setup script:
scripts/worktree-setup
This script:
- Clones
api/depsandapi/_buildfrom the best-matching sibling worktree copy-on-write, so ~590MB of build state arrives as a metadata operation (APFS clonefile on macOS, reflink on btrfs/XFS; a plain copy on filesystems with neither, which is slower but works) - Runs
pnpm install(buildingweb/node_modulesfrom pnpm's global store) andmix deps.get, then compiles dev and test concurrently - Creates, migrates and seeds the dev and test databases, or migrates them if they already exist, which is what makes it safe to re-run
Databases are named after your branch (e.g. feat-DI-1234 and vetspire_test_feat-DI-1234).
WORKTREE_SHARED_DB=1 points every worktree at a single shared vetspire_dev /
vetspire_test, which skips seeding (~1 min → ~5 s). The trade-off is isolation:
a destructive migration on one branch is visible to all of them. See
scripts/WORKTREES.md.
Alternatively, you can run the commands manually:
cd api && mix ecto.setup
cd api && MIX_ENV=test mix ecto.setup
If you want a clean database after running the above command, run:
mix ecto.reset
OS-dependant setup
macOS setup instructions
We recommend installing the following applications for development on macOS: ### Homebrew The so called "missing package manager" for macOS. Complete installation instructions can be found [here](https://brew.sh/). ### asdf [asdf](https://asdf-vm.com/) is a package manager responsible for keeping Elixir, Erlang, NodeJS and Python versions consistent with our production environments for all developers. Please see [installation notes](https://github.com/asdf-vm/asdf/issues/785) when installing via brew. ```bash brew install gnupg gnupg2 # Required for Erlang brew install openssl@3.0 brew install asdf asdf plugin add elixir asdf plugin add erlang asdf plugin add nodejs asdf plugin add python asdf plugin add yarn asdf plugin add pnpm export KERL_CONFIGURE_OPTIONS="--disable-debug --without-javac --with-ssl=$(brew --prefix openssl@3.0)" export KERL_INSTALL_HTMLDOCS=no export KERL_DOC_TARGETS="man chunks" asdf install cd api # Authenticate and enable getting Oban.Pro (paid dependency) # Install and compile dependencies mix hex.repo add oban https://repo.oban.pro \ --fetch-public-key SHA256:4/OSKi0NRF91QVVXlGAhb/BIMLnK8NHcx/EWs+aIWPc \ --auth-key 0a0cb15a8ff6f9d6175a9ea19eccff0c mix local.rebar mix deps.get ``` If you run into issues with Erlang installation, try installing complete Xcode app via App Store. You will also likely need to add asdf to your shell - [see documentation](https://asdf-vm.com/guide/getting-started.html#_3-install-asdf). ### Docker Docker makes app deployment across platforms a breeze. You can download it for macOS [here](https://www.docker.com/products/docker-desktop/). This is mainly used for Postgres, but running our (optional) end-to-end tests require it. ### Postgres Run: `DB_USER=postgres DB_PASSWORD=postgres docker compose up db` Instead of installing postgres onto your machine, I recommend installing docker and running a postgres container instance in the background. We'll use the vanilla postgres image provided by the Postgres maintainers. You'll still need the psql client though.[[1]](macos-psql) ```bash brew install libpq ``` If you'd like to manage a local postgres via homebrew instead, steps that worked for [getting PG setup via homebrew are here](/guides/local-postgres.md).Windows setup instructions
We recommend installing the following applications for development on Windows 10: ### Windows Terminal The fastest and most feature-full terminal emulator for Windows. Download [here](https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701). ### Windows Subsystem for Linux Vetspire's frontend project can definitely be developed natively on Windows, but because Vetspire's backend project is built in Erlang and Elixir, getting the backend working natively on Windows can prove to be a little troublesome. Its definitely doable, but requires installing a bunch of different applications so that Elixir can compile native code, and some users do report friction trying to develop Elixir applications natively on Windows. Instead of doing that, I highly recommend enabling Windows 10's `Windows Subsystem for Linux` feature which can be run in one of two modes: - `WSL 1` which acts similarly to `wine` in the Linux world -- it's a syscall translation layer which allows you to run ELF binaries without recompilation on Windows. This works pretty well but can be slow with projects that do a lot of IO. - `WSL 2` which is essentially a super light-weight virtual machine with interoperability and host-OS integrations built in. This performs roughly as well as on a native Linux installation, but requires that your CPU supports virtualization and necessitates the activation of `Hyper-V`, which may be a problem for both battery life and conflict with other virtualization solutions installed on your machine, if any. I personally recommend `WSL 2`, since we can use it to run `docker` without any additional overhead, but either will work fine and have slightly different minor tradeoffs. Enable `WSL` by running the following in an elevated Powershell prompt (`win+x`) ```powershell Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux # If WSL 1, thats all you need to do # If WSL 2, run the following also: Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform wsl.exe --set-default-version 2 ``` Once activated, you can install (technically any) Linux distribution you'd like. I recommend going with [Ubuntu](https://www.microsoft.com/en-us/p/ubuntu/9nblggh4msv6), though if you have a favorite distribution, feel free to use that instead. Once WSL is configured and your Linux distribution of choice is installed, you can proceed to follow the standard Linux setup instructions in the collapsed section below.Nix/NixOS setup instructions
NixOS is a Linux distribution built atop of the Nix package manager which allows you to define your entire development environment (and your entire operating system if you opt to use NixOS over Nix) in a declarative and reproducible way. For those of you who are interested in trying Nix, you can simply install [Nix on MacOS or any Linux distribution](https://nixos.org/download.html). Once that's done, you can simply run `nix-shell` in this directory to automatically download all of Vetspire's dependencies. You can think of `nix` as being similar to `asdf` (or `mix` / any other package manager) for literally any package you might want to install / configure / build. It can handle environment variables as well! Hit @vereis up if you want more nix-shilling 😉 Upon completing this, feel free to run `mix test` in the `api/` directory and `pnpm start` in the `web/` directory 💪 ### Docker / Docker-Compose / Postgres If you're using NixOS, you'll have a better experience if you install docker in your OS's `configuration.nix`, otherwise feel free to install your host OS's docker however you prefer. If you really don't want to pollute your OS's state I've also provided docker in this project's `shell.nix` which you can run yourself via executing `nohup dockerd > /dev/null &`. Once this is done, just `docker-compose up -d` to start all pre-requisite containers. ### Misc You can use [lorri](https://github.com/target/lorri) to automatically start `nix-shell` when you CD into this directory, but this is entirely optional.Linux setup instructions
For the purposes of this section, I'll assume that the OS you have installed is Debian-based (i.e. Ubuntu) and that you're using `bash`. If you're using a different distribution, the general instructions should still work but you may need to research differences in package names and installation instructions for certain tools. ### asdf [asdf](https://asdf-vm.com/) is a package manager responsible for keeping Elixir, Erlang, NodeJS and Python versions consistent with our production environments for all developers. Please see [installation notes](https://github.com/asdf-vm/asdf/issues/785) when installing via brew. ```bash sudo apt-get update sudo apt-get install build-essential sudo apt-get install gnupg gnupg2 # maybe not required, but if installing Erlang poses a difficulty, try this # Install asdf git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.8.1 echo ". $HOME/.asdf/asdf.sh" >> ~/.bashrc echo ". $HOME/.asdf/completions/asdf.bash" >> ~/.bashrc asdf plugin add elixir asdf plugin add erlang asdf plugin add nodejs asdf plugin add python asdf plugin add yarn asdf plugin add pnpm asdf install ``` ### Docker Docker makes app deployment across platforms a breeze. You can install it as follows: ```bash ## make sure that no default docker implementation was installed by default sudo apt-get remove docker docker-engine docker.io containerd runc ## install docker sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io ## test that installation was successful sudo docker run hello-world ## install docker-compose sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose ## test that installation was successful docker-compose --version ``` This is mainly used for Postgres, but running our (optional) end-to-end tests require it. ##### Postgres I highly recommend running Postgres in docker, though even doing so, you may want to install the following to be able to interact with your database via your shell: ```bash sudo apt-get install postgresql-client ``` Alternatively if you'd like to manage a local postgres without docker, steps that worked for [getting PG setup under Ubuntu can be found here](./api/README_LOCAL_PG.md).Vetspire Requirements
ImageMagick
Vetspire utilizes Mogrify which is an Elixir wrapper around ImageMagick.
In order to process images locally you will need to install ImageMagick.
On Mac, you can install it with brew install imagemagick.
On Ubuntu, you can install it with sudo apt-get install imagemagick.
On Windows, you can install it with chocolatey: choco install imagemagick.
Otherwise, please follow instructions on https://imagemagick.org/script/download.php
pdftk-java
Vetspire utilizes pdftk-java for PDF processing.
In order to process PDFs locally you will need to install pdftk-java.
On Mac, you can install it with brew install pdftk-java.
On Ubuntu, you can install it with sudo apt-get install pdftk.
On Windows, you can install it with chocolatey: choco install pdftk.