From 6a25f72a75f90b29f0a82dd8fcb1bdca25996de7 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 29 Jul 2020 13:02:48 +0200 Subject: [PATCH 01/22] FrontendStatic: Work correctly for other frontend types. --- lib/pleroma/plugs/frontend_static.ex | 1 + test/plugs/frontend_static_test.exs | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/pleroma/plugs/frontend_static.ex b/lib/pleroma/plugs/frontend_static.ex index f549ca75f..11a0d5382 100644 --- a/lib/pleroma/plugs/frontend_static.ex +++ b/lib/pleroma/plugs/frontend_static.ex @@ -30,6 +30,7 @@ defmodule Pleroma.Plugs.FrontendStatic do opts |> Keyword.put(:from, "__unconfigured_frontend_static_plug") |> Plug.Static.init() + |> Map.put(:frontend_type, opts[:frontend_type]) end def call(conn, opts) do diff --git a/test/plugs/frontend_static_test.exs b/test/plugs/frontend_static_test.exs index d11d91d78..6f4923048 100644 --- a/test/plugs/frontend_static_test.exs +++ b/test/plugs/frontend_static_test.exs @@ -3,6 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.FrontendStaticPlugTest do + alias Pleroma.Plugs.FrontendStatic use Pleroma.Web.ConnCase @dir "test/tmp/instance_static" @@ -14,6 +15,18 @@ defmodule Pleroma.Web.FrontendStaticPlugTest do setup do: clear_config([:instance, :static_dir], @dir) + test "init will give a static plug config + the frontend type" do + opts = + [ + at: "/admin", + frontend_type: :admin + ] + |> FrontendStatic.init() + + assert opts[:at] == ["admin"] + assert opts[:frontend_type] == :admin + end + test "overrides existing static files", %{conn: conn} do name = "pelmora" ref = "uguu" @@ -27,4 +40,18 @@ defmodule Pleroma.Web.FrontendStaticPlugTest do index = get(conn, "/") assert html_response(index, 200) == "from frontend plug" end + + test "overrides existing static files for the `pleroma/admin` path", %{conn: conn} do + name = "pelmora" + ref = "uguu" + + clear_config([:frontends, :admin], %{"name" => name, "ref" => ref}) + path = "#{@dir}/frontends/#{name}/#{ref}" + + File.mkdir_p!(path) + File.write!("#{path}/index.html", "from frontend plug") + + index = get(conn, "/pleroma/admin/") + assert html_response(index, 200) == "from frontend plug" + end end From 66974e17a06bc26d7ea0be26bdd77f82b80afdaa Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 29 Jul 2020 13:03:04 +0200 Subject: [PATCH 02/22] Endpoint: Serve a dynamically configured admin interface --- lib/pleroma/web/endpoint.ex | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex index 527fb288d..8b153763d 100644 --- a/lib/pleroma/web/endpoint.ex +++ b/lib/pleroma/web/endpoint.ex @@ -39,6 +39,18 @@ defmodule Pleroma.Web.Endpoint do } ) + plug(Plug.Static.IndexHtml, at: "/pleroma/admin/") + + plug(Pleroma.Plugs.FrontendStatic, + at: "/pleroma/admin", + frontend_type: :admin, + gzip: true, + cache_control_for_etags: @static_cache_control, + headers: %{ + "cache-control" => @static_cache_control + } + ) + # Serve at "/" the static files from "priv/static" directory. # # You should set gzip to true if you are running phoenix.digest @@ -56,8 +68,6 @@ defmodule Pleroma.Web.Endpoint do } ) - plug(Plug.Static.IndexHtml, at: "/pleroma/admin/") - plug(Plug.Static, at: "/pleroma/admin/", from: {:pleroma, "priv/static/adminfe/"} From e2f82968e87de20502ed46ad0f0392ae04f89819 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 29 Jul 2020 13:04:29 +0200 Subject: [PATCH 03/22] Config: Update frontend config example --- config/config.exs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/config.exs b/config/config.exs index 48fe7c669..d9c7969bc 100644 --- a/config/config.exs +++ b/config/config.exs @@ -653,7 +653,9 @@ config :pleroma, :static_fe, enabled: false # With no frontend configuration, the bundled files from the `static` directory will # be used. # -# config :pleroma, :frontends, primary: %{"name" => "pleroma", "ref" => "develop"} +# config :pleroma, :frontends, +# primary: %{"name" => "pleroma", "ref" => "develop"}, +# admin: %{"name" => "admin", "ref" => "stable"} config :pleroma, :web_cache_ttl, activity_pub: nil, From 54afb35685d5fca6056cc3c7f40c946aa02dc9a7 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 29 Jul 2020 13:06:51 +0200 Subject: [PATCH 04/22] Cheatsheet: Update frontends information. --- docs/configuration/cheatsheet.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/configuration/cheatsheet.md b/docs/configuration/cheatsheet.md index 2a25a024a..58bf787c8 100644 --- a/docs/configuration/cheatsheet.md +++ b/docs/configuration/cheatsheet.md @@ -1051,11 +1051,11 @@ Control favicons for instances. Frontends in Pleroma are swappable - you can specify which one to use here. -For now, you can set a frontend with the key `primary` and the options of `name` and `ref`. This will then make Pleroma serve the frontend from a folder constructed by concatenating the instance static path, `frontends` and the name and ref. +You can set a frontends for the key `primary` and `admin` and the options of `name` and `ref`. This will then make Pleroma serve the frontend from a folder constructed by concatenating the instance static path, `frontends` and the name and ref. -The key `primary` refers to the frontend that will be served by default for general requests. In the future, other frontends like the admin frontend will also be configurable here. +The key `primary` refers to the frontend that will be served by default for general requests. The key `admin` refers to the frontend that will be served at the `/pleroma/admin` path. -If you don't set anything here, the bundled frontend will be used. +If you don't set anything here, the bundled frontends will be used. Example: @@ -1064,6 +1064,10 @@ config :pleroma, :frontends, primary: %{ "name" => "pleroma", "ref" => "stable" + }, + admin: %{ + "name" => "admin", + "ref" => "develop" } ``` From f715bf1915b75cb3c5b24d4661a94885aaa1a0ac Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 29 Jul 2020 13:09:42 +0200 Subject: [PATCH 05/22] Changelog: Include frontend information. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95f318584..a4881cc82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added +- Frontends: Add configurable frontends for primary and admin fe. - Chats: Added `accepts_chat_messages` field to user, exposed in APIs and federation. - Chats: Added support for federated chats. For details, see the docs. - ActivityPub: Added support for existing AP ids for instances migrated from Mastodon. From d249f91b3f36e320d135d2f57964f49f55ea61a3 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 29 Jul 2020 16:27:11 +0200 Subject: [PATCH 06/22] Descriptions: Update with admin frontend info --- config/description.exs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/config/description.exs b/config/description.exs index 30a503696..b96fe9705 100644 --- a/config/description.exs +++ b/config/description.exs @@ -3517,6 +3517,23 @@ config :pleroma, :config_description, [ description: "reference of the installed primary frontend to be used" } ] + }, + %{ + key: :admin, + type: :map, + description: "Admin frontend", + children: [ + %{ + key: "name", + type: :string, + description: "Name of the installed Admin frontend" + }, + %{ + key: "ref", + type: :string, + description: "reference of the installed Admin frontend to be used" + } + ] } ] } From 2e20ceee523084a11c07c5a3a99fa2de3be15e7a Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 30 Jul 2020 14:12:41 +0200 Subject: [PATCH 07/22] Mix tasks: Add frontend task to download and install frontends. Co-authored-by: Roman Chvanikov --- lib/mix/tasks/pleroma/frontend.ex | 121 ++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 lib/mix/tasks/pleroma/frontend.ex diff --git a/lib/mix/tasks/pleroma/frontend.ex b/lib/mix/tasks/pleroma/frontend.ex new file mode 100644 index 000000000..bd65e9e36 --- /dev/null +++ b/lib/mix/tasks/pleroma/frontend.ex @@ -0,0 +1,121 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Mix.Tasks.Pleroma.Frontend do + use Mix.Task + + import Mix.Pleroma + + @shortdoc "Manages bundled Pleroma frontends" + + # @moduledoc File.read!("docs/administration/CLI_tasks/frontend.md") + + def run(["install", "none" | _args]) do + shell_info("Skipping frontend installation because none was requested") + "none" + end + + def run(["install", frontend | args]) do + log_level = Logger.level() + Logger.configure(level: :warn) + start_pleroma() + + {options, [], []} = + OptionParser.parse( + args, + strict: [ + ref: :string, + static_dir: :string, + build_url: :string + ] + ) + + instance_static_dir = + with nil <- options[:static_dir] do + Pleroma.Config.get!([:instance, :static_dir]) + end + + cmd_frontend_info = %{ + "name" => frontend, + "ref" => options[:ref], + "build_url" => options[:build_url] + } + + config_frontend_info = Pleroma.Config.get([:frontends, :available, frontend], %{}) + + frontend_info = + Map.merge(config_frontend_info, cmd_frontend_info, fn _key, config, cmd -> + # This only overrides things that are actually set + cmd || config + end) + + ref = frontend_info["ref"] + + unless ref do + raise "No ref given or configured" + end + + dest = + Path.join([ + instance_static_dir, + "frontends", + frontend, + ref + ]) + + fe_label = "#{frontend} (#{ref})" + + shell_info("Downloading pre-built bundle for #{fe_label}") + tmp_dir = Path.join(dest, "tmp") + + with {_, :ok} <- {:download, download_build(frontend_info, tmp_dir)}, + shell_info("Installing #{fe_label} to #{dest}"), + :ok <- install_frontend(frontend_info, tmp_dir, dest) do + File.rm_rf!(tmp_dir) + shell_info("Frontend #{fe_label} installed to #{dest}") + + Logger.configure(level: log_level) + else + {:download, _} -> + shell_info("Could not download the frontend") + + _e -> + shell_info("Could not install the frontend") + end + end + + defp download_build(frontend_info, dest) do + url = String.replace(frontend_info["build_url"], "${ref}", frontend_info["ref"]) + + with {:ok, %{status: 200, body: zip_body}} <- + Pleroma.HTTP.get(url, [], timeout: 120_000, recv_timeout: 120_000), + {:ok, unzipped} <- :zip.unzip(zip_body, [:memory]) do + File.rm_rf!(dest) + File.mkdir_p!(dest) + + Enum.each(unzipped, fn {filename, data} -> + path = filename + + new_file_path = Path.join(dest, path) + + new_file_path + |> Path.dirname() + |> File.mkdir_p!() + + File.write!(new_file_path, data) + end) + + :ok + else + e -> {:error, e} + end + end + + defp install_frontend(frontend_info, source, dest) do + from = frontend_info["build_dir"] || "dist" + File.mkdir_p!(dest) + File.cp_r!(Path.join([source, from]), dest) + :ok + end +end From 4ce4d799fd9fa5ab4fde6c6aa55bf8b516d64c12 Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 30 Jul 2020 14:14:58 +0200 Subject: [PATCH 08/22] Config: Add frontend information. --- config/config.exs | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/config/config.exs b/config/config.exs index 0c9685c4c..bf24d1bd9 100644 --- a/config/config.exs +++ b/config/config.exs @@ -657,7 +657,41 @@ config :pleroma, :static_fe, enabled: false # # config :pleroma, :frontends, # primary: %{"name" => "pleroma", "ref" => "develop"}, -# admin: %{"name" => "admin", "ref" => "stable"} +# admin: %{"name" => "admin", "ref" => "stable"}, +# available: %{...} + +config :pleroma, :frontends, + available: %{ + "pleroma" => %{ + "name" => "pleroma", + "git" => "https://git.pleroma.social/pleroma/pleroma-fe", + "build_url" => + "https://git.pleroma.social/pleroma/pleroma-fe/-/jobs/artifacts/${ref}/download?job=build", + "ref" => "develop" + }, + "fedi-fe" => %{ + "name" => "fedi-fe", + "git" => "https://git.pleroma.social/pleroma/fedi-fe", + "build_url" => + "https://git.pleroma.social/pleroma/fedi-fe/-/jobs/artifacts/${ref}/download?job=build", + "ref" => "master" + }, + "admin-fe" => %{ + "name" => "admin-fe", + "git" => "https://git.pleroma.social/pleroma/admin-fe", + "build_url" => + "https://git.pleroma.social/pleroma/admin-fe/-/jobs/artifacts/${ref}/download?job=build", + "ref" => "develop" + }, + "soapbox-fe" => %{ + "name" => "soapbox-fe", + "git" => "https://gitlab.com/soapbox-pub/soapbox-fe", + "build_url" => + "https://gitlab.com/soapbox-pub/soapbox-fe/-/jobs/artifacts/${ref}/download?job=build-production", + "ref" => "v1.0.0", + "build_dir" => "static" + } + } config :pleroma, :web_cache_ttl, activity_pub: nil, From 99bfdffb1dfa283d1d039c8d46b7da095876197d Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 30 Jul 2020 14:17:58 +0200 Subject: [PATCH 09/22] Config: Add kenoma as available frontend. --- config/config.exs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/config/config.exs b/config/config.exs index bf24d1bd9..82be82747 100644 --- a/config/config.exs +++ b/config/config.exs @@ -656,14 +656,21 @@ config :pleroma, :static_fe, enabled: false # be used. # # config :pleroma, :frontends, -# primary: %{"name" => "pleroma", "ref" => "develop"}, -# admin: %{"name" => "admin", "ref" => "stable"}, +# primary: %{"name" => "pleroma-fe", "ref" => "develop"}, +# admin: %{"name" => "admin-fe", "ref" => "stable"}, # available: %{...} config :pleroma, :frontends, available: %{ - "pleroma" => %{ - "name" => "pleroma", + "kenoma" => %{ + "name" => "kenoma", + "git" => "https://git.pleroma.social/lambadalambda/kenoma", + "build_url" => + "https://git.pleroma.social/lambadalambda/kenoma/-/jobs/artifacts/${ref}/download?job=build", + "ref" => "master" + }, + "pleroma-fe" => %{ + "name" => "pleroma-fe", "git" => "https://git.pleroma.social/pleroma/pleroma-fe", "build_url" => "https://git.pleroma.social/pleroma/pleroma-fe/-/jobs/artifacts/${ref}/download?job=build", From 7e01339dddf78d99f609fdac934e89724f8254c3 Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 31 Jul 2020 17:58:50 +0200 Subject: [PATCH 10/22] Frontend mix task: Support installation from local file. --- lib/mix/tasks/pleroma/frontend.ex | 41 ++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/lib/mix/tasks/pleroma/frontend.ex b/lib/mix/tasks/pleroma/frontend.ex index bd65e9e36..c385c355a 100644 --- a/lib/mix/tasks/pleroma/frontend.ex +++ b/lib/mix/tasks/pleroma/frontend.ex @@ -27,7 +27,9 @@ defmodule Mix.Tasks.Pleroma.Frontend do strict: [ ref: :string, static_dir: :string, - build_url: :string + build_url: :string, + build_dir: :string, + file: :string ] ) @@ -39,7 +41,8 @@ defmodule Mix.Tasks.Pleroma.Frontend do cmd_frontend_info = %{ "name" => frontend, "ref" => options[:ref], - "build_url" => options[:build_url] + "build_url" => options[:build_url], + "build_dir" => options[:build_dir] } config_frontend_info = Pleroma.Config.get([:frontends, :available, frontend], %{}) @@ -66,10 +69,10 @@ defmodule Mix.Tasks.Pleroma.Frontend do fe_label = "#{frontend} (#{ref})" - shell_info("Downloading pre-built bundle for #{fe_label}") tmp_dir = Path.join(dest, "tmp") - with {_, :ok} <- {:download, download_build(frontend_info, tmp_dir)}, + with {_, :ok} <- + {:download_or_unzip, download_or_unzip(frontend_info, tmp_dir, options[:file])}, shell_info("Installing #{fe_label} to #{dest}"), :ok <- install_frontend(frontend_info, tmp_dir, dest) do File.rm_rf!(tmp_dir) @@ -77,20 +80,26 @@ defmodule Mix.Tasks.Pleroma.Frontend do Logger.configure(level: log_level) else - {:download, _} -> - shell_info("Could not download the frontend") + {:download_or_unzip, _} -> + shell_info("Could not download or unzip the frontend") _e -> shell_info("Could not install the frontend") end end - defp download_build(frontend_info, dest) do - url = String.replace(frontend_info["build_url"], "${ref}", frontend_info["ref"]) + defp download_or_unzip(frontend_info, temp_dir, file) do + if file do + with {:ok, zip} <- File.read(Path.expand(file)) do + unzip(zip, temp_dir) + end + else + download_build(frontend_info, temp_dir) + end + end - with {:ok, %{status: 200, body: zip_body}} <- - Pleroma.HTTP.get(url, [], timeout: 120_000, recv_timeout: 120_000), - {:ok, unzipped} <- :zip.unzip(zip_body, [:memory]) do + def unzip(zip, dest) do + with {:ok, unzipped} <- :zip.unzip(zip, [:memory]) do File.rm_rf!(dest) File.mkdir_p!(dest) @@ -107,6 +116,16 @@ defmodule Mix.Tasks.Pleroma.Frontend do end) :ok + end + end + + defp download_build(frontend_info, dest) do + shell_info("Downloading pre-built bundle for #{frontend_info["name"]}") + url = String.replace(frontend_info["build_url"], "${ref}", frontend_info["ref"]) + + with {:ok, %{status: 200, body: zip_body}} <- + Pleroma.HTTP.get(url, [], timeout: 120_000, recv_timeout: 120_000) do + unzip(zip_body, dest) else e -> {:error, e} end From 187d9bda0f28d5cc9548abc0b81f4f34e2aaacb1 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 3 Aug 2020 16:39:01 +0200 Subject: [PATCH 11/22] Description: Add new fields for frontend configuration. --- config/description.exs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/config/description.exs b/config/description.exs index b96fe9705..969d50a1d 100644 --- a/config/description.exs +++ b/config/description.exs @@ -3515,6 +3515,23 @@ config :pleroma, :config_description, [ key: "ref", type: :string, description: "reference of the installed primary frontend to be used" + }, + %{ + key: "git", + type: :string, + description: "URL of the git repository of the frontend" + }, + %{ + key: "build_url", + type: :string, + description: + "Either an url to a zip file containing the frontend or a template to build it by inserting the `ref`. The string `${ref}` will be replaced by the configured `ref`.", + example: "https://some.url/builds/${ref}.zip" + }, + %{ + key: "build_dir", + type: :string, + description: "The directory inside the zip file " } ] }, @@ -3532,6 +3549,23 @@ config :pleroma, :config_description, [ key: "ref", type: :string, description: "reference of the installed Admin frontend to be used" + }, + %{ + key: "git", + type: :string, + description: "URL of the git repository of the frontend" + }, + %{ + key: "build_url", + type: :string, + description: + "Either an url to a zip file containing the frontend or a template to build it by inserting the `ref`. The string `${ref}` will be replaced by the configured `ref`.", + example: "https://some.url/builds/${ref}.zip" + }, + %{ + key: "build_dir", + type: :string, + description: "The directory inside the zip file " } ] } From 5c2745725e2480f18bc81176575210bbef7f286c Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 3 Aug 2020 17:44:59 +0200 Subject: [PATCH 12/22] Docs: Document installation of frontends Co-authored-by: Roman Chvanikov --- docs/administration/CLI_tasks/frontend.md | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 docs/administration/CLI_tasks/frontend.md diff --git a/docs/administration/CLI_tasks/frontend.md b/docs/administration/CLI_tasks/frontend.md new file mode 100644 index 000000000..50bb926d0 --- /dev/null +++ b/docs/administration/CLI_tasks/frontend.md @@ -0,0 +1,50 @@ +# Managing frontends + +`mix pleroma.frontend install [--ref ] [--file ] [--build-url ] [--path ] [--build-dir ]` + +Frontend can be installed either from local zip file, or automatically downloaded from the web. + +You can give all the options directly on the command like, but missing information will be filled out by looking at the data configured under `frontends.available` in the config files. + +Currently known `` values are: +- [admin-fe](https://git.pleroma.social/pleroma/admin-fe) +- [kenoma](http://git.pleroma.social/lambadalambda/kenoma) +- [pleroma-fe](http://git.pleroma.social/pleroma/pleroma-fe) +- [fedi-fe](https://git.pleroma.social/pleroma/fedi-fe) +- [soapbox-fe](https://gitlab.com/soapbox-pub/soapbox-fe) + +You can still install frontends that are not configured, see below. + +## Example installations for a known frontend + +For a frontend configured under the `available` key, it's enough to install it by name. + +```bash +mix pleroma.frontend install pleroma +``` + +This will download the latest build for the the pre-configured `ref` and install it. It can then be configured as the one of the served frontends in the config file (see `primary` or `admin`). + +You can override any of the details. To install a pleroma build from a different url, you could do this: + +```bash +mix pleroma.frontend install pleroma --ref 2huedition --build-url https://example.org/raymoo.zip +``` + +Similarly, you can also install from a local zip file. + +```bash +mix pleroma.frontend install pleroma --ref mybuild --file ~/Downloads/doomfe.zip +``` + +The resulting frontend will always be installed into a folder of this template: `${instance_static}/frontends/${name}/${ref}` + +Careful: This folder will be completely replaced on installation + +## Example installation for an unknown frontend + +The installation process is the same, but you will have to give all the needed options on the commond line. For example: + +```bash +mix pleroma.frontend install gensokyo --ref master --build-url https://gensokyo.2hu/builds/marisa.zip +``` From 8b1da33a54dc3c6a489be7e2391e64af9e24d439 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 3 Aug 2020 17:50:53 +0200 Subject: [PATCH 13/22] Docs: Add info about installing from a local path. --- docs/administration/CLI_tasks/frontend.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/administration/CLI_tasks/frontend.md b/docs/administration/CLI_tasks/frontend.md index 50bb926d0..11c1c8614 100644 --- a/docs/administration/CLI_tasks/frontend.md +++ b/docs/administration/CLI_tasks/frontend.md @@ -48,3 +48,6 @@ The installation process is the same, but you will have to give all the needed o ```bash mix pleroma.frontend install gensokyo --ref master --build-url https://gensokyo.2hu/builds/marisa.zip ``` + +If you don't have a zip file but just want to install a frontend from a local path, you can simply copy the files over a folder of this template: `${instance_static}/frontends/${name}/${ref}` + From e26f2c913529748423384d467472f3ad06248ea4 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 3 Aug 2020 18:23:26 +0200 Subject: [PATCH 14/22] Changelog: Update with frontend mix task. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb782e82c..1edaed2c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added +- Frontends: Add mix task to install frontends. - Frontends: Add configurable frontends for primary and admin fe. - Chats: Added `accepts_chat_messages` field to user, exposed in APIs and federation. - Chats: Added support for federated chats. For details, see the docs. From 03da653a123341036e0caa84c6a7b4edd129afed Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 6 Aug 2020 16:41:56 +0200 Subject: [PATCH 15/22] Description: Refactor. --- config/description.exs | 95 ++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 58 deletions(-) diff --git a/config/description.exs b/config/description.exs index b56ea3339..1f50c9952 100644 --- a/config/description.exs +++ b/config/description.exs @@ -12,6 +12,36 @@ websocket_config = [ compress: false ] +frontend_options = [ + %{ + key: "name", + type: :string, + description: "Name of the installed Admin frontend" + }, + %{ + key: "ref", + type: :string, + description: "reference of the installed Admin frontend to be used" + }, + %{ + key: "git", + type: :string, + description: "URL of the git repository of the frontend" + }, + %{ + key: "build_url", + type: :string, + description: + "Either an url to a zip file containing the frontend or a template to build it by inserting the `ref`. The string `${ref}` will be replaced by the configured `ref`.", + example: "https://some.url/builds/${ref}.zip" + }, + %{ + key: "build_dir", + type: :string, + description: "The directory inside the zip file " + } +] + config :pleroma, :config_description, [ %{ group: :pleroma, @@ -3552,69 +3582,18 @@ config :pleroma, :config_description, [ key: :primary, type: :map, description: "Primary frontend, the one that is served for all pages by default", - children: [ - %{ - key: "name", - type: :string, - description: "Name of the installed primary frontend" - }, - %{ - key: "ref", - type: :string, - description: "reference of the installed primary frontend to be used" - }, - %{ - key: "git", - type: :string, - description: "URL of the git repository of the frontend" - }, - %{ - key: "build_url", - type: :string, - description: - "Either an url to a zip file containing the frontend or a template to build it by inserting the `ref`. The string `${ref}` will be replaced by the configured `ref`.", - example: "https://some.url/builds/${ref}.zip" - }, - %{ - key: "build_dir", - type: :string, - description: "The directory inside the zip file " - } - ] + children: frontend_options }, %{ key: :admin, type: :map, description: "Admin frontend", - children: [ - %{ - key: "name", - type: :string, - description: "Name of the installed Admin frontend" - }, - %{ - key: "ref", - type: :string, - description: "reference of the installed Admin frontend to be used" - }, - %{ - key: "git", - type: :string, - description: "URL of the git repository of the frontend" - }, - %{ - key: "build_url", - type: :string, - description: - "Either an url to a zip file containing the frontend or a template to build it by inserting the `ref`. The string `${ref}` will be replaced by the configured `ref`.", - example: "https://some.url/builds/${ref}.zip" - }, - %{ - key: "build_dir", - type: :string, - description: "The directory inside the zip file " - } - ] + children: frontend_options + }, + %{ + key: :available, + type: :map, + description: "A map containing frontends that we have some knowledge of" } ] } From 3f88366e2aebf34e81b3bec7db5c29175cdeca23 Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 7 Aug 2020 11:07:02 +0000 Subject: [PATCH 16/22] Apply 1 suggestion(s) to 1 file(s) --- config/description.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/description.exs b/config/description.exs index 1f50c9952..c7c8524dd 100644 --- a/config/description.exs +++ b/config/description.exs @@ -3593,7 +3593,7 @@ config :pleroma, :config_description, [ %{ key: :available, type: :map, - description: "A map containing frontends that we have some knowledge of" + description: "A map containing available frontends and parameters for their installation." } ] } From e5ab5fbe764dc8a1326fb31fb9754e5986ee53ee Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 7 Aug 2020 15:01:08 +0200 Subject: [PATCH 17/22] Mix task frontend: Read the docs. --- lib/mix/tasks/pleroma/frontend.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mix/tasks/pleroma/frontend.ex b/lib/mix/tasks/pleroma/frontend.ex index c385c355a..2adbf8d72 100644 --- a/lib/mix/tasks/pleroma/frontend.ex +++ b/lib/mix/tasks/pleroma/frontend.ex @@ -9,7 +9,7 @@ defmodule Mix.Tasks.Pleroma.Frontend do @shortdoc "Manages bundled Pleroma frontends" - # @moduledoc File.read!("docs/administration/CLI_tasks/frontend.md") + @moduledoc File.read!("docs/administration/CLI_tasks/frontend.md") def run(["install", "none" | _args]) do shell_info("Skipping frontend installation because none was requested") From d97b76104eabcd670aa78b8281832ab128373d36 Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 7 Aug 2020 15:10:34 +0200 Subject: [PATCH 18/22] Mix Task Frontend: Add tests. --- test/fixtures/tesla_mock/frontend.zip | Bin 0 -> 186 bytes test/fixtures/test.txt | 1 - test/tasks/frontend_test.exs | 69 ++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/tesla_mock/frontend.zip delete mode 100644 test/fixtures/test.txt create mode 100644 test/tasks/frontend_test.exs diff --git a/test/fixtures/tesla_mock/frontend.zip b/test/fixtures/tesla_mock/frontend.zip new file mode 100644 index 0000000000000000000000000000000000000000..114d576a3806cb864566e06b1fdd8e4cec0b83a7 GIT binary patch literal 186 zcmWIWW@h1H00FfHUIC}W{!bSHvO$=GL586uwYWsDq@pA=gp+}}VufQ|KbKB?X$3a} zBg+eB1_m%ul95@g07QujC8-r93Tc@+sayfxj7)OOxXhIRS;xQ##0wfhEQBqr5L?h} U2=HcQ1F2&KLO&oK2I4RP06@qk+yDRo literal 0 HcmV?d00001 diff --git a/test/fixtures/test.txt b/test/fixtures/test.txt deleted file mode 100644 index e9ea42a12..000000000 --- a/test/fixtures/test.txt +++ /dev/null @@ -1 +0,0 @@ -this is a text file diff --git a/test/tasks/frontend_test.exs b/test/tasks/frontend_test.exs new file mode 100644 index 000000000..5cd4594e2 --- /dev/null +++ b/test/tasks/frontend_test.exs @@ -0,0 +1,69 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.FrontendTest do + use Pleroma.DataCase + alias Mix.Tasks.Pleroma.Frontend + + @dir "test/frontend_static_test" + + setup do + File.mkdir_p!(@dir) + clear_config([:instance, :static_dir], @dir) + + on_exit(fn -> + File.rm_rf(@dir) + end) + end + + test "it downloads and unzips a known frontend" do + clear_config([:frontends, :available], %{ + "pleroma" => %{ + "ref" => "fantasy", + "name" => "pleroma", + "build_url" => "http://gensokyo.2hu/builds/${ref}", + "build_dir" => "" + } + }) + + Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/builds/fantasy"} -> + %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")} + end) + + Frontend.run(["install", "pleroma"]) + assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"])) + end + + test "it also works given a file" do + clear_config([:frontends, :available], %{ + "pleroma" => %{ + "ref" => "fantasy", + "name" => "pleroma", + "build_dir" => "" + } + }) + + Frontend.run(["install", "pleroma", "--file", "test/fixtures/tesla_mock/frontend.zip"]) + assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"])) + end + + test "it downloads and unzips unknown frontends" do + Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/madeup.zip"} -> + %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")} + end) + + Frontend.run([ + "install", + "unknown", + "--ref", + "baka", + "--build-url", + "http://gensokyo.2hu/madeup.zip", + "--build-dir", + "" + ]) + + assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"])) + end +end From de00a4c0f1cc5d61d0a821a2d0a292f8bd95e3f1 Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 7 Aug 2020 15:27:41 +0200 Subject: [PATCH 19/22] Mix Task Frontend Test: Capture IO. --- test/tasks/frontend_test.exs | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/test/tasks/frontend_test.exs b/test/tasks/frontend_test.exs index 5cd4594e2..6a9a931eb 100644 --- a/test/tasks/frontend_test.exs +++ b/test/tasks/frontend_test.exs @@ -6,6 +6,8 @@ defmodule Pleroma.FrontendTest do use Pleroma.DataCase alias Mix.Tasks.Pleroma.Frontend + import ExUnit.CaptureIO, only: [capture_io: 1] + @dir "test/frontend_static_test" setup do @@ -31,7 +33,10 @@ defmodule Pleroma.FrontendTest do %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")} end) - Frontend.run(["install", "pleroma"]) + capture_io(fn -> + Frontend.run(["install", "pleroma"]) + end) + assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"])) end @@ -44,7 +49,10 @@ defmodule Pleroma.FrontendTest do } }) - Frontend.run(["install", "pleroma", "--file", "test/fixtures/tesla_mock/frontend.zip"]) + capture_io(fn -> + Frontend.run(["install", "pleroma", "--file", "test/fixtures/tesla_mock/frontend.zip"]) + end) + assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"])) end @@ -53,16 +61,18 @@ defmodule Pleroma.FrontendTest do %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")} end) - Frontend.run([ - "install", - "unknown", - "--ref", - "baka", - "--build-url", - "http://gensokyo.2hu/madeup.zip", - "--build-dir", - "" - ]) + capture_io(fn -> + Frontend.run([ + "install", + "unknown", + "--ref", + "baka", + "--build-url", + "http://gensokyo.2hu/madeup.zip", + "--build-dir", + "" + ]) + end) assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"])) end From 50d5bdfd31970c9ab5461a3eeb2316dc3203dc61 Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 7 Aug 2020 16:03:06 +0200 Subject: [PATCH 20/22] Mix Task Frontend test: Expand. --- test/fixtures/tesla_mock/dist/test.txt | 1 + test/fixtures/tesla_mock/frontend_dist.zip | Bin 0 -> 334 bytes test/fixtures/test.txt | 1 + test/tasks/frontend_test.exs | 5 ++--- 4 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/tesla_mock/dist/test.txt create mode 100644 test/fixtures/tesla_mock/frontend_dist.zip create mode 100644 test/fixtures/test.txt diff --git a/test/fixtures/tesla_mock/dist/test.txt b/test/fixtures/tesla_mock/dist/test.txt new file mode 100644 index 000000000..e9ea42a12 --- /dev/null +++ b/test/fixtures/tesla_mock/dist/test.txt @@ -0,0 +1 @@ +this is a text file diff --git a/test/fixtures/tesla_mock/frontend_dist.zip b/test/fixtures/tesla_mock/frontend_dist.zip new file mode 100644 index 0000000000000000000000000000000000000000..20d7952a447a3540c3fad426a2ac67a9f76574cf GIT binary patch literal 334 zcmWIWW@h1H00Fle_CPQLO0Y7>Fr;J_m*|Iva56B5MCis_1952uHv=Qf3uXoeFcARP zuC~A{;B?sk=^{YwAj}KXUXof|qE}K;0yd^%g=1VlmkzoyB^jB;3P6;oP?B0vqL7xE zlgbs~&B!FjjLU5jP*(~t{B;B|p)O^GxD>;c2%|9F2{DQhXvl&_dzeuOR|Aa%xf;Vr RRyL5mOh7mfNY4Us7y$noJ|6%8 literal 0 HcmV?d00001 diff --git a/test/fixtures/test.txt b/test/fixtures/test.txt new file mode 100644 index 000000000..e9ea42a12 --- /dev/null +++ b/test/fixtures/test.txt @@ -0,0 +1 @@ +this is a text file diff --git a/test/tasks/frontend_test.exs b/test/tasks/frontend_test.exs index 6a9a931eb..0ca2b9a28 100644 --- a/test/tasks/frontend_test.exs +++ b/test/tasks/frontend_test.exs @@ -24,13 +24,12 @@ defmodule Pleroma.FrontendTest do "pleroma" => %{ "ref" => "fantasy", "name" => "pleroma", - "build_url" => "http://gensokyo.2hu/builds/${ref}", - "build_dir" => "" + "build_url" => "http://gensokyo.2hu/builds/${ref}" } }) Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/builds/fantasy"} -> - %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")} + %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend_dist.zip")} end) capture_io(fn -> From 199ad47c22e5d72741f5809eb015bac9b00cca03 Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 7 Aug 2020 17:04:44 +0200 Subject: [PATCH 21/22] Docs: Add OTP commands to frontend docs. --- docs/administration/CLI_tasks/frontend.md | 26 ++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/docs/administration/CLI_tasks/frontend.md b/docs/administration/CLI_tasks/frontend.md index 11c1c8614..7d1c1e937 100644 --- a/docs/administration/CLI_tasks/frontend.md +++ b/docs/administration/CLI_tasks/frontend.md @@ -19,7 +19,11 @@ You can still install frontends that are not configured, see below. For a frontend configured under the `available` key, it's enough to install it by name. -```bash +```sh tab="OTP" +./bin/pleroma_ctl frontend install pleroma +``` + +```sh tab="From Source" mix pleroma.frontend install pleroma ``` @@ -27,13 +31,21 @@ This will download the latest build for the the pre-configured `ref` and install You can override any of the details. To install a pleroma build from a different url, you could do this: -```bash -mix pleroma.frontend install pleroma --ref 2huedition --build-url https://example.org/raymoo.zip +```sh tab="OPT" +./bin/pleroma_ctl frontend install pleroma --ref 2hu_edition --build-url https://example.org/raymoo.zip +``` + +```sh tab="From Source" +mix pleroma.frontend install pleroma --ref 2hu_edition --build-url https://example.org/raymoo.zip ``` Similarly, you can also install from a local zip file. -```bash +```sh tab="OTP" +./bin/pleroma_ctl frontend install pleroma --ref mybuild --file ~/Downloads/doomfe.zip +``` + +```sh tab="From Source" mix pleroma.frontend install pleroma --ref mybuild --file ~/Downloads/doomfe.zip ``` @@ -45,7 +57,11 @@ Careful: This folder will be completely replaced on installation The installation process is the same, but you will have to give all the needed options on the commond line. For example: -```bash +```sh tab="OTP" +./bin/pleroma_ctl frontend install gensokyo --ref master --build-url https://gensokyo.2hu/builds/marisa.zip +``` + +```sh tab="From Source" mix pleroma.frontend install gensokyo --ref master --build-url https://gensokyo.2hu/builds/marisa.zip ``` From 6d6e43fd09a66740d447e77e9878d9d35bc07414 Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 25 Aug 2020 11:49:44 +0200 Subject: [PATCH 22/22] Description: Update description. --- config/description.exs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/config/description.exs b/config/description.exs index c50910911..29a657333 100644 --- a/config/description.exs +++ b/config/description.exs @@ -12,20 +12,35 @@ websocket_config = [ compress: false ] -frontend_options = [ +installed_frontend_options = [ %{ key: "name", label: "Name", type: :string, description: - "Name of the frontend. Valid config must include both `Name` and `Reference` values." + "Name of the installed frontend. Valid config must include both `Name` and `Reference` values." }, %{ key: "ref", label: "Reference", type: :string, description: - "Reference of the frontend to be used. Valid config must include both `Name` and `Reference` values." + "Reference of the installed frontend to be used. Valid config must include both `Name` and `Reference` values." + } +] + +frontend_options = [ + %{ + key: "name", + label: "Name", + type: :string, + description: "Name of the frontend." + }, + %{ + key: "ref", + label: "Reference", + type: :string, + description: "Reference of the frontend to be used." }, %{ key: "git", @@ -3587,13 +3602,13 @@ config :pleroma, :config_description, [ key: :primary, type: :map, description: "Primary frontend, the one that is served for all pages by default", - children: frontend_options + children: installed_frontend_options }, %{ key: :admin, type: :map, description: "Admin frontend", - children: frontend_options + children: installed_frontend_options }, %{ key: :available,