Skip to content

nullstone-io/elixir-phoenix-quickstart

Repository files navigation

Elixir Phoenix Quickstart

This is a Elixir Phoenix Quickstart for Nullstone. This is based off the official Phoenix Up and Running guide.

How to launch via Nullstone

  1. Create postgresql datastore.
  2. Create a public web app. (Remember app-name for later)
  3. Add the postgresql datastore (from step 1) to the app.
  4. Add the SECRET_KEY_BASE for Rails Cookies capability to the app. (this capability works for Rails and Phoenix)
  5. Provision
nullstone up --wait --block=<app-name> --env=<env-name>
  1. Build, push, and deploy
docker build -t phoenix-quickstart .
nullstone launch --source=phoenix-quickstart --app=<app-name> --env=<env-name>

How to run locally

You can run this project locally inside Docker or using elixir alone. To use docker, this project contains docker-compose.yml that runs with MIX_ENV=dev. This setup ensures that using Docker doesn't inhibit typical development workflows:

  • Hot reload is configured so that changes to the app doesn't require a reboot
  • Dependencies are installed on boot of docker container

Hot reload

The app in docker-compose.yml is configured to automatically reload changes to files. You do not need to rebuild/restart the phoenix app when making changes to code.

Update dependencies

However, when updating dependencies, you will need to restart your docker container. The dependencies will be installed on boot of the docker container.

docker compose restart app

Details about quickstart

This app was generated following these steps.

  1. mix phx.new --app=elixir_phoenix_quickstart .
  2. Change config/dev.exs to ensure local docker works:
# Binding to loopback ipv4 address prevents access from other machines.
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
http: [ip: {0, 0, 0, 0}, port: String.to_integer(System.get_env("PORT") || "9000")],
  1. Change config/dev.exs to use env var for database url:
# Configure your database
config :elixir_phoenix_quickstart, ElixirPhoenixQuickstart.Repo, 
  url: System.get_env("DATABASE_URL"), 
#  username: "postgres",
#  password: "postgres",
#  hostname: "localhost",
#  database: "elixir_phoenix_quickstart_dev",
  ...
  1. mix phx.gen.release --docker
  2. Replace final stage of Dockerfile
FROM nullstone/phoenix
# Only copy the final release from the build stage
COPY --from=builder /app/_build/${MIX_ENV}/rel/elixir_phoenix_quickstart ./