diff --git a/.dockerignore b/.dockerignore index 7c59f61..a03cecf 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,18 @@ -priv/uploads -deps/ \ No newline at end of file +.dockerignore +# there are valid reasons to keep the .git, namely so that you can get the +# current commit hash +#.git +.log +tmp + +# Mix artifacts +_build +deps +*.ez +releases + +# Generate on crash by the VM +erl_crash.dump + +# Static artifacts +node_modules diff --git a/Dockerfile b/Dockerfile index 2b9b569..b76a7c9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -50,13 +50,9 @@ COPY priv priv # step down so that `lib` is available. COPY assets assets -# For Phoenix 1.6 and later, compile assets using esbuild +# compile assets RUN mix assets.deploy -# For Phoenix versions earlier than 1.6, compile assets npm -# RUN cd assets && yarn install && yarn run webpack --mode production -# RUN mix phx.digest - # Compile the release COPY lib lib @@ -86,13 +82,8 @@ WORKDIR "/app" RUN chown nobody /app # Only copy the final release from the build stage -COPY --from=builder --chown=nobody:root /app/_build/prod/rel ./ +COPY --from=builder --chown=nobody:root /app/_build/prod/rel/live_beats ./ USER nobody -# Create a symlink to the application directory by extracting the directory name. This is required -# since the release directory will be named after the application, and we don't know that name. -RUN set -eux; \ - ln -nfs /app/$(basename *)/bin/$(basename *) /app/entry - -CMD /app/entry start \ No newline at end of file +CMD /app/bin/server \ No newline at end of file diff --git a/config/runtime.exs b/config/runtime.exs index c0200f6..5d676a9 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -14,11 +14,13 @@ if config_env() == :prod do For example: ecto://USER:PASS@HOST/DATABASE """ - ipv6? = !!System.get_env("IPV6") + server? = System.get_env("PHX_SERVER") == "true" + host = System.get_env("PHX_HOST") || "example.com" + ecto_ipv6? = System.get_env("ECTO_IPV6") == "true" config :live_beats, LiveBeats.Repo, # ssl: true, - socket_options: if(ipv6?, do: [:inet6], else: []), + socket_options: if(ecto_ipv6?, do: [:inet6], else: []), url: database_url, pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10") @@ -29,7 +31,6 @@ if config_env() == :prod do You can generate one by calling: mix phx.gen.secret """ - host = System.get_env("URL_HOST") || "example.com" config :live_beats, LiveBeatsWeb.Endpoint, url: [host: host, port: 80], @@ -41,9 +42,8 @@ if config_env() == :prod do ip: {0, 0, 0, 0, 0, 0, 0, 0}, port: String.to_integer(System.get_env("PORT") || "4000") ], - check_origin: ["//#{host}"], secret_key_base: secret_key_base, - server: true + server: server? config :live_beats, :files, [ uploads_dir: "/app/uploads", diff --git a/fly.toml b/fly.toml index e24047e..3bed91a 100644 --- a/fly.toml +++ b/fly.toml @@ -5,11 +5,12 @@ kill_timeout = 5 processes = [] [deploy] - release_command = "/app/entry eval LiveBeats.Release.migrate" + release_command = "/app/bin/migrate" [env] - IPV6 = 1 - URL_HOST = "livebeats.fly.dev" + PHX_HOST = "livebeats.fly.dev" + ECTO_IPV6 = "true" + ERL_AFLAGS = "-proto_dist inet6_tcp" [mounts] source="data" diff --git a/mix.exs b/mix.exs index 34c8c71..5224bc9 100644 --- a/mix.exs +++ b/mix.exs @@ -33,7 +33,8 @@ defmodule LiveBeats.MixProject do # Type `mix help deps` for examples and options. defp deps do [ - {:phoenix, "~> 1.6.0"}, + # {:phoenix, "~> 1.6.0"}, + {:phoenix, path: "~/oss/phoenix", override: true}, {:phoenix_ecto, "~> 4.4"}, {:ecto_sql, "~> 3.6"}, {:postgrex, ">= 0.0.0"}, diff --git a/mix.lock b/mix.lock index 592a856..ddbf449 100644 --- a/mix.lock +++ b/mix.lock @@ -10,7 +10,7 @@ "ecto_sql": {:hex, :ecto_sql, "3.7.0", "2fcaad4ab0c8d76a5afbef078162806adbe709c04160aca58400d5cbbe8eeac6", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.4.0 or ~> 0.5.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a26135dfa1d99bf87a928c464cfa25bba6535a4fe761eefa56077a4febc60f70"}, "erlog": {:git, "git://github.com/segun/erlog.git", "76825e0500b6b62b99f28411933dc15a1cb2817f", [ref: "master"]}, "erlp3tags": {:git, "https://github.com/segun/erlp3tags.git", "9b6c72da9057b9e00c7711148ce10e6cdbacae18", []}, - "esbuild": {:hex, :esbuild, "0.2.2", "864b8d1cdab8aa3d08f9811af79b54d89d06dc2ec806b22b3e9bf4535579b0d5", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "0742259fded40073eb8583d38d9265b41c269ce29842e2d26b0de69b38324bf0"}, + "esbuild": {:hex, :esbuild, "0.3.4", "416203c642eb84b207f882cf7953a1fd7bb71e23f5f86554f983bb7bad18b897", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "c472e38b37e9547113776b1e4b64b44ec540bcc7056dd252c2c3ffba41aa9793"}, "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, "floki": {:hex, :floki, "0.31.0", "f05ee8a8e6a3ced4e62beeb2c79a63bc8e12ab98fbaaf6e6a3d9b76b1278e23f", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "b05afa372f5c345a5bf240ac25ea1f0f3d5fcfd7490ac0beeb4a203f9444891e"}, "gettext": {:hex, :gettext, "0.18.2", "7df3ea191bb56c0309c00a783334b288d08a879f53a7014341284635850a6e55", [:mix], [], "hexpm", "f9f537b13d4fdd30f3039d33cb80144c3aa1f8d9698e47d7bcbcc8df93b1f5c5"}, diff --git a/rel/env.sh.eex b/rel/env.sh.eex index 69cea06..382cd83 100644 --- a/rel/env.sh.eex +++ b/rel/env.sh.eex @@ -1,6 +1,18 @@ #!/bin/sh -ip=$(grep fly-local-6pn /etc/hosts | cut -f 1) -export RELEASE_DISTRIBUTION=name -export RELEASE_NODE=$FLY_APP_NAME@$ip -export ELIXIR_ERL_OPTIONS="-proto_dist inet6_tcp" \ No newline at end of file +# Sets and enables heart (recommended only in daemon mode) +# case $RELEASE_COMMAND in +# daemon*) +# HEART_COMMAND="$RELEASE_ROOT/bin/$RELEASE_NAME $RELEASE_COMMAND" +# export HEART_COMMAND +# export ELIXIR_ERL_OPTIONS="-heart" +# ;; +# *) +# ;; +# esac + +# Set the release to work across nodes. If using the long name format like +# the one below (my_app@127.0.0.1), you need to also uncomment the +# RELEASE_DISTRIBUTION variable below. Must be "sname", "name" or "none". +# export RELEASE_DISTRIBUTION=name +# export RELEASE_NODE=<%= @release.name %>@127.0.0.1 diff --git a/rel/overlays/bin/migrate b/rel/overlays/bin/migrate new file mode 100755 index 0000000..6a71841 --- /dev/null +++ b/rel/overlays/bin/migrate @@ -0,0 +1,3 @@ +#!/bin/sh +cd -P -- "$(dirname -- "$0")" +./live_beats eval LiveBeats.Release.migrate \ No newline at end of file diff --git a/rel/overlays/bin/server b/rel/overlays/bin/server new file mode 100755 index 0000000..1400471 --- /dev/null +++ b/rel/overlays/bin/server @@ -0,0 +1,3 @@ +#!/bin/sh +cd -P -- "$(dirname -- "$0")" +PHX_SERVER=true ./live_beats start