Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Deploy UI within fidesops #625

Merged
merged 30 commits into from
Jun 14, 2022
Merged

Deploy UI within fidesops #625

merged 30 commits into from
Jun 14, 2022

Conversation

TheAndrewJackson
Copy link
Contributor

@TheAndrewJackson TheAndrewJackson commented Jun 9, 2022

Purpose

Build and serve the Admin UI within fidesops as a static website.

Changes

  • Update Dockerfile to build website and copy files into the project
  • Add startup event to serve the website if it's toggled on
  • Fix a few miscellaneous issues with serving the frontend from within fidesops
  • Refactor Head portion of pages into single FidesHead component to remove duplication

Checklist

  • Update CHANGELOG.md file
    • Merge in main so the most recent CHANGELOG.md file is being appended to
    • Add description within the Unreleased section in an appropriate category. Add a new category from the list at the top of the file if the needed one isn't already there.
    • Add a link to this PR at the end of the description with the PR number as the text. example: #1
  • Applicable documentation updated (guides, quickstart, postman collections, tutorial, fidesdemo, database diagram.
  • If docs updated (select one):
    • documentation complete, or draft/outline provided (tag docs-team to complete/review on this branch)
    • documentation issue created (tag docs-team to complete issue separately)
  • Good unit test/integration test coverage
  • This PR contains a DB migration. If checked, the reviewer should confirm with the author that the down_revision correctly references the previous migration before merging
  • The Run Unsafe PR Checks label has been applied, and checks have passed, if this PR touches any external services

Ticket

Fixes #528 #529

@TheAndrewJackson TheAndrewJackson marked this pull request as ready for review June 10, 2022 13:54
@TheAndrewJackson TheAndrewJackson requested a review from a team June 10, 2022 13:55
Comment on lines +63 to +64
| Admin UI Variables|---|---|---|---|---|
|`ENABLED` | `FIDESOPS__ADMIN_UI__ENABLED` | bool | False | True | Toggle whether the `/static` file directory is mounted to serve the Admin UI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this! 👍

@eastandwestwind
Copy link
Contributor

@TheAndrewJackson I'm getting this build err locally when trying to make server, any ideas?

Building fidesops
[+] Building 1.2s (6/6) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                   0.0s
 => => transferring dockerfile: 2.08kB                                                                                                                                                                 0.0s
 => [internal] load .dockerignore                                                                                                                                                                      0.0s
 => => transferring context: 208B                                                                                                                                                                      0.0s
 => ERROR [internal] load metadata for docker.io/library/python:3.9.13-slim-buster                                                                                                                     1.1s
 => ERROR [internal] load metadata for docker.io/library/node:16                                                                                                                                       1.1s
 => [auth] library/python:pull token for registry-1.docker.io                                                                                                                                          0.0s
 => [auth] library/node:pull token for registry-1.docker.io                                                                                                                                            0.0s
------
 > [internal] load metadata for docker.io/library/python:3.9.13-slim-buster:
------
------
 > [internal] load metadata for docker.io/library/node:16:
------
failed to solve with frontend dockerfile.v0: failed to create LLB definition: failed to authorize: rpc error: code = Unknown desc = failed to fetch oauth token: unexpected status: 500 Internal Server Error
ERROR: Service 'fidesops' failed to build : Build failed
make: *** [compose-build] Error 1

@eastandwestwind
Copy link
Contributor

Aside from my comment above ^ the code itself looks good.

Not blocking, but would like to add documentation for how to nav to the admin ui when the fidesops server is up and running.

@TheAndrewJackson
Copy link
Contributor Author

@TheAndrewJackson I'm getting this build err locally when trying to make server, any ideas?

Building fidesops
[+] Building 1.2s (6/6) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                   0.0s
 => => transferring dockerfile: 2.08kB                                                                                                                                                                 0.0s
 => [internal] load .dockerignore                                                                                                                                                                      0.0s
 => => transferring context: 208B                                                                                                                                                                      0.0s
 => ERROR [internal] load metadata for docker.io/library/python:3.9.13-slim-buster                                                                                                                     1.1s
 => ERROR [internal] load metadata for docker.io/library/node:16                                                                                                                                       1.1s
 => [auth] library/python:pull token for registry-1.docker.io                                                                                                                                          0.0s
 => [auth] library/node:pull token for registry-1.docker.io                                                                                                                                            0.0s
------
 > [internal] load metadata for docker.io/library/python:3.9.13-slim-buster:
------
------
 > [internal] load metadata for docker.io/library/node:16:
------
failed to solve with frontend dockerfile.v0: failed to create LLB definition: failed to authorize: rpc error: code = Unknown desc = failed to fetch oauth token: unexpected status: 500 Internal Server Error
ERROR: Service 'fidesops' failed to build : Build failed
make: *** [compose-build] Error 1

I ran into that issue this morning and resolved it by restarting my computer. I'm not completely sure what was wrong 🤷‍♂️

@TheAndrewJackson
Copy link
Contributor Author

Aside from my comment above ^ the code itself looks good.

Not blocking, but would like to add documentation for how to nav to the admin ui when the fidesops server is up and running.

Good idea. Can we get that in a follow up docs ticket? @eastandwestwind

@eastandwestwind
Copy link
Contributor

eastandwestwind commented Jun 14, 2022

I was able to resolve the make server issues, and got the app running.

Main question is, when I nav to http://0.0.0.0:8080/static/index.html, i'm receiving the placeholder index.html instead of the index.html supposedly copied over from the build in Dockerfile here. Is this expected?

@eastandwestwind
Copy link
Contributor

I've added a separate issue for docs here- #644

@TheAndrewJackson
Copy link
Contributor Author

I was able to resolve the make server issues, and got the app running.

Main question is, when I nav to http://0.0.0.0:8080/static/index.html, i'm receiving the placeholder index.html instead of the index.html supposedly copied over from the build in Dockerfile here. Is this expected?

Ahh, it's sort of expected. I ran into this a few times while developing this feature. What you're most likely seeing is the docker-compose.yml file is removing your UI files. Here is the snippet that is causing the issue:

    volumes:
      - type: bind
        source: ./
        target: /fidesops
        read_only: False
      - /fidesops/src/fidesops.egg-info

What's happening is the UI is built when the docker image is created initially. Then when make server or docker-compose up is run it mounts the local fidesops directory which doesn't contain the src/fidesops/build/static path so it creates the placeholder. If you comment out the snippet above in the docker-compose.yml file it should serve the UI like you're expecting as long as the initial docker image has the UI built into it.

@eastandwestwind
Copy link
Contributor

Thanks for the clarification @TheAndrewJackson !

@eastandwestwind eastandwestwind merged commit a3c4b02 into main Jun 14, 2022
@eastandwestwind eastandwestwind deleted the deploy_ui_within_fidesops branch June 14, 2022 14:16
Comment on lines +54 to +57
if not WEBAPP_INDEX.is_file():
WEBAPP_DIRECTORY.mkdir(parents=True, exist_ok=True)
with open(WEBAPP_DIRECTORY / "index.html", "w") as index_file:
index_file.write("<h1>Privacy is a Human Right!</h1>")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why is this needed? Is this just to handle a case where the docker build hasn't successfully built the admin UI and exported it, or is it more common than that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the same pattern that the fides used did for this update: https://github.com/ethyca/fides/blob/main/src/fidesapi/main.py#L59-L68. I believe that it is so there is always something to display in the event that the admin UI is toggled on.

It should probably be updated to display something for helpful to help the user know why the full admin ui isn't being displayed.

One common issue that Catherine, Sean, and I ran into while this was developed the the default config in the docker-compose.yml mounts a volume of the local fidesops files with this snippet

    volumes:
      - type: bind
        source: ./
        target: /fidesops
        read_only: False
      - /fidesops/src/fidesops.egg-info

Since the admin ui is only built while the docker image is created the ui files are missing from the local fidesops code causing the ui files to be missing once docker-compose up is ran.

This is okay because frontend development still uses npm run dev from clients/admin-ui and backend development won't typically need to use the admin ui from within the fidesops webserver. In the event that backend development needs the full admin within the webserver they can run the npm run prod-export command from within clients/admin-ui and that will build and move the full ui into the correct place within the backend code.

@@ -128,6 +137,7 @@ class FidesopsConfig(FidesSettings):
security: FidesopsSecuritySettings
execution: ExecutionSettings
root_user: RootUserSettings
admin_ui: AdminUiSettings
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add this to the log_all_config_values helper too? Sorry I didn't know a clean way to introspect the settings object to do this automatically

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll make an issue for it now and update the code.

sanders41 pushed a commit that referenced this pull request Sep 22, 2022
* Switch to Chakra image instead of nextjs

* checking in progress towards static build

* Mount static file directory

* Update Dockerfile

* Add dockerignore file

* Fix file path

* Update Dockerfile

* Add admin ui config model

* Conditionally build the UI

* Fix env_prefix

* Remove hello_world placeholder

* Remove if logic from Dockerfile

* Fix issues with BASE_URL

* Refactor Head into component &  update URNs

* Fix import order

* Update test URL path

* Fix isort lint issue

* Fix unit test failure

* Update docs and changelog
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Admin UI] Configure server to host static files
4 participants