Skip to content

Commit

Permalink
ops: production environment (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
joaodiaslobo authored Jan 9, 2025
1 parent b7cf37f commit 9221f06
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 38 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
8 changes: 4 additions & 4 deletions lib/safira_web/components/layouts/landing.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<%= assigns[:page_title] || "SEI '25" %>
</.live_title>
<link phx-track-static rel="stylesheet" href={~p"/assets/app.css"} />
<link rel="apple-touch-icon" sizes="180x180" href="images/icons/apple-touch-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="images/icons/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="images/icons/favicon-16x16.png" />
<link rel="apple-touch-icon" sizes="180x180" href="/images/icons/apple-touch-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/images/icons/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/images/icons/favicon-16x16.png" />
<script defer phx-track-static type="text/javascript" src={~p"/assets/app.js"}>
</script>
<script
Expand All @@ -24,7 +24,7 @@
<.navbar
pages={SafiraWeb.Config.landing_pages()}
registrations_open?={Safira.Event.registrations_open?()}
current_user={@current_user}
current_user={Map.get(assigns, :current_user)}
/>
<main>
<%= @inner_content %>
Expand Down
3 changes: 3 additions & 0 deletions lib/safira_web/components/layouts/root.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<%= assigns[:page_title] || "SEI '25" %>
</.live_title>
<link phx-track-static rel="stylesheet" href={~p"/assets/app.css"} />
<link rel="apple-touch-icon" sizes="180x180" href="/images/icons/apple-touch-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/images/icons/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/images/icons/favicon-16x16.png" />
<script defer phx-track-static type="text/javascript" src={~p"/assets/app.js"}>
</script>
<script
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
4 changes: 4 additions & 0 deletions test/safira_web/live/user_login_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ defmodule SafiraWeb.UserLoginLiveTest do
import Phoenix.LiveViewTest
import Safira.AccountsFixtures

alias Safira.Event

describe "Log in page" do
test "redirects if already logged in", %{conn: conn} do
result =
Expand Down Expand Up @@ -51,6 +53,8 @@ defmodule SafiraWeb.UserLoginLiveTest do

describe "login navigation" do
test "redirects to registration page when the Register button is clicked", %{conn: conn} do
Event.change_registrations_open(true)

{:ok, lv, _html} = live(conn, ~p"/users/log_in")

{:ok, _login_live, login_html} =
Expand Down
4 changes: 3 additions & 1 deletion test/safira_web/live/user_reset_password_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule SafiraWeb.UserResetPasswordLiveTest do
import Phoenix.LiveViewTest
import Safira.AccountsFixtures

alias Safira.Accounts
alias Safira.{Accounts, Event}

setup do
user = user_fixture()
Expand All @@ -14,6 +14,8 @@ defmodule SafiraWeb.UserResetPasswordLiveTest do
Accounts.deliver_user_reset_password_instructions(user, url)
end)

Event.change_registrations_open(true)

%{token: token, user: user}
end

Expand Down

0 comments on commit 9221f06

Please sign in to comment.