This write up was based on Henrik's gist
- Set up a virtual machine on azure, aws, digital ocean or whatever
- Don't forget to Setup inbounding rule (in some cases) for azure: https://docs.microsoft.com/en-us/azure/virtual-machines/windows/nsg-quickstart-portal, for open a listening port
- install dokku http://dokku.viewdocs.io/dokku/
- ssh into your server (ex: ssh [email protected])
- Run these commands in the terminal.
1. Change the app_name to your application name or something like prod or qa.
1. Change app_db to your database name(if you are using postgrex)
1. Change SECRET_KEY_BASE="" to actual key from your
prod.secret.exs
file 1. Optional: You can copy this into a setup.sh file and run it with ./setup.sh. (Remember to change the file permissionchmod u+x ./setup.sh
)
#commands to run on your server
dokku apps:create app_name
dokku config:set app_name BUILDPACK_URL=https://github.com/mbenatti/heroku-buildpack-multi.git
dokku config:set app_name LC_ALL=en_US.utf8
#For postgres
sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git
dokku postgres:create app_db
dokku postgres:link app_db app_name
dokku config:set app_name SECRET_KEY_BASE="key"
#For mongodb
dokku config:set app_name MONGODB_URI="mongodb_uri"
#Port
dokku config:set app_name PORT=80
#Last but not least
dokku config:set app_name MIX_ENV=prod
#add a domain
dokku domains:add app_name sdev.yoursite.com.br
Create the following file in your project root folder
- Create a file named
.buildpacks
with the following content
https://github.com/HashNuke/heroku-buildpack-elixir.git
https://github.com/gjaldon/heroku-buildpack-phoenix-static.git
- Create a file named
elixir_buildpack.config
with the following content (change it to your setting)
erlang_version=19.3
elixir_version=1.4.2
always_rebuild=false
post_compile="pwd"
- Create a file named
phoenix_static_buildpack.config
with the following content (change it to your setting)
node_version=6.10.2
npm_version=3.10.10
#Phx 1.3 configs
phoenix_relative_path=apps/app_web_or_api
assets_path=assets
phoenix_ex=phx
#optional
clean_cache=true
- Open up
config/prod.exs
- Remove this line
import_config "prod.secret.exs"
(at the end of the file) to prevent it from importing prod.secret - Add
secret_key_base: System.get_env("SECRET_KEY_BASE")
underneath the main config. Ex: (not required for stage or dev, search other way do to it skiping this step) - Change 'url: [host: xxx]' to
host: System.get_env("HOSTNAME") || "localhost"
(you can pass the port: 80, if you wish)
```
config :App, App.Endpoint,
http: [port: {:system, "PORT"}],
url: [host: System.get_env("HOSTNAME") || "localhost"],
cache_static_manifest: "priv/static/manifest.json",
secret_key_base: System.get_env("SECRET_KEY_BASE")
```
Remember to add the **comma** before adding `secret_key_base`
- Optional: Add database setting to the end of the file, change
blog
to your app name anddb_name
to your database name 1. Note you must get url fromDATABASE_URL
because that's where Dokku set your database url
config :app, App.Repo,
adapter: Ecto.Adapters.Postgres,
database: "db_name",
url: System.get_env("DATABASE_URL"),
pool_size: 20
#or mongodb
config :app, App.Repo,
adapter: Mongo.Ecto,
url: System.get_env("MONGODB_URI"),
pool_size: 20
- Create a custom RSA key: ssh-keygen -t rsa (or use your id_rsa.pub)
- Enter custom as the file name
- Just set an empty passphrase
- Add the custom.pub key to Dokku's VM by running this command: (refer to the settings of the VM)
$ cat ~/.ssh/id_rsa.pub | ssh [email protected] "sudo sshcommand acl-add dokku my-ssh-key"
- Add a git remote
git remote add ocean dokku@ip_address:app_name
- Note you have to log in using
dokku
as the user - Ex: `git remote add ocean [email protected]:app_name
- Deploy
git push ocean master
- Optional: Setup your database
- ssh into your server
- Migrate database
dokku run app_name mix ecto.migrate
4.Start aplication:dokku run app_name elixir --detached -S mix phoenix.server
You can see all the dokku commands with dokku help
.
- https://gist.github.com/col/a509ee4b73cecb347c97
- http://blog.pragtechnologies.com/deploying-phoenix-using-dokku-in-azure/
- https://gist.github.com/henrik/c70e32544e09c1a79841
- http://www.phoenixframework.org/docs/heroku
- https://www.digitalocean.com/community/tutorials/how-to-use-the-digitalocean-dokku-application
- http://dokku.viewdocs.io/dokku/application-deployment/