Skip to content

Commit

Permalink
ops: production environment
Browse files Browse the repository at this point in the history
  • Loading branch information
joaodiaslobo committed Jan 8, 2025
1 parent b7cf37f commit 41b7924
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 33 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/fly-deploy.yml

This file was deleted.

32 changes: 32 additions & 0 deletions fly-prod.toml
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"
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
2 changes: 0 additions & 2 deletions lib/safira/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 1 addition & 10 deletions lib/safira/constants.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ defmodule Safira.Constants do

alias Safira.Constants.Pair

@cache_service :safira_cache

@doc """
Get a value by key.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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} ->
Expand Down
11 changes: 10 additions & 1 deletion lib/safira_web/live/backoffice/product_live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
1 change: 0 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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"},

Expand Down
1 change: 0 additions & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down

0 comments on commit 41b7924

Please sign in to comment.