From 3b196006c05acc395fbdf295b09c1f75169596b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Thu, 15 May 2025 08:31:26 +0200 Subject: [PATCH] feat: make production ready --- Makefile | 1 + config/config.exs | 4 +- config/dev.exs | 2 - config/prod.exs | 2 +- config/runtime.exs | 15 +-- flake.nix | 104 +++++++++++++----- .../components/layouts/app.html.heex | 26 ----- .../components/layouts/root.html.heex | 2 +- mix.exs | 1 - 9 files changed, 87 insertions(+), 70 deletions(-) diff --git a/Makefile b/Makefile index ef4298d..a5f5494 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,7 @@ authelia-start: ${AUTHELIA_PID} ${AUTHELIA_PID}: ${AUTHELIA_CONFIG} mkdir -p ${AUTHELIA_HOME}/tmp/ cd ${AUTHELIA_HOME} + mkdir -p $(dir ${AUTHELIA_PID}) authelia --config ${AUTHELIA_CONFIG} &> ${AUTHELIA_LOG} & echo $$! > ${AUTHELIA_PID} diff --git a/config/config.exs b/config/config.exs index c4857cf..7097c4f 100644 --- a/config/config.exs +++ b/config/config.exs @@ -51,7 +51,7 @@ config :putzplan, # Configures the endpoint config :putzplan, PutzplanWeb.Endpoint, - url: [host: "localhost"], + url: [host: "127.0.0.1"], adapter: Bandit.PhoenixAdapter, render_errors: [ formats: [html: PutzplanWeb.ErrorHTML, json: PutzplanWeb.ErrorJSON], @@ -99,6 +99,8 @@ config :logger, :console, # Use Jason for JSON parsing in Phoenix config :phoenix, :json_library, Jason +config :exqlite, force_build: true + # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. import_config "#{config_env()}.exs" diff --git a/config/dev.exs b/config/dev.exs index a3ec2e6..157e7a5 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -3,8 +3,6 @@ config :live_debugger, browser_features?: true # Configure your database config :putzplan, Putzplan.Repo, - username: "postgres", - password: "postgres", hostname: "localhost", database: "tmp/putzplan_dev", stacktrace: true, diff --git a/config/prod.exs b/config/prod.exs index cdc42f2..5c9c4fe 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -5,7 +5,7 @@ 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 :putzplan, PutzplanWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json" +config :putzplan, PutzplanWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json", server: true # Configures Swoosh API Client config :swoosh, api_client: Swoosh.ApiClient.Finch, finch_name: Putzplan.Finch diff --git a/config/runtime.exs b/config/runtime.exs index 93a4df4..b3b033d 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -21,20 +21,15 @@ if System.get_env("PHX_SERVER") do end if config_env() == :prod do - database_url = - System.get_env("DATABASE_URL") || + database = + System.get_env("DATABASE") || raise """ - environment variable DATABASE_URL is missing. - For example: ecto://USER:PASS@HOST/DATABASE + environment variable DATABASE is missing. """ - maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: [] - config :putzplan, Putzplan.Repo, - # ssl: true, - url: database_url, - pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"), - socket_options: maybe_ipv6 + database: database, + pool_size: String.to_integer(System.get_env("POOL_SIZE") || "1") # 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 diff --git a/flake.nix b/flake.nix index c91cfb4..6ce8685 100644 --- a/flake.nix +++ b/flake.nix @@ -6,39 +6,87 @@ flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, flake-utils }: - flake-utils.lib.eachDefaultSystem (system: - let + outputs = { + self, + nixpkgs, + flake-utils, + }: + flake-utils.lib.eachDefaultSystem ( + system: let pkgs = nixpkgs.legacyPackages.${system}; - in - { + erl = pkgs.beam.interpreters.erlang_27; + erlangPackages = pkgs.beam.packagesWith erl; + elixir = erlangPackages.elixir; + in { + packages = let + version = "0.1.0"; + src = ./.; + mixFodDeps = erlangPackages.fetchMixDeps { + inherit version src; + pname = "putzplan"; + sha256 = "sha256-H8FFuNayJcFvESWlGYr6H6L5zSzAjqBixBmob5Gnoc4="; + }; + translatedPlatform = + pkgs.lib.getAttr + system + { + aarch64-darwin = "macos-arm64"; + aarch64-linux = "linux-arm64"; + armv7l-linux = "linux-armv7"; + x86_64-darwin = "macos-x64"; + x86_64-linux = "linux-x64"; + }; + in rec { + default = erlangPackages.mixRelease { + inherit version src mixFodDeps; + pname = "putzplan"; + + preInstall = '' + ln -s ${pkgs.tailwindcss}/bin/tailwindcss _build/tailwind-${translatedPlatform} + ln -s ${pkgs.esbuild}/bin/esbuild _build/esbuild-${translatedPlatform} + + ${elixir}/bin/mix assets.deploy + ${elixir}/bin/mix phx.gen.release + ''; + }; + dockerImage = pkgs.dockerTools.buildImage { + name = "putzplan"; + config = { + Entrypoint = "${default}/bin/putzplan"; + Cmd = "start"; + }; + }; + }; devShells.default = pkgs.mkShell { - buildInputs = with pkgs; [ - erlang_25 - beam.packages.erlang_25.elixir_1_18 - lexical - beam.packages.erlang_25.elixir-ls - next-ls + buildInputs = with pkgs; + [ + erl + elixir + lexical + erlangPackages.elixir-ls + next-ls - sqlite - gnumake - authelia - ] - ++ lib.optionals stdenv.isLinux [ - # For ExUnit Notifier on Linux. - libnotify + gnumake + authelia + lazysql - # For file_system on Linux. - inotify-tools - ] - ++ lib.optionals stdenv.isDarwin ([ - # For ExUnit Notifier on macOS. - terminal-notifier + nix-output-monitor + ] + ++ lib.optionals stdenv.isLinux [ + # For ExUnit Notifier on Linux. + libnotify - # For file_system on macOS. - darwin.apple_sdk.frameworks.CoreFoundation - darwin.apple_sdk.frameworks.CoreServices - ]); + # For file_system on Linux. + inotify-tools + ] + ++ lib.optionals stdenv.isDarwin [ + # For ExUnit Notifier on macOS. + terminal-notifier + + # For file_system on macOS. + darwin.apple_sdk.frameworks.CoreFoundation + darwin.apple_sdk.frameworks.CoreServices + ]; shellHook = '' export OIDC_CLIENT_ID="putzplan" diff --git a/lib/putzplan_web/components/layouts/app.html.heex b/lib/putzplan_web/components/layouts/app.html.heex index 3b3b607..c5e8a20 100644 --- a/lib/putzplan_web/components/layouts/app.html.heex +++ b/lib/putzplan_web/components/layouts/app.html.heex @@ -1,29 +1,3 @@ -
-
-
- - - -

- v{Application.spec(:phoenix, :vsn)} -

-
- -
-
<.flash_group flash={@flash} /> diff --git a/lib/putzplan_web/components/layouts/root.html.heex b/lib/putzplan_web/components/layouts/root.html.heex index 1798c32..1c58c4c 100644 --- a/lib/putzplan_web/components/layouts/root.html.heex +++ b/lib/putzplan_web/components/layouts/root.html.heex @@ -9,7 +9,7 @@ - <.live_title default="Putzplan" suffix=" ยท Phoenix Framework"> + <.live_title default="Putzplan"> {assigns[:page_title]} diff --git a/mix.exs b/mix.exs index 5fda815..a9fec15 100644 --- a/mix.exs +++ b/mix.exs @@ -45,7 +45,6 @@ defmodule Putzplan.MixProject do {:phoenix, "~> 1.7.21"}, {:phoenix_ecto, "~> 4.5"}, {:ecto_sql, "~> 3.10"}, - {:postgrex, ">= 0.0.0"}, {:phoenix_html, "~> 4.1"}, {:phoenix_live_reload, "~> 1.2", only: :dev}, {:phoenix_live_view, "~> 1.0"},