From 41b792425af5e73fa0330273ca9b889e413aa073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lobo?= Date: Wed, 8 Jan 2025 22:55:36 +0000 Subject: [PATCH] ops: production environment --- .github/workflows/fly-deploy.yml | 18 ----------- fly-prod.toml | 32 +++++++++++++++++++ lib/safira/application.ex | 2 -- lib/safira/constants.ex | 11 +------ .../live/backoffice/product_live/show.ex | 11 ++++++- mix.exs | 1 - mix.lock | 1 - 7 files changed, 43 insertions(+), 33 deletions(-) delete mode 100644 .github/workflows/fly-deploy.yml create mode 100644 fly-prod.toml diff --git a/.github/workflows/fly-deploy.yml b/.github/workflows/fly-deploy.yml deleted file mode 100644 index b0c246ed..00000000 --- a/.github/workflows/fly-deploy.yml +++ /dev/null @@ -1,18 +0,0 @@ -# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/ - -name: Fly Deploy -on: - push: - branches: - - main -jobs: - deploy: - name: Deploy app - runs-on: ubuntu-latest - concurrency: deploy-group # optional: ensure only one action runs at a time - steps: - - uses: actions/checkout@v4 - - uses: superfly/flyctl-actions/setup-flyctl@master - - run: flyctl deploy --remote-only - env: - FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/fly-prod.toml b/fly-prod.toml new file mode 100644 index 00000000..c70cfad1 --- /dev/null +++ b/fly-prod.toml @@ -0,0 +1,32 @@ +app = "safira-prod" +primary_region = "mad" +kill_signal = "SIGTERM" + +[deploy] + release_command = "/app/bin/migrate" + +[env] + PHX_HOST = "seium.org" + MIX_ENV = "prod" + PORT = "8080" + FROM_EMAIL_NAME = "SEI '25" + FROM_EMAIL_ADDRESS = "no-reply@seium.org" + DNS_CLUSTER_QUERY = "safira-prod.internal" + +[http_service] + internal_port = 8080 + force_https = true + auto_stop_machines = false + auto_start_machines = true + min_machines_running = 0 + processes = ["app"] + + [http_service.concurrency] + type = "connections" + hard_limit = 1000 + soft_limit = 1000 + +[[vm]] + memory = "512mb" + cpu_kind = "shared" + cpus = 1 diff --git a/lib/safira/application.ex b/lib/safira/application.ex index 67dbfc6b..b902c37f 100644 --- a/lib/safira/application.ex +++ b/lib/safira/application.ex @@ -15,8 +15,6 @@ defmodule Safira.Application do {Phoenix.PubSub, name: Safira.PubSub}, # Start the Finch HTTP client for sending emails {Finch, name: Safira.Finch}, - # Start the Cachex cache - {Cachex, name: :safira_cache}, # Start a worker by calling: Safira.Worker.start_link(arg) # {Safira.Worker, arg}, # Start to serve requests, typically the last entry diff --git a/lib/safira/constants.ex b/lib/safira/constants.ex index bbd9f985..9b0149ad 100644 --- a/lib/safira/constants.ex +++ b/lib/safira/constants.ex @@ -7,8 +7,6 @@ defmodule Safira.Constants do alias Safira.Constants.Pair - @cache_service :safira_cache - @doc """ Get a value by key. @@ -21,11 +19,7 @@ defmodule Safira.Constants do {:error, "key not found"} """ def get(key) do - # Try to get the value from the cache - case Cachex.get(@cache_service, key) do - {:ok, nil} -> fetch_key_value(key) - {:ok, value} -> {:ok, value} - end + fetch_key_value(key) end defp fetch_key_value(key) do @@ -34,8 +28,6 @@ defmodule Safira.Constants do {:error, "key not found"} pair -> - # Cache the value - Cachex.put(@cache_service, key, pair.value[key]) {:ok, pair.value[key]} end end @@ -51,7 +43,6 @@ defmodule Safira.Constants do def set(key, value) do case set_key_value(key, value) do {:ok, result} -> - Cachex.put(@cache_service, key, value) {:ok, result} {:error, reason} -> diff --git a/lib/safira_web/live/backoffice/product_live/show.ex b/lib/safira_web/live/backoffice/product_live/show.ex index 1f7be55d..a301560c 100644 --- a/lib/safira_web/live/backoffice/product_live/show.ex +++ b/lib/safira_web/live/backoffice/product_live/show.ex @@ -7,7 +7,11 @@ defmodule SafiraWeb.Backoffice.ProductLive.Show do show: %{"products" => ["show"]}, edit: %{"products" => ["edit"]}} @impl true - def mount(_params, _session, socket) do + def mount(%{"id" => id}, _session, socket) do + if connected?(socket) do + Store.subscribe_to_product_update(id) + end + {:ok, socket} end @@ -20,6 +24,11 @@ defmodule SafiraWeb.Backoffice.ProductLive.Show do |> assign(:product, Store.get_product!(id))} end + @impl true + def handle_info(updated_product, socket) do + {:noreply, assign(socket, product: updated_product)} + end + defp page_title(:show), do: "Show Product" defp page_title(:edit), do: "Edit Product" end diff --git a/mix.exs b/mix.exs index 622d3a1f..9ecc1814 100644 --- a/mix.exs +++ b/mix.exs @@ -62,7 +62,6 @@ defmodule Safira.MixProject do # tools {:qrcode_ex, "~> 0.1.1"}, - {:cachex, "~> 3.6"}, {:credo, "~> 1.6", only: [:dev, :test], runtime: false}, {:faker, "~> 0.18.0"}, diff --git a/mix.lock b/mix.lock index c2d86b63..f48a902e 100644 --- a/mix.lock +++ b/mix.lock @@ -2,7 +2,6 @@ "bandit": {:hex, :bandit, "1.6.2", "a5fa4cfbae9baaf196269a88533e18eef9e7c53bea07b03f6bc2c6d5bf87b1ce", [:mix], [{:hpax, "~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 1.0", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "4563b81ec94f25448ac02a8853453198cf7a63abac6202dbd4bda2c7f1a71eed"}, "bcrypt_elixir": {:hex, :bcrypt_elixir, "3.2.0", "feab711974beba4cb348147170346fe097eea2e840db4e012a145e180ed4ab75", [:make, :mix], [{:comeonin, "~> 5.3", [hex: :comeonin, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "563e92a6c77d667b19c5f4ba17ab6d440a085696bdf4c68b9b0f5b30bc5422b8"}, "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"}, - "cachex": {:hex, :cachex, "3.6.0", "14a1bfbeee060dd9bec25a5b6f4e4691e3670ebda28c8ba2884b12fe30b36bf8", [:mix], [{:eternal, "~> 1.2", [hex: :eternal, repo: "hexpm", optional: false]}, {:jumper, "~> 1.0", [hex: :jumper, repo: "hexpm", optional: false]}, {:sleeplocks, "~> 1.1", [hex: :sleeplocks, repo: "hexpm", optional: false]}, {:unsafe, "~> 1.0", [hex: :unsafe, repo: "hexpm", optional: false]}], "hexpm", "ebf24e373883bc8e0c8d894a63bbe102ae13d918f790121f5cfe6e485cc8e2e2"}, "castore": {:hex, :castore, "1.0.11", "4bbd584741601eb658007339ea730b082cc61f3554cf2e8f39bf693a11b49073", [:mix], [], "hexpm", "e03990b4db988df56262852f20de0f659871c35154691427a5047f4967a16a62"}, "certifi": {:hex, :certifi, "2.12.0", "2d1cca2ec95f59643862af91f001478c9863c2ac9cb6e2f89780bfd8de987329", [:rebar3], [], "hexpm", "ee68d85df22e554040cdb4be100f33873ac6051387baf6a8f6ce82272340ff1c"}, "combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"},