beabee-communityrm / monorepo

Beabee is platform for community journalism
https://www.beabee.io
GNU Affero General Public License v3.0
1 stars 0 forks source link

Very complex frontend routing configuration #1

Open JumpLink opened 1 month ago

JumpLink commented 1 month ago

After much trial and error, I think I now know why I failed to test the docker image of the frontend locally.

It took me a long time to understand how the frontend docker image works. Here is a summary:

When the frontend is started locally without docker:

Problems

  1. One problem is that the frontend does not display a meaningful error message when the backend is not available:

grafik

  1. Another problem is, that the env.appUrl is not used for the requests, so I can set whatever I want here, it won't change the fact that the backend is not accessible locally since the same host is always assumed. The way the frontend is currently implemented, everything must be accessible via the same domain, which is the domain via which the frontend is accessible. This is worked around in the production stack by an Nginx configuration, just as it is the case on the devlopment stack with the proxy in vite .

All API requests use the frontend host itself, which also means that no request errors occur, everything returns 200 even though the backend is not accessible:

grafik

  1. If I want to work on the frontend code to fix this problem, I can mount my local frontend build into the docker image, but then the necessary placeholders will not be replaced. So I have to build the container from scratch every time:

    frontend:
      build:
        context: ../..
        dockerfile: ./apps/frontend/Dockerfile
      restart: unless-stopped
      # Not working because docker-entrypoint.sh is not executed
      # volumes:
      #   - ../../apps/frontend/dist:/usr/share/nginx/html
      environment:
        APP_BASE_URL: ${BEABEE_AUDIENCE}
        API_BASE_URL: /api/1.0
        APP_REVISION: dev
        APP_VERSION: dev
        APPSIGNAL_KEY: ""
        CAPTCHAFOX_KEY: ""
        MAPTILER_KEY: ""
        CNR_MODE: ""
        EXPERIMENTAL_FEATURES: ""
  2. The router used in the production stack has its own repository and I had not yet dealt with it, so it was completely off my radar. The development environment uses the vite proxy for that which is included in the repository, but not the production router with his nginx config for that.

  3. Checking out the hive-deploy-stack, executing a script in it and then making automatic commits in it also increases the complexity and is not documented anywhere.

  4. The release scripts are bash scripts, which means that another language is used.

Proposed solution

Due to this complex setup, the problems described and the differences between the development stack and the production, it was very difficult to identify the problem here. New developers are likely to have the same problems, which makes it very difficult to get started. I also asked @wpf500 how I could test the frontend docker image locally and he didn't seem to have that in mind either. Instead, I would rethink the entire setup; I don't think the development stack should be too different from the production stack.

The routers for development and for productive hosting should be merged and usable locally and productively via environment variables.

The hive-deploy-stack should also not differ too much from the development environment and could instead be added to the monorepo and also be used for local development.

I would suggest the following steps:

With release-it we could:

Temporary solution

I have now adapted the docker-compose.yml and nginx.conf so that I can at least test the frontend docker image locally. I have checked the whole thing into the repo so that we can continue to test locally, even though this is not a clean, permanent solution and the image needs to rebuild each time when new changes to the frontend should be tested.

wpf500 commented 1 month ago

Thanks for documenting this. As you say, it's a confusing setup!

It would be great to unify the development and production setup, I think I agree with most of the things you've said. Let's have a look at it together tomorrow.

One thing to note though: I don't think we can remove hive-deploy-stack unfortunately. Portainer checks this repo out per stack and you can't tell it to only check out certain files, so if we changed it to point at monorepo it would check out the entire repo for each client.