The idea is to have a ready to go phoenix project setup with Nix, along with some extra bells and whistles (see Features).
The existing phoenix project is generated using mix phx.new
with Phoenix 1.7.14, but it is easy (execute run delete.phx
) to rip out all the phoenix related files and start from scratch with a new mix phx.new
command as needed.
- Nix setup (using flakes)
- Postgres & pgadmin setup (via Docker Compose)
- Credo and Dialyzer setup
- Livebook attached to the Phoenix app
- Multi env support (using shdotenv)
run
commands for common workflows- Github Actions setup for
- running build & tests in CI (with nix cache & postgres support)
- running lint (credo) and dialyzer in CI
- deploying to fly.io via gh actions or via terminal (currently setup to deploy on manual trigger)
- VSCode Tasks for running tests.
- Installing nix and direnv is required.
- Clone this repo and
cd
into it. - Execute
direnv allow
in the terminal. - Execute
help
in the terminal to see the available commands. - Execute
run deps
in the terminal to install dependencies. - To customize this for your Phoenix project, you have two options:
- Rename and use the existing Phoenix project (Phoenix 1.7.2)
- Remove existing Phoenix project, and generate a new one
- Execute
rename_phoenix_project MODULE=NewName APP=new_otp
which will rename the phoenix project and OTP application toNewName
andnew_otp
respectively.
- If you want to generate your own phoenix project instead of using the existing one, you can do so by executing
run delete.phx
in the terminal. - This will remove all the phoenix related files and directories, and you can generate your own phoenix project using
mix phx.new
. - Note that this will also remove
credo
anddialyxir
from deps. To add it back, just add the following indeps
ofmix.exs
:
# Linting
{:credo, "~> 1.6", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 1.0", only: [:dev], runtime: false}
Following info can also be found by executing help
in the terminal
help
Show help message with available commandsrun [command]
Run any command with dev env loadedrun deps
Install dependenciesrun server
Run the server inside an IEx shellrun server.iex
Run a remote IEx shell connected to the server. useful for debugging in IEX without logs getting in the way.run livebook.setup
Setup livebookrun livebook
Run livebookrun compile
Compile the projectrun db
Start postgres and pgadminrun db.setup
Setup local dbrun db.migrate
Migrate local dbrun db.rollback
Rollback local dbrun db.create_migration <name>
Create new migration scriptrun dev.reset
Reset dev databaserun test.reset
Reset test databaserun test
Run testsrun test.watch
Run test in watch moderun test.cover
Show test coveragerun format
Format project filesrun lint
Lint project filesrun delete.phx
Remove all Phoenix framework related filesrun clean
Removes dependencies, build files, and ElixirLS files
- run commands to be added
run deploy
which will deploy to fly.io- document lint setup, and remaining
run
commands.
- Setup for spawning an IEX shell on production server
- Document env setup (.env.dev in dev environtment, .env.test in test environment, .local files to override them)
Option 1: via terminal
flake.nix
hasflyctl
.flyctl auth login
fly launch
fly secrets set
/cat .env.prod.local | fly secrets import
fly deploy
Option 2: via GH Actions
- todo: add docs