elixir setting up staging environment code example

Example: elixir creating staging deploy environment

cp prod.exs staging.exs; cp prod.secrets.exs staging.secrets.exs;

nano ./release.sh

# release_executable_location is printed out after the release is finished generating the executable seen as _build/something...
# So add the last line after you know that line (from the rest of the script)

---

echo -n "Deploy Environment (blank for production): "
read environment
if [ -z "$environment" ]; then
environment="prod"
fi

echo -n "Version (blank for 0.1):"
read version
if [ -z "$version" ]; then
version="0.1"
fi

mix deps.get --only $environment
MIX_ENV=$environment mix compile
npm install --prefix ./assets
npm run deploy --prefix ./assets
mix phx.digest
MIX_ENV=$environment mix setup
MIX_ENV=$environment mix release --version $version

release_executable_location eval start

---

chmod 775 release.sh

# Configure your secrets files to define the base key and your database url.
# Add your staging secrets file to gitignore (you dont want connections on the repo)

# Add server: true to your Endpoint configuration inside of staging.secret.exs (you'll also want to do this with production)

config :my_app, MyAppWeb.Endpoint,
       http: [
         port: String.to_integer(System.get_env("PORT") || "4000"),
         transport_options: [socket_opts: [:inet6]]
       ],
       secret_key_base: secret_key_base,
       server: true