An LiveView Example That Just Works?

I know there’s docs and some fairly simple step by step deployment instructions, for deploying with LiveView. I have a phoenix app that works locally, with a postgres db. I can get about halfway through fly launch (the DB works, is built etc), but in the end fail due to:

Recent Logs
***v18 failed - Failed due to unhealthy allocations - no stable job version to auto revert to and deploying as v19

I tried to make a new app using the step by step instructions for LiveView, and that failed:

 ERROR! Config provider Config.Reader failed with:
 For example: ecto://USER:PASS@HOST/DATABASE
     (stdlib 4.0.1) erl_eval.erl:744: :erl_eval.do_apply/7
     (stdlib 4.0.1) erl_eval.erl:136: :erl_eval.exprs/6
     (elixir 1.13.4) src/elixir.erl:296: :elixir.recur_eval/3
     (elixir 1.13.4) lib/config.ex:260: Config.__eval__!/3
 {"init terminating in do_boot",{#{'__exception__'=>true,'__struct__'=>'Elixir.RuntimeError',message=><<101,110,118,105,114,111,110,109,101,110,116,32,118,97,114,105,97,98,108,101,32,68,65,84,65,66,65,83,69,95,85,82,76,32,105,115,32,109,105,115,115,105,110,103,46,10,70,111,114,32,101,120,97,109,112,108,101,58,32,101,99,116,111,58,47,47,85,83,69,82,58,80,65,83,83,64,72,79,83,84,47,68,65,84,65,66,65,83,69,10>>},[{erl_eval,do_apply,7,[{file,"erl_eval.erl"},{line,744},{error_info,#{module=>'Elixir.Exception'}}]},{erl_eval,expr,6,[{file,"erl_eval.erl"},{line,492}]},{erl_eval,exprs,6,[{file,"erl_eval.erl"},{line,136}]},{elixir,recur_eval,3,[{file,"src/elixir.erl"},{line,296}]},{elixir,eval_forms,3,[{file,"src/elixir.erl"},{line,274}]},{'Elixir.Code',validated_eval_string,3,[{file,"lib/code.ex"},{line,404}]},{'Elixir.Config','__eval__!',3,[{file,"lib/config.ex"},{line,260}]},{'Elixir.Config.Reader','read!',2,[{file,"lib/config/reader.ex"},{line,92}]}]}}
 init terminating in do_boot ({,[{erl_eval,do_apply,7,[{_},{_},{_}]},{erl_eval,expr,6,[{_},{_}]},{erl_eval,exprs,6,[{_},{_}]},{elixir,recur_eval,3,[{_},{_}]},{elixir,eval_forms,3,[{_},{_}]},{Elixir.Code,validated_eval_string,3,[{_},{_}]},{Elixir.Config,__eval__!,3,[{_},{_}]},{Elixir.Config.Reader,read!,2,[{_},{_}]}]})
 Crash dump is being written to: erl_crash.dump...done
 Starting clean up.

Error Release command failed, deployment aborted

The question is simple - is there some repo, or some example, where a very basic case of getting a launch to work with a handful of commands, exists and is tested? I’ve spent a few days trying to deploy, and REALLY want to support Fly.io, but I’ll have to go back to office Monday and basically punt and deploy my app on AWS, which sucks, but the handful of "you need to modify the runtime.exs to support ipv6 and you need to change the TOML fly generated to internal_port whatever, it all seems very idiosyncratic. Would love if someone had a repo I could pull, that ALWAYS is deployable, so I can see what those config files looke like?

Hey,

Their example should work so that’s strange … You mention the step-by-step instructions: do you have a link for which guide you followed (that they can then check and debug)?

I know of this repo which is a sample app built by Fly using LiveView. You may be able to compare that to see what differs?

There are some LiveView experts here so if that’s not sufficient, hopefully one will get back to you soon with assistance.

Thx. Example helpful. They dont have the expose line in Dockerfile. They use 80 for prod.exs, and they have the ipv6 for postgres add. Ill sync mine to that and see what happens.

I would say somewhere theres a log that has the needful but dont know where. :frowning:

Sorry they have internal port 4000 in toml and 80 in prod.exs

I

Oh well.

Instance
ID = 54645317
Process = app
Version = 21
Region = iad
Desired = run
Status = running
Health Checks = 1 total, 1 critical
Restarts = 0
Created = 4m50s ago

Recent Events
TIMESTAMP TYPE MESSAGE
2022-09-25T21:30:24Z Received Task received by client
2022-09-25T21:30:24Z Task Setup Building Task Directory
2022-09-25T21:30:29Z Started Task started by client

Recent Logs
2022-09-25T21:30:26.000 [info] Configuring virtual machine
2022-09-25T21:30:26.000 [info] Pulling container image
2022-09-25T21:30:27.000 [info] Unpacking image
2022-09-25T21:30:29.000 [info] Preparing kernel init
2022-09-25T21:30:29.000 [info] Configuring firecracker
2022-09-25T21:30:29.000 [info] Starting virtual machine
2022-09-25T21:30:29.000 [info] Starting init (commit: 249766e)…
2022-09-25T21:30:29.000 [info] Preparing to run: /app/bin/server as nobody
2022-09-25T21:30:29.000 [info] 2022/09/25 21:30:29 listening on [fdaa:0:89e4:a7b:8aeb:5464:5317:2]:22 (DNS: [fdaa::3]:53)
***v21 failed - Failed due to unhealthy allocations - no stable job version to auto revert to and deploying as v22

Troubleshooting guide at Troubleshooting your Deployment · Fly Docs
Error abort

22 attempts, calling it a day thx anyways!

Yah, I feel your pain and I’m already running my elixir app here. I wanted to create an app to test litefs and using the documentation I could not do it. Had to use my existing app to get it working. Not sure if it will help, but here’s what I used for https://litefs-liveview.fly.dev using phoenix 1.6.11. You’ll need to take out the mounts line in fly.toml though I think.

fly.toml


app = "litefs-liveview"
kill_signal = "SIGTERM"
kill_timeout = 5
processes = []

# [deploy]
#   release_command = "/app/bin/migrate"

[mounts]
source="litefs"
destination="/mnt/litefs"

[env]
  PHX_HOST = "litefs-liveview.fly.dev"
  PORT = "8080"

[experimental]
  allowed_public_ports = []
  auto_rollback = true
  enable_consul=true

[[services]]
  http_checks = []
  internal_port = 8080
  processes = ["app"]
  protocol = "tcp"
  script_checks = []
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

Dockerfile

ARG ELIXIR_VERSION=1.13.4
ARG OTP_VERSION=25.0.4
ARG DEBIAN_VERSION=bullseye-20220801-slim

ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"

FROM flyio/litefs as litefs
FROM ${BUILDER_IMAGE} as builder

# install build dependencies
RUN apt-get update -y && apt-get install -y build-essential git \
    && apt-get clean && rm -f /var/lib/apt/lists/*_*

# prepare build dir
WORKDIR /app

# install hex + rebar
RUN mix local.hex --force && \
    mix local.rebar --force

# set build ENV
ENV MIX_ENV="prod"

# install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV
RUN mkdir config

# copy compile-time config files before we compile dependencies
# to ensure any relevant config change will trigger the dependencies
# to be re-compiled.
COPY config/config.exs config/${MIX_ENV}.exs config/
RUN mix deps.compile

COPY priv priv

COPY lib lib

COPY assets assets

# compile assets
RUN mix assets.deploy

# Compile the release
RUN mix compile

# Changes to config/runtime.exs don't require recompiling the code
COPY config/runtime.exs config/

COPY rel rel
RUN mix release

# start a new build stage so that the final image will only contain
# the compiled release and other runtime necessities
FROM ${RUNNER_IMAGE}

RUN apt-get update -y && apt-get install -y libstdc++6 openssl libncurses5 locales busybox fuse ca-certificates sqlite3 lsof \
  && apt-get clean && rm -f /var/lib/apt/lists/*_*

# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV ECTO_IPV6 true
ENV ERL_AFLAGS "-proto_dist inet6_tcp"
ENV LITEFS_DB_DIR "/mnt/litefs/db"
ENV LITEFS_PORT 20202

WORKDIR "/app"
RUN chown nobody /app

# set runner ENV
ENV MIX_ENV="prod"

# Only copy the final release from the build stage
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/litefs_liveview ./
#COPY --from=litefs /usr/local/bin/litefs /usr/local/bin/litefs
#COPY --chmod=0755 litefs.bin /usr/local/bin/litefs
COPY --chmod=0755 litefs_gh /usr/local/bin/litefs
COPY config/litefs.yml /litefs.yml
COPY --chmod=0755 entrypoint.sh /entrypoint.sh
RUN mkdir -p /mnt/litefs/db
RUN chown -R nobody /mnt/litefs

#USER nobody
ENTRYPOINT ["/entrypoint.sh"]
CMD ["/app/bin/server"]

entrypoint.sh:

#!/usr/bin/env bash
set -euo pipefail
mkdir -p /mnt/litefs/db
/usr/local/bin/litefs -config /litefs.yml &
sleep 10

exec "$@"
$ fly secrets list
Update available 0.0.389 -> v0.0.396.
Run "flyctl version update" to upgrade.
NAME            DIGEST                                  CREATED AT           
SECRET_KEY_BASE 6c6d84a082194b934c7d8cf1e0307ec8        2022-08-24T22:14:59Z

config/runtime.exs

import Config

if config_env() == :prod do

  config :litefs_liveview, LitefsLiveview.Repo.Local,
    database: "/mnt/litefs/db/testdb.sqlite",
    journal_mode: :delete,
    pool_size: String.to_integer(System.get_env("POOL_SIZE") || "5"),
    stacktrace: true,
    show_sensitive_data_on_connection_error: true

  secret_key_base =
    System.get_env("SECRET_KEY_BASE") ||
      raise """
      environment variable SECRET_KEY_BASE is missing.
      You can generate one by calling: mix phx.gen.secret
      """

  port = String.to_integer(System.get_env("PORT") || "4000")

  config :litefs_liveview, LitefsLiveviewWeb.Endpoint,
    server: true,
    http: [ip: {0, 0, 0, 0, 0, 0, 0, 0}, port: System.get_env("PORT") || 4000, compress: true],
    url: [host: "localhost", port: System.get_env("PORT") || 4000],
    check_origin: ["//*.fly.dev", "//localhost"],
    cache_static_manifest: "priv/static/cache_manifest.json",
    root: ".",
    secret_key_base: secret_key_base

  config :fly,
    region: System.get_env("FLY_REGION")

  app_name =
    System.get_env("FLY_APP_NAME") ||
      raise "FLY_APP_NAME not available"

  config :libcluster,
      topologies: [
        fly6pn: [
          strategy: Cluster.Strategy.DNSPoll,
          config: [
            polling_interval: 5_000,
            node_basename: app_name
          ]
        ]
      ]
end


1 Like

Thanks, appreciate that. I had to AWS, I’ll come back in a couple months, with a different app we’re building with LiveView, and see if something’s changed.

Hi @tj1 would that repo happen to be open source?

Just to follow up - I got the base example working. So I’ll port my app to that new deploy, see which piece ends up breaking it. Thanks for help, all.

1 Like

Should anyone need help with this issue going forward, I cannot open source this repo, but I can help if you DM me and want to see the configs etc.

1 Like

I was planning to opensource it, but ironically, I haven’t even committed it to source control yet. :slight_smile:

When you do feel free to @ me please :slight_smile:

Taking the message from here:

message=>

Copy/pasting into IEX I get:

iex(3)> <<101,110,118,105,114,111,110,109,101,110,116,32,118,97,114,105,97,98,108,101,32,68,65,84,65,66,65,83,69,95,85,82,76,32,105,115,32,109,105,115,115,105,110,103,46,10,70,111,114,32,101,120,97,109,112,108,101,58,32,101,99,116,111,58,47,47,85,83,69,82,58,80,65,83,83,64,72,79,83,84,47,68,65,84,65,66,65,83,69,10>>          
"environment variable DATABASE_URL is missing.\nFor example: ecto://USER:PASS@HOST/DATABASE\n"

Looks like you have to set DATABASE_URL. Not sure if fly launch is supposed to do this for you. Maybe if you created your database outside of the tutorial flow then it skips this.

For others using sqlite with LiveView on fly.io, check this gist:

It has some useful tips including setting a different environment variable, DATABASE_PATH