2019-04-04 / @syui

pleroma , heroku

pleromaをherokuで立てる

pleroma on heroku.

herokuでpleromaを動かします。動いた環境を記録します。

heroku info

remote:        * Stack heroku-18
remote:        * Erlang 21.2
remote:        * Elixir 1.7

src : https://git.pleroma.social/pleroma/pleroma , fd7dd8f9a2f052531bb17fe51d3678787bd8b4c8

buildpack : https://github.com/syui/heroku-buildpack-elixir

こちらのHashNuke/heroku-buildpack-elixir${build_path}からmixを実行できないので、それを修正したもの。

$ git push heroku master
remote: -----> Fetching app dependencies with mix
remote: fatal: not a git repository (or any parent up to mount point /)
remote: Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
$ heroku buildpacks:set https://github.com/syui/heroku-buildpack-elixir.git -a $APP_NAME

Procfile

web: mix phx.server

elixir_buildpack.config

erlang_version=21.2
elixir_version=1.7
always_rebuild=false
runtime_path=/app
hook_pre_fetch_dependencies="pwd"
#hook_pre_compile="pwd"
#hook_post_compile="pwd"

Pleroma Install Wiki

example

$ git clone https://git.pleroma.social/pleroma/pleroma
$ cd !$:t
$ git checkout -b master

$ heroku create $APP_NAME
$ heroku git:remote -a $APP_NAME
$ heroku buildpacks:set https://github.com/syui/heroku-buildpack-elixir.git -a $APP_NAME

$ heroku addons:create heroku-postgresql:hobby-dev -a $APP_NAME
$ heroku config -a $APP_NAME

$ mix --version
Erlang/OTP 21 [erts-10.3.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe] [dtrace]
Mix 1.8.1 (compiled with Erlang/OTP 21)

$ mix deps.get

# これによって必要な値がconfig(config/generated_config.exs)に書き込まれる
$ mix pleroma.instance gen
$ mv config/{generated_config.exs,prod.secret.exs}

# heroku pgslでは、権限がないので、setup_db.psqlの内容は書き込めない
# cat config/setup_db.psql | pbcopy
# heroku pg:psql -a $APP_NAME
# 貼り付け

$ heroku pg:reset -a $APP_NAME 

$ mix phx.gen.secret
# configのsecret_key_baseに入れる, herokuのSECRET_KEY_BASEを使ってもいい
$ heroku config:set SECRET_KEY_BASE="XXX" -a $APP_NAME

$ mix ecto.migrate

# heroku用に$PORTを追加
$ vim config/prod.secret.exs
config :pleroma, Pleroma.Web.Endpoint,
 http: [port: {:system, "PORT"}],
   url: [host: "APP_NAME.herokuapp.com", scheme: "https", port: 443],
   secret_key_base: "",
   signing_salt: "o+Aj/ehx"

# あと、System.get_env("DATABASE_URL")などを使ったほうが安全

$ vim Procfile
web: mix phx.server

$ vim elixir_buildpack.config
erlang_version=21.2
elixir_version=1.7
always_rebuild=false
runtime_path=/app
hook_pre_fetch_dependencies="pwd"
#hook_pre_compile="pwd"
#hook_post_compile="pwd"

$ cat .gitignore
$ cat ~/.gitignore

$ git add .
$ git commit -m "first"
$ git push heroku master

$ heroku logs -a $APP_NAME
$ heroku run bash -a $APP_NAME
$ ls -a
$ ./.platform_tools/elixir/bin/mix phx.server

# ユーザーの作成
$ heroku run "mix pleroma.user invite" -a $APP_NAME
# 権限の付与
$ heroku run "mix pleroma.user set $USER --admin" -a $APP_NAME

説明

pleromaは、elixir+phoenixで書かれた分散snsです。最新のcommitでは、buildpackがうまく動作しませんので、対応しました。

srcやbuildpackを合わせても、今後、herokuやaddonの仕様変更によって動かなくなる可能性はあります。

動いた日付 : 2019/04/01