Skip to content

Commit

Permalink
Halt server if migrations fail on boot (#457)
Browse files Browse the repository at this point in the history
  • Loading branch information
remi authored Dec 7, 2023
1 parent a3c3f6a commit fa04edd
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

WORKDIR "/opt/elixir_boilerplate"
RUN chown nobody /opt/elixir_boilerplate
WORKDIR "/app"
RUN chown nobody /app

# Only copy the final release from the build stage
COPY --from=otp-builder --chown=nobody:root /app/_build/prod/rel/elixir_boilerplate ./

USER nobody

CMD ["/opt/elixir_boilerplate/bin/server"]
CMD ["sh", "-c", "/app/bin/migrate && /app/bin/server"]
3 changes: 1 addition & 2 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import Config

config :elixir_boilerplate, ElixirBoilerplateWeb.Endpoint,
cache_static_manifest: "priv/static/cache_manifest.json",
debug_errors: false,
server: true
debug_errors: false

config :logger, :console,
format: "$time $metadata[$level] $message\n",
Expand Down
6 changes: 6 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ config :elixir_boilerplate, ElixirBoilerplate.Repo,
pool_size: get_env!("DATABASE_POOL_SIZE", :integer),
socket_options: if(get_env("DATABASE_IPV6", :boolean), do: [:inet6], else: [])

# NOTE: Only set `server` to `true` if `PHX_SERVER` is present. We cannot set
# it to `false` otherwise because `mix phx.server` will stop working without it.
if get_env("PHX_SERVER", :boolean) == true do
config :elixir_boilerplate, ElixirBoilerplateWeb.Endpoint, server: true
end

config :elixir_boilerplate, ElixirBoilerplateWeb.Endpoint,
http: [port: get_env!("PORT", :integer)],
secret_key_base: get_env!("SECRET_KEY_BASE"),
Expand Down
1 change: 0 additions & 1 deletion rel/overlays/bin/migrate
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/sh
cd -P -- "$(dirname -- "$0")"

exec ./elixir_boilerplate eval ElixirBoilerplate.Release.migrate
6 changes: 1 addition & 5 deletions rel/overlays/bin/server
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#!/bin/sh
cd -P -- "$(dirname -- "$0")"

# Always run migrations
./elixir_boilerplate eval ElixirBoilerplate.Release.migrate

exec ./elixir_boilerplate start
PHX_SERVER=true exec ./elixir_boilerplate start

0 comments on commit fa04edd

Please sign in to comment.