LoginSignup
6
6

More than 5 years have passed since last update.

HerokuでPhoenixアプリケーションを動かす

Posted at

buildpack

このbuildpackを追加することで、Herokuで動かせるようになります。

https://github.com/HashNuke/heroku-buildpack-elixir.git
https://github.com/gjaldon/heroku-buildpack-phoenix-static.git

設定を環境変数にする

config/prod.exs

diff --git a/config/prod.exs b/config/prod.exs
index e502547..2794277 100644
--- a/config/prod.exs
+++ b/config/prod.exs
@@ -12,9 +12,10 @@ use Mix.Config
 # manifest is generated by the mix phoenix.digest task
 # which you typically run after static files are built.
 config :app, App.Endpoint,
-  http: [port: {:system, "PORT"}],
-  url: [host: "example.com", port: 80],
-  cache_static_manifest: "priv/static/manifest.json"
+  http: [port: System.get_env("PORT")],
+  url: [host: System.get_env("HOST"), port: 80],
+  cache_static_manifest: "priv/static/manifest.json",
+  check_origin: [System.get_env("CHECK_ORIGIN")]

 # Do not print debug messages in production
 config :logger, level: :info
@@ -58,4 +59,7 @@ config :logger, level: :info

 # Finally import the config/prod.secret.exs
 # which should be versioned separately.
-import_config "prod.secret.exs"
+# import_config "prod.secret.exs"
+
+config :app, App.Endpoint,
+  secret_key_base: System.get_env("SECRET_KEY_BASE")

Herokuの場合、設定関係は環境変数で設定するので修正します。

Procfile

PhoenixアプリケーションのルートにProcfileを設置します。

web: mix phoenix.server

webpackを使う場合

フロントエンド周りのビルドがツールが標準だとbrunchになってるので、webpackを使う場合はbuildpackの設定を上書きする必要がありました。
brunchを使う場合はこの設定は必要ありません。

heroku-buildpack-phoenix-staticのphoenix_static_buildpack.configとcompileをPhoenixアプリケーションのルートに設置して

compileを修正します。

diff --git a/compile b/compile
index 61a99e5..2954c16 100644
--- a/compile
+++ b/compile
@@ -1,4 +1,4 @@
-brunch build --production
+webpack

 cd $phoenix_dir
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6