A toy project for Elixir build

theenglishway (time) 14a647a5bc Make release work by adding server: true il y a 4 ans
assets b8aef69bd4 Initial commit il y a 4 ans
config 14a647a5bc Make release work by adding server: true il y a 4 ans
lib b8aef69bd4 Initial commit il y a 4 ans
priv 7043c93a99 Add a build.sh file to build project on the local machine il y a 4 ans
test b8aef69bd4 Initial commit il y a 4 ans
.formatter.exs b8aef69bd4 Initial commit il y a 4 ans
.gitignore b8aef69bd4 Initial commit il y a 4 ans
README.md 03d8281d84 Documenting build and running in production mode il y a 4 ans
mix.exs 2f31d47141 Add a config helper module il y a 4 ans
mix.lock b8aef69bd4 Initial commit il y a 4 ans

README.md

Toy

This project is intended to be a (serious) playground for other Elixir projects of mine in the aspects of build, integration and deployment.

Goals

  • Document build
  • [] Implement and document cross-build
  • [] Install the project as a systemd service
  • [] Handle the current version via a git tag
  • [] Build as dev or prod

Preconditions

Update Elixir's configuration to the best practices.

For some reason the default configuration of newly-generated Phoenix projects is completely outdated, e.g. using Mix.Config when the standard is now Config.

It is advised above all to update the configuration, and try to match the master branch

PostgreSQL role

In dev as well as in prod modes, the role used in config/#{mode}.exs must be created using e.g. the command line : sudo -u postgres createuser -P role_name

(add -d flag to allow database creation)

PostgreSQL database

In dev as well as in prod modes, the role used in config/#{mode}.exs must be created using e.g. the command line : sudo -u postgres createdb -O role_name db_name

Running the server

In development mode

The PostgreSQL role/database must be installed, if required.

To start the server in dev mode :

  • Install dependencies with mix deps.get
  • Install Node.js dependencies with mix cmd npm install --prefix assets
  • Start the server : mix phx.server or iex -S mix phx.server to run within a shell

The server can now be accessed on localhost:4000.

In production mode

In production mode some configuration is extracted from the environment.

  • Generate a secret key using mix phx.gen.secret
  • Install dependencies with mix deps.get --only prod
  • Compile the application MIX_ENV=prod mix compile
  • Compile static assets into priv/static : npm run deploy --prefix ./assets
  • Compress and digest static assets mix phx.digest
  • Start the server : MIX_ENV=prod DATABASE_URL=db-url SECRET_KEY_BASE=secret_key PORT=port mix phx.server