From 91f960cc9413e4b7a5131b2988310a80dc5df9b4 Mon Sep 17 00:00:00 2001 From: Robert Prehn <3952444+prehnRA@users.noreply.github.com> Date: Fri, 2 Apr 2021 17:49:58 -0500 Subject: [PATCH 1/6] chore: Create initial documentation shell --- apps/core/guides/features/admin.md | 1 + apps/core/guides/features/auth.md | 1 + apps/core/guides/features/background-jobs.md | 1 + .../guides/features/content-management.md | 1 + apps/core/guides/features/devops-templates.md | 1 + .../guides/features/fluid-email-templates.md | 1 + apps/core/guides/features/i18n.md | 1 + .../core/guides/features/tasks-and-scripts.md | 1 + apps/core/guides/overview.md | 29 +++++--- apps/core/guides/tutorial.md | 1 + apps/core/lib/core_web/views/helpers.ex | 2 +- apps/core/mix.exs | 71 ++++++++++++++++++- 12 files changed, 98 insertions(+), 13 deletions(-) create mode 100644 apps/core/guides/features/admin.md create mode 100644 apps/core/guides/features/auth.md create mode 100644 apps/core/guides/features/background-jobs.md create mode 100644 apps/core/guides/features/content-management.md create mode 100644 apps/core/guides/features/devops-templates.md create mode 100644 apps/core/guides/features/fluid-email-templates.md create mode 100644 apps/core/guides/features/i18n.md create mode 100644 apps/core/guides/features/tasks-and-scripts.md create mode 100644 apps/core/guides/tutorial.md diff --git a/apps/core/guides/features/admin.md b/apps/core/guides/features/admin.md new file mode 100644 index 00000000..aad94154 --- /dev/null +++ b/apps/core/guides/features/admin.md @@ -0,0 +1 @@ +# Admin diff --git a/apps/core/guides/features/auth.md b/apps/core/guides/features/auth.md new file mode 100644 index 00000000..e97b0679 --- /dev/null +++ b/apps/core/guides/features/auth.md @@ -0,0 +1 @@ +# Authentication and Authorization diff --git a/apps/core/guides/features/background-jobs.md b/apps/core/guides/features/background-jobs.md new file mode 100644 index 00000000..e6291265 --- /dev/null +++ b/apps/core/guides/features/background-jobs.md @@ -0,0 +1 @@ +# Background Jobs diff --git a/apps/core/guides/features/content-management.md b/apps/core/guides/features/content-management.md new file mode 100644 index 00000000..1a420e8e --- /dev/null +++ b/apps/core/guides/features/content-management.md @@ -0,0 +1 @@ +# Content Management diff --git a/apps/core/guides/features/devops-templates.md b/apps/core/guides/features/devops-templates.md new file mode 100644 index 00000000..3e40f583 --- /dev/null +++ b/apps/core/guides/features/devops-templates.md @@ -0,0 +1 @@ +# DevOps Templates diff --git a/apps/core/guides/features/fluid-email-templates.md b/apps/core/guides/features/fluid-email-templates.md new file mode 100644 index 00000000..59585663 --- /dev/null +++ b/apps/core/guides/features/fluid-email-templates.md @@ -0,0 +1 @@ +# Fluid Email Templates diff --git a/apps/core/guides/features/i18n.md b/apps/core/guides/features/i18n.md new file mode 100644 index 00000000..05b5b619 --- /dev/null +++ b/apps/core/guides/features/i18n.md @@ -0,0 +1 @@ +# I18n diff --git a/apps/core/guides/features/tasks-and-scripts.md b/apps/core/guides/features/tasks-and-scripts.md new file mode 100644 index 00000000..adde2d85 --- /dev/null +++ b/apps/core/guides/features/tasks-and-scripts.md @@ -0,0 +1 @@ +# Tasks and Scripts diff --git a/apps/core/guides/overview.md b/apps/core/guides/overview.md index 832d9522..0ff8f53b 100644 --- a/apps/core/guides/overview.md +++ b/apps/core/guides/overview.md @@ -23,6 +23,13 @@ development better. ## Up and Running +Since Legendary is both a template and a framework, you can simply clone the repo +to start using it. It's a fully functional Phoenix app as-is. To start a new project: + +```sh +git clone git@gitlab.com:mythic-insight/legendary.git +``` + In order to start the server, run `script/server`. Any dependencies required will be installed automatically using [brew](https://brew.sh/), [asdf](https://asdf-vm.com/#/), and [hex](https://hex.pm/). @@ -31,27 +38,31 @@ Now you can visit [`localhost:4000`](http://localhost:4000) from your browser. ## Development -Your main app lives in apps/app/ and that is where you will do most of your +Check out [the tutorial](tutorial.md) to learn how to build your first app with +Legendary. + +Your main app lives in apps/app/ and you will do most of your development there. This is a normal Phoenix application and you can develop it as such. Any resources which apply to developing Phoenix applications will apply inside of the app. See the [Phoenix Guides](https://hexdocs.pm/phoenix/overview.html) for a good starting resource in Phoenix development. You should not generally need to change code in the other applications which -are part of the framework-- admin, content, core. We encourage you to avoid -changing those as much as possible, because doing so will make it more difficult -to upgrade Legendary to newer versions. However, they are available to you if -you find that there are no other ways to accomplish the changes you want to -accomplish. If you find yourself adding functionality to admin, content, or core +are part of the framework-- apps/admin, apps/content, apps/core. We encourage you +to avoid changing those as much as possible, because doing so will make it more +difficult to upgrade Legendary to newer versions. However, they are available to +you if you find that there are no other ways to accomplish the changes that you want. +If you find yourself adding functionality to admin, content, or core that you feel would be beneficial to all Legendary apps, consider making a code contribution back to the framework! ## CI Configuration -Legendary comes with gitlab CI settings which should work for you with minimal +Legendary comes with GitLab CI settings which should work for you with minimal setup. The CI script will automatically tag successful builds. To do this, you will -need to configure a [CI variable](-/settings/ci_cd) named `GITLAB_TOKEN`. This -token should be a [personal access token](/-/profile/personal_access_tokens) with +need to configure a [CI variable](https://docs.gitlab.com/ee/ci/variables/) named +`GITLAB_TOKEN`. This token should be a +[personal access token](https://gitlab.com/-/profile/personal_access_tokens) with `read_repository, write_repository` permissions. diff --git a/apps/core/guides/tutorial.md b/apps/core/guides/tutorial.md new file mode 100644 index 00000000..4f50eccc --- /dev/null +++ b/apps/core/guides/tutorial.md @@ -0,0 +1 @@ +# Tutorial diff --git a/apps/core/lib/core_web/views/helpers.ex b/apps/core/lib/core_web/views/helpers.ex index 4af16e83..0bfa73b1 100644 --- a/apps/core/lib/core_web/views/helpers.ex +++ b/apps/core/lib/core_web/views/helpers.ex @@ -1,6 +1,6 @@ defmodule Legendary.CoreWeb.Helpers do @moduledoc """ - HTML helpers for our styled (Fomantic UI) forms. + HTML helpers for our styled (Tailwind) forms. """ use Phoenix.HTML diff --git a/apps/core/mix.exs b/apps/core/mix.exs index 828e3789..e3a23f62 100644 --- a/apps/core/mix.exs +++ b/apps/core/mix.exs @@ -26,8 +26,10 @@ defmodule Legendary.Core.MixProject do homepage_url: "https://legendaryframework.org/", docs: [ main: "overview", - extra_section: "GUIDES", - extras: extras() + extra_section: "Getting Started", + extras: extras(), + groups_for_extras: groups_for_extras(), + groups_for_modules: groups_for_modules(), ], # Hex @@ -45,7 +47,70 @@ defmodule Legendary.Core.MixProject do end defp extras do - Path.wildcard("guides/**/*.md") + [ + "guides/overview.md", + "guides/tutorial.md", + # "guides/tutorial.md": [filename: "tutorial", title: "Tutorial"], + "guides/features/admin.md", + "guides/features/auth.md", + "guides/features/background-jobs.md", + "guides/features/content-management.md", + "guides/features/devops-templates.md", + "guides/features/fluid-email-templates.md", + "guides/features/i18n.md", + "guides/features/tasks-and-scripts.md", + ] + end + + defp groups_for_extras do + [ + Guides: ~r{guides/[^\.]+.md}, + ] + end + + defp groups_for_modules do + [ + "Auth": [ + Legendary.Auth, + Legendary.AuthWeb, + ~r{Legendary\.Auth(Web)?\..+}, + Legendary.CoreWeb.Router.PowExtensionRouter + ], + "Email": [ + Legendary.CoreEmail, + Legendary.CoreMailer, + Legendary.CoreWeb.EmailHelpers, + Legendary.CoreWeb.CoreEmailView, + ], + "Internationalization": [ + Legendary.I18n + ], + "Mix Tasks": [ + Legendary.Mix, + ], + "View Helpers": [ + Legendary.CoreWeb.ErrorHelpers, + Legendary.CoreWeb.Helpers, + ], + "Core Other": [ + Legendary.Core, + Legendary.Core.MapUtils, + Legendary.Core.Repo, + Legendary.Core.SharedDBConnectionPool, + Mix.Legendary, + ], + "Web Other": [ + Legendary.CoreWeb, + Legendary.CoreWeb.Endpoint, + Legendary.CoreWeb.ErrorView, + Legendary.CoreWeb.Gettext, + Legendary.CoreWeb.LayoutView, + Legendary.CoreWeb.Router, + Legendary.CoreWeb.Router.Helpers, + Legendary.CoreWeb.Telemetry, + Legendary.CoreWeb.UserSocket, + ] + ] end # Configuration for the OTP application. From f2e27bbaa1df5e21f53c4c64ad1dc96142098ed1 Mon Sep 17 00:00:00 2001 From: Robert Prehn <3952444+prehnRA@users.noreply.github.com> Date: Fri, 9 Apr 2021 15:46:10 -0500 Subject: [PATCH 2/6] fix: Make layout tags work correctly --- apps/app/lib/app_web/views/layout_view.ex | 42 +++++------------------ 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/apps/app/lib/app_web/views/layout_view.ex b/apps/app/lib/app_web/views/layout_view.ex index 8c5b31d9..27d26082 100644 --- a/apps/app/lib/app_web/views/layout_view.ex +++ b/apps/app/lib/app_web/views/layout_view.ex @@ -1,39 +1,15 @@ defmodule AppWeb.LayoutView do use AppWeb, :view - def title(view_module, template, assigns) do - delegate_with_default(view_module, :title, [view_module, template, assigns], Legendary.I18n.t!("en", "site.title")) - end + def title(_, _, _) do + Legendary.I18n.t!("en", "site.title") + end - def excerpt(view_module, template, assigns) do - delegate_with_default(view_module, :excerpt, [view_module, template, assigns], Legendary.I18n.t!("en", "site.excerpt")) - end + def excerpt(_, _, _) do + Legendary.I18n.t!("en", "site.excerpt") + end - def feed_tag(conn, view_module, view_template, assigns) do - delegate_with_default(view_module, :feed_tag, [conn, view_module, view_template, assigns], nil) - end - - defp delegate_with_default(nil, _, _, default), do: default - defp delegate_with_default(view_module, function_name, args, default) do - sibling_layout = sibling_layout_view(view_module) - if function_exported?(sibling_layout, function_name, args |> Enum.count()) do - apply(sibling_layout, function_name, args) - else - default - end - end - - defp sibling_layout_view(view_module) do - view_module - |> parent_module() - |> Module.concat("LayoutView") - end - - defp parent_module(mod) do - [_|tail] = Module.split(mod) |> Enum.reverse() - - tail - |> Enum.reverse() - |> Module.concat() - end + def feed_tag(_, _, _, _) do + nil + end end From 39f508b2970c3dca39d51b5e519fa723f244d0a7 Mon Sep 17 00:00:00 2001 From: Robert Prehn <3952444+prehnRA@users.noreply.github.com> Date: Fri, 16 Apr 2021 15:02:05 -0500 Subject: [PATCH 3/6] fix: Make _build folder available to docker build --- .gitlab-ci.yml | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b0083a18..85e919c5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,7 @@ stages: - application_dependencies - asset_dependencies + - prebuild - test - deploy_tags - deploy @@ -63,12 +64,27 @@ fetch_asset_dependencies: exclude: - apps/app/assets/node_modules +prebuild: + stage: prebuild + image: "elixir:1.10" + needs: + - fetch_application_dependencies + cache: + - key: + files: + - mix.lock + paths: + - _build/ + - deps/ + script: + - mix compile + # Test stage. Runs various tests and speculatively builds docker image in # parallel, in case the build passes. test: stage: test needs: - - fetch_application_dependencies + - prebuild image: "elixir:1.10" services: - name: postgres:12 @@ -85,7 +101,7 @@ build_image_for_commit: stage: test needs: - fetch_asset_dependencies - - fetch_application_dependencies + - prebuild image: "docker:20.10" only: - master @@ -109,6 +125,7 @@ build_image_for_commit: - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA # This copies the elixir build artifacts for deps and app so that we can cache them - docker cp `docker create $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA`:/root/app/_build/prod _build + - la -la _build/ # If tests pass, tag the commit and update package versions deploy_to_tags: From d7351ac34fefee14f728d568152f49ac2d53fa3d Mon Sep 17 00:00:00 2001 From: Robert Prehn <3952444+prehnRA@users.noreply.github.com> Date: Fri, 16 Apr 2021 15:32:14 -0500 Subject: [PATCH 4/6] fix: Roll prebuild and app dependencies stages together --- .gitlab-ci.yml | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 85e919c5..968f3f25 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,6 @@ stages: - - application_dependencies - - asset_dependencies - prebuild + - asset_dependencies - test - deploy_tags - deploy @@ -20,7 +19,7 @@ variables: # across jobs and pipelines. Note that elixir deps need to go first, because # we need the phoenix and phoenix_html hex packages to install their JS. fetch_application_dependencies: - stage: application_dependencies + stage: prebuild image: "elixir:1.10" cache: key: @@ -34,6 +33,7 @@ fetch_application_dependencies: - mix local.rebar --force - mix deps.get - mix deps.compile + - mix compile # Make results available to other jobs artifacts: paths: @@ -64,21 +64,6 @@ fetch_asset_dependencies: exclude: - apps/app/assets/node_modules -prebuild: - stage: prebuild - image: "elixir:1.10" - needs: - - fetch_application_dependencies - cache: - - key: - files: - - mix.lock - paths: - - _build/ - - deps/ - script: - - mix compile - # Test stage. Runs various tests and speculatively builds docker image in # parallel, in case the build passes. test: @@ -125,7 +110,6 @@ build_image_for_commit: - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA # This copies the elixir build artifacts for deps and app so that we can cache them - docker cp `docker create $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA`:/root/app/_build/prod _build - - la -la _build/ # If tests pass, tag the commit and update package versions deploy_to_tags: From 74eacb6ccf681cea47afda315f69a4a27e5ee739 Mon Sep 17 00:00:00 2001 From: Robert Prehn <3952444+prehnRA@users.noreply.github.com> Date: Fri, 16 Apr 2021 15:35:13 -0500 Subject: [PATCH 5/6] fix: Rename CI job --- .gitlab-ci.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 968f3f25..714141eb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -15,10 +15,9 @@ variables: # fetch & clean the repo rather than completely cloning (faster) GIT_STRATEGY: fetch -# Dependency stages-- fetch these first so that we can cache them and reuse them -# across jobs and pipelines. Note that elixir deps need to go first, because -# we need the phoenix and phoenix_html hex packages to install their JS. -fetch_application_dependencies: +# Build the app once and cache it so that we can have fast compiles in test +# and Docker built steps +prebuild: stage: prebuild image: "elixir:1.10" cache: @@ -46,7 +45,7 @@ fetch_asset_dependencies: stage: asset_dependencies image: "node:15.0" needs: - - fetch_application_dependencies + - prebuild only: - master cache: From 76ca4505000db466b76e59d730aa1b9307c8ff13 Mon Sep 17 00:00:00 2001 From: Robert Prehn <3952444+prehnRA@users.noreply.github.com> Date: Fri, 16 Apr 2021 16:04:21 -0500 Subject: [PATCH 6/6] chore: Log _build contents --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 714141eb..bed29d01 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -99,6 +99,7 @@ build_image_for_commit: - _build/ - deps/ script: + - ls -la _build - docker login "https://${CI_REGISTRY}" -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD - docker pull $CI_REGISTRY_IMAGE:latest || true # This enables fast parallel builds @@ -109,6 +110,7 @@ build_image_for_commit: - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA # This copies the elixir build artifacts for deps and app so that we can cache them - docker cp `docker create $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA`:/root/app/_build/prod _build + - ls -la _build # If tests pass, tag the commit and update package versions deploy_to_tags: