@@ -22,7 +22,9 @@ Distillery's guide into scripts.
2222      of 20180524. These samples were pulled from
2323      [ master] ( https://github.com/bitwalker/distillery/blob/fa6777fdc0c61aa8fcad54ffaabbb6829dd4fb38/docs/guides/running_migrations.md ) .
2424  -  [ lib/your_app/release_tasks.ex] ( ./lib/your_app/release_tasks.ex ) .
25-   -  [ rel/commands/migrate.sh] ( ./rel/commands/migrate.sh ) 
25+   -  [ rel/commands/migrate.sh] ( ./rel/commands/migrate.sh )  There is a
26+       difference here where the ` env.prod `  file is sourced to get the
27+       secrets in the environment before running the command.
2628  -  [ rel/config.exs] ( ./rel/config.exs ) 
2729-  [ priv/repo/seeds.exs] ( ./priv/repo/seeds.exs )  Sample seed file. All of
2830    it is commented out, but you can get an idea of what real seeds look
@@ -45,6 +47,7 @@ vary if you use a different OS or SaaS.
4547# find .ssh -print |  cpio -pdmv --owner=deploy ~ deploy 
4648# sudo su - deploy 
4749$ mkdir -p your_app/postgres_backups 
50+ $ mkdir -p your_app/config 
4851``` 
4952
5053## HTTP server  
@@ -62,8 +65,8 @@ $ sudo nginx -c /etc/nginx/nginx.conf -t
6265$ sudo systemctl restart nginx 
6366``` 
6467
65- The sample nginx config is not fit for real  production usage. This will
66- get  you started, but you should definitely setup SSL and HTTPS.
68+ The sample nginx config is not fit for production usage. This will get 
69+ you started, but you should definitely setup SSL and HTTPS.
6770
6871Follow [ Digital Ocean's guide]  for enabling SSL, and make sure You
6972update the server config in ` config/prod.exs ` 
@@ -104,21 +107,24 @@ Please don't use `shh` as your password :\
104107## Copy secrets over  
105108
106109``` bash 
107- #  ~/.bashrc
108- export  LANG=en_US.UTF-8
109- export  MIX_ENV=prod
110- export  REPLACE_OS_VARS=true
111- #  If you're using Phoenix, you'll need this:
112- export  HOST=localhost
113- export  SECRET_KEY_BASE=1234
114- export  PORT=4000
110+ #  ~/your_app/config/env.prod
111+ LANG=en_US.UTF-8
112+ MIX_ENV=prod
113+ REPLACE_OS_VARS=true
114+ RELEASE_NAME=your_app_production
115+ 
116+ #  If you're using Phoenix, you'll need these:
117+ HOST=localhost
118+ SECRET_KEY_BASE=1234
119+ PORT=4000
120+ 
115121#  if you're using Ecto, you'll need these:
116- export   DB_HOST=localhost
117- export   DB_NAME=your_app
118- export   DB_PASS=shh
119- export   DB_PORT=5432
120- export   DB_USER=deploy
121- export   POOL_SIZE=95
122+ DB_HOST=localhost
123+ DB_NAME=your_app
124+ DB_PASS=shh
125+ DB_PORT=5432
126+ DB_USER=deploy
127+ POOL_SIZE=95
122128#  95 leaves you with 5 extra connections for other processes
123129#  Postgres defaults to having 100 connections available
124130``` 
@@ -172,3 +178,75 @@ How to release:
1721781 .  run [ bin/release.sh] ( ./bin/release.sh ) . When prompted, enter the
173179   release version that distillery built. It should be mentioned in the
174180   stdout above the prompt.
181+ 
182+ 
183+ 
184+ # FAQ  
185+ 
186+ ### I have two instances of the app running on the same server. Will this  
187+ work?
188+ 
189+ The ` RELEASE_NAME `  environment variable will be the nodename of that
190+ release, and it's required for that name to be unique. When you have
191+ both instances on the server, edit the ` env.prod `  file for a given
192+ instance and make sure it's unique.
193+ 
194+ ### I don't want to source the environment file before every command  
195+ 
196+ is there a way to automatically do that? I keep forgetting to use
197+ ` REPLACE_OS_VARS=true `  and add my database credentials?
198+ 
199+ Yes! I feelz ya. One way is to add a Distillery plugin that creates a
200+ custom ` boot_check `  script. In this script, copy the [ default boot_check
201+ template]  into ` rel/templates/boot_check.eex ` , but add something like
202+ this before it loads the app:
203+ 
204+ ``` bash 
205+ #  /rel/templates/boot_check.eex
206+ 
207+ ... snip ...
208+ .  " ${SCRIPT_DIR} /../config/env.prod" 
209+ export  REPLACE_OS_VARS=true
210+ 
211+ ... snip ...
212+ ``` 
213+ 
214+ Then create the Distillery plugin that uses this custom boot check template:
215+ 
216+ ``` elixir 
217+ defmodule  YourApp .Release .CustomBootCheck  do 
218+   use  Mix .Releases .Plugin 
219+ 
220+   def  before_assembly (_release , _opts ), do:  nil 
221+ 
222+   def  after_assembly (_release , _opts ), do:  nil 
223+ 
224+   def  before_package (%Release {} =  release, template:  template) do 
225+     info " Generating custom executable.." 
226+ 
227+     executable = 
228+       EEx .eval_file (template, [release_name:  release.name,
229+                                exec_options:  release.profile.exec_opts])
230+ 
231+     bin_path =  Path .join (release.profile.output_dir, " bin"  )
232+ 
233+     File .write! (Path .join (bin_path, Atom .to_string (release.name)), executable)
234+ 
235+     release
236+   end 
237+ 
238+   def  after_package (_release , _opts ), do:  nil 
239+ 
240+   def  after_cleanup (_args , _opts ), do:  nil 
241+ end 
242+ ``` 
243+ 
244+ Finally, tell Distillery to use the plugin:
245+ 
246+ ``` elixir 
247+ #  rel/config.exs
248+ 
249+ plugin YourApp .Release .CustomBootCheck , template:  " rel/templates/boot_check.eex" 
250+ ``` 
251+ 
252+ [ boot_check ] : https://github.com/bitwalker/distillery/blob/master/priv/templates/boot_check.eex 
0 commit comments