diff --git a/.gitignore b/.gitignore index e3f94db..bb05f1b 100644 --- a/.gitignore +++ b/.gitignore @@ -23,7 +23,7 @@ erl_crash.dump /tmp/ # Ignore package tarball (built via "mix hex.build"). -phoenix_test-*.tar +quip-*.tar # Ignore assets that are produced by build tools. /priv/static/assets/ @@ -35,3 +35,7 @@ phoenix_test-*.tar npm-debug.log /assets/node_modules/ +# Database files +*.db +*.db-* + diff --git a/.tool-versions b/.tool-versions deleted file mode 100644 index 0c26ce6..0000000 --- a/.tool-versions +++ /dev/null @@ -1,3 +0,0 @@ -nodejs 20.17.0 -erlang 27.0.1 -elixir 1.17.2 diff --git a/Dockerfile b/Dockerfile index cc3545d..5a19571 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,7 @@ ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}" FROM ${BUILDER_IMAGE} as builder # install build dependencies -RUN apt-get update -y && apt-get install -y build-essential git curl \ +RUN apt-get update -y && apt-get install -y build-essential git \ && apt-get clean && rm -f /var/lib/apt/lists/*_* # prepare build dir @@ -51,18 +51,6 @@ COPY lib lib COPY assets assets -ENV NVM_DIR=/root/.nvm -ENV NODE_VERSION 20.9.0 - -RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.39.5/install.sh | bash \ - && . $NVM_DIR/nvm.sh \ - && nvm install $NODE_VERSION \ - && nvm alias default $NODE_VERSION \ - && nvm use default -ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}" - -RUN mix cmd npm install --prefix assets - # compile assets RUN mix assets.deploy @@ -97,7 +85,7 @@ RUN chown nobody /app ENV MIX_ENV="prod" # Only copy the final release from the build stage -COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/phoenix_test ./ +COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/quip ./ USER nobody diff --git a/README.md b/README.md index b17d9bb..f691e60 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PhoenixTest +# Quip To start your Phoenix server: diff --git a/assets/tailwind.config.js b/assets/tailwind.config.js index 3a5b4ef..bf02ba7 100644 --- a/assets/tailwind.config.js +++ b/assets/tailwind.config.js @@ -8,8 +8,8 @@ const path = require("path") module.exports = { content: [ "./js/**/*.js", - "../lib/phoenix_test_web.ex", - "../lib/phoenix_test_web/**/*.*ex" + "../lib/quip_web.ex", + "../lib/quip_web/**/*.*ex" ], theme: { extend: { diff --git a/config/config.exs b/config/config.exs index f7610ec..c570008 100644 --- a/config/config.exs +++ b/config/config.exs @@ -7,20 +7,20 @@ # General application configuration import Config -config :phoenix_test, - ecto_repos: [PhoenixTest.Repo], +config :quip, + ecto_repos: [Quip.Repo], generators: [timestamp_type: :utc_datetime] # Configures the endpoint -config :phoenix_test, PhoenixTestWeb.Endpoint, +config :quip, QuipWeb.Endpoint, url: [host: "localhost"], adapter: Bandit.PhoenixAdapter, render_errors: [ - formats: [html: PhoenixTestWeb.ErrorHTML, json: PhoenixTestWeb.ErrorJSON], + formats: [html: QuipWeb.ErrorHTML, json: QuipWeb.ErrorJSON], layout: false ], - pubsub_server: PhoenixTest.PubSub, - live_view: [signing_salt: "bXtM8iJy"] + pubsub_server: Quip.PubSub, + live_view: [signing_salt: "J4MlrElx"] # Configures the mailer # @@ -29,12 +29,12 @@ config :phoenix_test, PhoenixTestWeb.Endpoint, # # For production it's recommended to configure a different adapter # at the `config/runtime.exs`. -config :phoenix_test, PhoenixTest.Mailer, adapter: Swoosh.Adapters.Local +config :quip, Quip.Mailer, adapter: Swoosh.Adapters.Local # Configure esbuild (the version is required) config :esbuild, version: "0.17.11", - phoenix_test: [ + quip: [ args: ~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*), cd: Path.expand("../assets", __DIR__), @@ -44,7 +44,7 @@ config :esbuild, # Configure tailwind (the version is required) config :tailwind, version: "3.4.3", - phoenix_test: [ + quip: [ args: ~w( --config=tailwind.config.js --input=css/app.css diff --git a/config/dev.exs b/config/dev.exs index b325c34..dde2f9f 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -1,14 +1,11 @@ import Config # Configure your database -config :phoenix_test, PhoenixTest.Repo, - username: "postgres", - password: "postgres", - hostname: "localhost", - database: "phoenix_test_dev", +config :quip, Quip.Repo, + database: Path.expand("../quip_dev.db", __DIR__), + pool_size: 5, stacktrace: true, - show_sensitive_data_on_connection_error: true, - pool_size: 10 + show_sensitive_data_on_connection_error: true # For development, we disable any cache and enable # debugging and code reloading. @@ -16,17 +13,17 @@ config :phoenix_test, PhoenixTest.Repo, # The watchers configuration can be used to run external # watchers to your application. For example, we can use it # to bundle .js and .css sources. -config :phoenix_test, PhoenixTestWeb.Endpoint, +config :quip, QuipWeb.Endpoint, # Binding to loopback ipv4 address prevents access from other machines. # Change to `ip: {0, 0, 0, 0}` to allow access from other machines. http: [ip: {127, 0, 0, 1}, port: 4000], check_origin: false, code_reloader: true, debug_errors: true, - secret_key_base: "5AWJTTMb3iv5xM9DExujLeC74qMduXvRv7keyiKc7/kvPOAKCOHInuX0C2hdWHmq", + secret_key_base: "l4+6blY1rcppRaUjqSzQBM2ZZBfVwIobcktDvsq1eYMd+sMjaRhY0uSdI2qDTUlL", watchers: [ - esbuild: {Esbuild, :install_and_run, [:phoenix_test, ~w(--sourcemap=inline --watch)]}, - tailwind: {Tailwind, :install_and_run, [:phoenix_test, ~w(--watch)]} + esbuild: {Esbuild, :install_and_run, [:quip, ~w(--sourcemap=inline --watch)]}, + tailwind: {Tailwind, :install_and_run, [:quip, ~w(--watch)]} ] # ## SSL Support @@ -53,17 +50,17 @@ config :phoenix_test, PhoenixTestWeb.Endpoint, # different ports. # Watch static and templates for browser reloading. -config :phoenix_test, PhoenixTestWeb.Endpoint, +config :quip, QuipWeb.Endpoint, live_reload: [ patterns: [ ~r"priv/static/(?!uploads/).*(js|css|png|jpeg|jpg|gif|svg)$", ~r"priv/gettext/.*(po)$", - ~r"lib/phoenix_test_web/(controllers|live|components)/.*(ex|heex)$" + ~r"lib/quip_web/(controllers|live|components)/.*(ex|heex)$" ] ] # Enable dev routes for dashboard and mailbox -config :phoenix_test, dev_routes: true +config :quip, dev_routes: true # Do not include metadata nor timestamps in development logs config :logger, :console, format: "[$level] $message\n" diff --git a/config/prod.exs b/config/prod.exs index c6b6e64..84422d2 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -5,11 +5,10 @@ import Config # manifest is generated by the `mix assets.deploy` task, # which you should run after static files are built and # before starting your production server. -config :phoenix_test, PhoenixTestWeb.Endpoint, - cache_static_manifest: "priv/static/cache_manifest.json" +config :quip, QuipWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json" # Configures Swoosh API Client -config :swoosh, api_client: Swoosh.ApiClient.Finch, finch_name: PhoenixTest.Finch +config :swoosh, api_client: Swoosh.ApiClient.Finch, finch_name: Quip.Finch # Disable Swoosh Local Memory Storage config :swoosh, local: false diff --git a/config/runtime.exs b/config/runtime.exs index ca419ba..01386e6 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -12,29 +12,25 @@ import Config # If you use `mix release`, you need to explicitly enable the server # by passing the PHX_SERVER=true when you start it: # -# PHX_SERVER=true bin/phoenix_test start +# PHX_SERVER=true bin/quip start # # Alternatively, you can use `mix phx.gen.release` to generate a `bin/server` # script that automatically sets the env var above. if System.get_env("PHX_SERVER") do - config :phoenix_test, PhoenixTestWeb.Endpoint, server: true + config :quip, QuipWeb.Endpoint, server: true end if config_env() == :prod do - database_url = - System.get_env("DATABASE_URL") || + database_path = + System.get_env("DATABASE_PATH") || raise """ - environment variable DATABASE_URL is missing. - For example: ecto://USER:PASS@HOST/DATABASE + environment variable DATABASE_PATH is missing. + For example: /etc/quip/quip.db """ - maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: [] - - config :phoenix_test, PhoenixTest.Repo, - # ssl: true, - url: database_url, - pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"), - socket_options: maybe_ipv6 + config :quip, Quip.Repo, + database: database_path, + pool_size: String.to_integer(System.get_env("POOL_SIZE") || "5") # The secret key base is used to sign/encrypt cookies and other secrets. # A default value is used in config/dev.exs and config/test.exs but you @@ -51,9 +47,9 @@ if config_env() == :prod do host = System.get_env("PHX_HOST") || "example.com" port = String.to_integer(System.get_env("PORT") || "4000") - config :phoenix_test, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY") + config :quip, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY") - config :phoenix_test, PhoenixTestWeb.Endpoint, + config :quip, QuipWeb.Endpoint, url: [host: host, port: 443, scheme: "https"], http: [ # Enable IPv6 and bind on all interfaces. @@ -70,7 +66,7 @@ if config_env() == :prod do # To get SSL working, you will need to add the `https` key # to your endpoint configuration: # - # config :phoenix_test, PhoenixTestWeb.Endpoint, + # config :quip, QuipWeb.Endpoint, # https: [ # ..., # port: 443, @@ -92,7 +88,7 @@ if config_env() == :prod do # We also recommend setting `force_ssl` in your config/prod.exs, # ensuring no data is ever sent via http, always redirecting to https: # - # config :phoenix_test, PhoenixTestWeb.Endpoint, + # config :quip, QuipWeb.Endpoint, # force_ssl: [hsts: true] # # Check `Plug.SSL` for all available options in `force_ssl`. @@ -103,7 +99,7 @@ if config_env() == :prod do # Also, you may need to configure the Swoosh API client of your choice if you # are not using SMTP. Here is an example of the configuration: # - # config :phoenix_test, PhoenixTest.Mailer, + # config :quip, Quip.Mailer, # adapter: Swoosh.Adapters.Mailgun, # api_key: System.get_env("MAILGUN_API_KEY"), # domain: System.get_env("MAILGUN_DOMAIN") diff --git a/config/test.exs b/config/test.exs index d570c38..61d05a3 100644 --- a/config/test.exs +++ b/config/test.exs @@ -5,23 +5,20 @@ import Config # The MIX_TEST_PARTITION environment variable can be used # to provide built-in test partitioning in CI environment. # Run `mix help test` for more information. -config :phoenix_test, PhoenixTest.Repo, - username: "postgres", - password: "postgres", - hostname: "localhost", - database: "phoenix_test_test#{System.get_env("MIX_TEST_PARTITION")}", - pool: Ecto.Adapters.SQL.Sandbox, - pool_size: System.schedulers_online() * 2 +config :quip, Quip.Repo, + database: Path.expand("../quip_test.db", __DIR__), + pool_size: 5, + pool: Ecto.Adapters.SQL.Sandbox # We don't run a server during test. If one is required, # you can enable the server option below. -config :phoenix_test, PhoenixTestWeb.Endpoint, +config :quip, QuipWeb.Endpoint, http: [ip: {127, 0, 0, 1}, port: 4002], - secret_key_base: "A7xacZJjAytqd85J4lTTrhOD2hD3rZE+DjLf4HVaxrOJB7M3ZvVx8v4erjVvJIER", + secret_key_base: "60BPpQ3VaiaNWaJ9XBOpjteaYhP64maXILhzQMGiHqo6LOen7RfQrtBJ09ltCxLY", server: false # In test we don't send emails -config :phoenix_test, PhoenixTest.Mailer, adapter: Swoosh.Adapters.Test +config :quip, Quip.Mailer, adapter: Swoosh.Adapters.Test # Disable swoosh api client as it is only required for production adapters config :swoosh, :api_client, false diff --git a/lib/phoenix_test/application.ex b/lib/phoenix_test/application.ex deleted file mode 100644 index beaa76b..0000000 --- a/lib/phoenix_test/application.ex +++ /dev/null @@ -1,36 +0,0 @@ -defmodule PhoenixTest.Application do - # See https://hexdocs.pm/elixir/Application.html - # for more information on OTP Applications - @moduledoc false - - use Application - - @impl true - def start(_type, _args) do - children = [ - PhoenixTestWeb.Telemetry, - PhoenixTest.Repo, - {DNSCluster, query: Application.get_env(:phoenix_test, :dns_cluster_query) || :ignore}, - {Phoenix.PubSub, name: PhoenixTest.PubSub}, - # Start the Finch HTTP client for sending emails - {Finch, name: PhoenixTest.Finch}, - # Start a worker by calling: PhoenixTest.Worker.start_link(arg) - # {PhoenixTest.Worker, arg}, - # Start to serve requests, typically the last entry - PhoenixTestWeb.Endpoint - ] - - # See https://hexdocs.pm/elixir/Supervisor.html - # for other strategies and supported options - opts = [strategy: :one_for_one, name: PhoenixTest.Supervisor] - Supervisor.start_link(children, opts) - end - - # Tell Phoenix to update the endpoint configuration - # whenever the application is updated. - @impl true - def config_change(changed, _new, removed) do - PhoenixTestWeb.Endpoint.config_change(changed, removed) - :ok - end -end diff --git a/lib/phoenix_test/mailer.ex b/lib/phoenix_test/mailer.ex deleted file mode 100644 index c6744fe..0000000 --- a/lib/phoenix_test/mailer.ex +++ /dev/null @@ -1,3 +0,0 @@ -defmodule PhoenixTest.Mailer do - use Swoosh.Mailer, otp_app: :phoenix_test -end diff --git a/lib/phoenix_test/repo.ex b/lib/phoenix_test/repo.ex deleted file mode 100644 index dbc2c05..0000000 --- a/lib/phoenix_test/repo.ex +++ /dev/null @@ -1,5 +0,0 @@ -defmodule PhoenixTest.Repo do - use Ecto.Repo, - otp_app: :phoenix_test, - adapter: Ecto.Adapters.Postgres -end diff --git a/lib/phoenix_test.ex b/lib/quip.ex similarity index 68% rename from lib/phoenix_test.ex rename to lib/quip.ex index 033975a..9b61d57 100644 --- a/lib/phoenix_test.ex +++ b/lib/quip.ex @@ -1,6 +1,6 @@ -defmodule PhoenixTest do +defmodule Quip do @moduledoc """ - PhoenixTest keeps the contexts that define your domain + Quip keeps the contexts that define your domain and business logic. Contexts are also responsible for managing your data, regardless diff --git a/lib/quip/application.ex b/lib/quip/application.ex new file mode 100644 index 0000000..f4b9918 --- /dev/null +++ b/lib/quip/application.ex @@ -0,0 +1,44 @@ +defmodule Quip.Application do + # See https://hexdocs.pm/elixir/Application.html + # for more information on OTP Applications + @moduledoc false + + use Application + + @impl true + def start(_type, _args) do + children = [ + QuipWeb.Telemetry, + Quip.Repo, + {Ecto.Migrator, + repos: Application.fetch_env!(:quip, :ecto_repos), + skip: skip_migrations?()}, + {DNSCluster, query: Application.get_env(:quip, :dns_cluster_query) || :ignore}, + {Phoenix.PubSub, name: Quip.PubSub}, + # Start the Finch HTTP client for sending emails + {Finch, name: Quip.Finch}, + # Start a worker by calling: Quip.Worker.start_link(arg) + # {Quip.Worker, arg}, + # Start to serve requests, typically the last entry + QuipWeb.Endpoint + ] + + # See https://hexdocs.pm/elixir/Supervisor.html + # for other strategies and supported options + opts = [strategy: :one_for_one, name: Quip.Supervisor] + Supervisor.start_link(children, opts) + end + + # Tell Phoenix to update the endpoint configuration + # whenever the application is updated. + @impl true + def config_change(changed, _new, removed) do + QuipWeb.Endpoint.config_change(changed, removed) + :ok + end + + defp skip_migrations?() do + # By default, sqlite migrations are run when using a release + System.get_env("RELEASE_NAME") != nil + end +end diff --git a/lib/quip/mailer.ex b/lib/quip/mailer.ex new file mode 100644 index 0000000..1753e7a --- /dev/null +++ b/lib/quip/mailer.ex @@ -0,0 +1,3 @@ +defmodule Quip.Mailer do + use Swoosh.Mailer, otp_app: :quip +end diff --git a/lib/phoenix_test/release.ex b/lib/quip/release.ex similarity index 91% rename from lib/phoenix_test/release.ex rename to lib/quip/release.ex index 31fd70c..b2b8310 100644 --- a/lib/phoenix_test/release.ex +++ b/lib/quip/release.ex @@ -1,9 +1,9 @@ -defmodule PhoenixTest.Release do +defmodule Quip.Release do @moduledoc """ Used for executing DB release tasks when run in production without Mix installed. """ - @app :phoenix_test + @app :quip def migrate do load_app() diff --git a/lib/quip/repo.ex b/lib/quip/repo.ex new file mode 100644 index 0000000..19c4c1f --- /dev/null +++ b/lib/quip/repo.ex @@ -0,0 +1,5 @@ +defmodule Quip.Repo do + use Ecto.Repo, + otp_app: :quip, + adapter: Ecto.Adapters.SQLite3 +end diff --git a/lib/phoenix_test_web.ex b/lib/quip_web.ex similarity index 83% rename from lib/phoenix_test_web.ex rename to lib/quip_web.ex index aa21113..3ca948c 100644 --- a/lib/phoenix_test_web.ex +++ b/lib/quip_web.ex @@ -1,12 +1,12 @@ -defmodule PhoenixTestWeb do +defmodule QuipWeb do @moduledoc """ The entrypoint for defining your web interface, such as controllers, components, channels, and so on. This can be used in your application as: - use PhoenixTestWeb, :controller - use PhoenixTestWeb, :html + use QuipWeb, :controller + use QuipWeb, :html The definitions below will be executed for every controller, component, etc, so keep them short and clean, focused @@ -40,10 +40,10 @@ defmodule PhoenixTestWeb do quote do use Phoenix.Controller, formats: [:html, :json], - layouts: [html: PhoenixTestWeb.Layouts] + layouts: [html: QuipWeb.Layouts] import Plug.Conn - import PhoenixTestWeb.Gettext + import QuipWeb.Gettext unquote(verified_routes()) end @@ -52,7 +52,7 @@ defmodule PhoenixTestWeb do def live_view do quote do use Phoenix.LiveView, - layout: {PhoenixTestWeb.Layouts, :app} + layout: {QuipWeb.Layouts, :app} unquote(html_helpers()) end @@ -84,8 +84,8 @@ defmodule PhoenixTestWeb do # HTML escaping functionality import Phoenix.HTML # Core UI components and translation - import PhoenixTestWeb.CoreComponents - import PhoenixTestWeb.Gettext + import QuipWeb.CoreComponents + import QuipWeb.Gettext # Shortcut for generating JS commands alias Phoenix.LiveView.JS @@ -98,9 +98,9 @@ defmodule PhoenixTestWeb do def verified_routes do quote do use Phoenix.VerifiedRoutes, - endpoint: PhoenixTestWeb.Endpoint, - router: PhoenixTestWeb.Router, - statics: PhoenixTestWeb.static_paths() + endpoint: QuipWeb.Endpoint, + router: QuipWeb.Router, + statics: QuipWeb.static_paths() end end diff --git a/lib/phoenix_test_web/components/core_components.ex b/lib/quip_web/components/core_components.ex similarity index 98% rename from lib/phoenix_test_web/components/core_components.ex rename to lib/quip_web/components/core_components.ex index 34965b6..3fb1ae1 100644 --- a/lib/phoenix_test_web/components/core_components.ex +++ b/lib/quip_web/components/core_components.ex @@ -1,4 +1,4 @@ -defmodule PhoenixTestWeb.CoreComponents do +defmodule QuipWeb.CoreComponents do @moduledoc """ Provides core UI components. @@ -17,7 +17,7 @@ defmodule PhoenixTestWeb.CoreComponents do use Phoenix.Component alias Phoenix.LiveView.JS - import PhoenixTestWeb.Gettext + import QuipWeb.Gettext @doc """ Renders a modal. @@ -661,9 +661,9 @@ defmodule PhoenixTestWeb.CoreComponents do # with our gettext backend as first argument. Translations are # available in the errors.po file (as we use the "errors" domain). if count = opts[:count] do - Gettext.dngettext(PhoenixTestWeb.Gettext, "errors", msg, msg, count, opts) + Gettext.dngettext(QuipWeb.Gettext, "errors", msg, msg, count, opts) else - Gettext.dgettext(PhoenixTestWeb.Gettext, "errors", msg, opts) + Gettext.dgettext(QuipWeb.Gettext, "errors", msg, opts) end end diff --git a/lib/phoenix_test_web/components/layouts.ex b/lib/quip_web/components/layouts.ex similarity index 66% rename from lib/phoenix_test_web/components/layouts.ex rename to lib/quip_web/components/layouts.ex index 28b909a..6a89adb 100644 --- a/lib/phoenix_test_web/components/layouts.ex +++ b/lib/quip_web/components/layouts.ex @@ -1,14 +1,14 @@ -defmodule PhoenixTestWeb.Layouts do +defmodule QuipWeb.Layouts do @moduledoc """ This module holds different layouts used by your application. See the `layouts` directory for all templates available. The "root" layout is a skeleton rendered as part of the application router. The "app" layout is set as the default - layout on both `use PhoenixTestWeb, :controller` and - `use PhoenixTestWeb, :live_view`. + layout on both `use QuipWeb, :controller` and + `use QuipWeb, :live_view`. """ - use PhoenixTestWeb, :html + use QuipWeb, :html embed_templates "layouts/*" end diff --git a/lib/phoenix_test_web/components/layouts/app.html.heex b/lib/quip_web/components/layouts/app.html.heex similarity index 100% rename from lib/phoenix_test_web/components/layouts/app.html.heex rename to lib/quip_web/components/layouts/app.html.heex diff --git a/lib/phoenix_test_web/components/layouts/root.html.heex b/lib/quip_web/components/layouts/root.html.heex similarity index 91% rename from lib/phoenix_test_web/components/layouts/root.html.heex rename to lib/quip_web/components/layouts/root.html.heex index 0273992..fb1416f 100644 --- a/lib/phoenix_test_web/components/layouts/root.html.heex +++ b/lib/quip_web/components/layouts/root.html.heex @@ -5,7 +5,7 @@ <.live_title suffix=" ยท Phoenix Framework"> - <%= assigns[:page_title] || "PhoenixTest" %> + <%= assigns[:page_title] || "Quip" %>