diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index fb0b042ab..6dc2b8bf8 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -14,6 +14,11 @@ on: required: true default: development type: environment + client-ref: + description: "Client branch or tag" + required: false + default: main + type: string permissions: id-token: write # This is required for requesting the JWT for OIDC @@ -30,7 +35,34 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v6 + + - name: Checkout code + uses: actions/checkout@v6 + with: + repository: graasp/client + ref: ${{ inputs.client-ref || 'main' }} + path: client + + - name: Install Mise + uses: jdx/mise-action@v3 + + - name: build client + run: cd client && mise run build && cp -r dist ../priv/static/client + env: + VITE_VERSION: ${{ inputs.version || github.sha }} + VITE_GRAASP_API_HOST: ${{ vars.VITE_GRAASP_API_HOST }} + VITE_GRAASP_WS_HOST: ${{ vars.VITE_GRAASP_WS_HOST }} + VITE_GRAASP_LIBRARY_HOST: ${{ vars.VITE_GRAASP_LIBRARY_HOST }} + VITE_SENTRY_ENV: ${{ inputs.environment || 'development' }} + VITE_SENTRY_DSN: ${{ secrets.VITE_SENTRY_DSN }} + VITE_SHOW_NOTIFICATIONS: true + VITE_UMAMI_WEBSITE_ID: ${{ secrets.VITE_UMAMI_WEBSITE_ID }} + VITE_UMAMI_HOST: ${{ vars.VITE_UMAMI_HOST }} + VITE_RECAPTCHA: ${{ secrets.VITE_RECAPTCHA_SITE_KEY }} + VITE_GRAASP_H5P_INTEGRATION_URL: ${{ vars.VITE_GRAASP_H5P_INTEGRATION_URL }} + VITE_GRAASP_REDIRECTION_HOST: ${{ vars.VITE_GRAASP_REDIRECTION_HOST }} + shell: bash - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v4 diff --git a/.gitignore b/.gitignore index ef15e74f9..67ec8828a 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,6 @@ npm-debug.log # PLT caches /priv/plts/*.plt /priv/plts/*.plt.hash + +# client SPA artifacts +/priv/static/client diff --git a/lib/admin/docs.ex b/lib/admin/docs.ex new file mode 100644 index 000000000..e69de29bb diff --git a/lib/admin_web.ex b/lib/admin_web.ex index d33a4bcab..2fe8286d8 100644 --- a/lib/admin_web.ex +++ b/lib/admin_web.ex @@ -18,7 +18,7 @@ defmodule AdminWeb do """ def static_paths, - do: ~w(assets fonts images icons favicon.ico favicons robots.txt) + do: ~w(assets fonts images icons client favicon.ico favicons robots.txt) def router do quote do diff --git a/lib/admin_web/controllers/client_controller.ex b/lib/admin_web/controllers/client_controller.ex new file mode 100644 index 000000000..f8939ea01 --- /dev/null +++ b/lib/admin_web/controllers/client_controller.ex @@ -0,0 +1,19 @@ +defmodule AdminWeb.ClientController do + use AdminWeb, :controller + + def index(conn, _params) do + conn + |> put_resp_content_type("text/html") + |> send_resp(200, render_react_app()) + end + + # Serve the index.html file as-is and let React + # take care of the rendering and client-side rounting. + # + # Potential improvement: Cache the file contents here + # in an ETS table so we don't read from the disk for every request. + defp render_react_app do + Application.app_dir(:admin, "priv/static/client/index.html") + |> File.read!() + end +end diff --git a/lib/admin_web/controllers/docs_html.ex b/lib/admin_web/controllers/docs_html.ex new file mode 100644 index 000000000..e69de29bb diff --git a/lib/admin_web/controllers/redirection_controller.ex b/lib/admin_web/controllers/redirection_controller.ex index fa9f1abc7..b098eb483 100644 --- a/lib/admin_web/controllers/redirection_controller.ex +++ b/lib/admin_web/controllers/redirection_controller.ex @@ -4,8 +4,4 @@ defmodule AdminWeb.RedirectionController do def library(conn, _params) do redirect(conn, external: Application.get_env(:admin, :library_origin)) end - - def login(conn, _params) do - redirect(conn, external: "#{Application.get_env(:admin, :client_origin)}/auth/login") - end end diff --git a/lib/admin_web/router.ex b/lib/admin_web/router.ex index 729dc6e80..c78d109f1 100644 --- a/lib/admin_web/router.ex +++ b/lib/admin_web/router.ex @@ -57,9 +57,17 @@ defmodule AdminWeb.Router do delete "/locale", LandingController, :remove_locale generate_localized_routes() + + get "/home", ClientController, :index + get "/published", ClientController, :index + get "/recycled", ClientController, :index + get "/account/*path", ClientController, :index + get "/auth/*path", ClientController, :index + get "/builder/*path", ClientController, :index + get "/player/*path", ClientController, :index + # redirections for now get "/library", RedirectionController, :library - get "/auth/login", RedirectionController, :login end scope "/admin", AdminWeb do