Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bff): serving static assets on bff #690

Merged
merged 2 commits into from
Jan 13, 2025

Conversation

ederign
Copy link
Member

@ederign ederign commented Jan 8, 2025

Description

This PR is a preparation for the BFF and FE being served in production on the same container.

At "/" we are now serving static files:

Screenshot 2025-01-08 at 5 23 57 PM

As we used to do, we keep serving the BFF API on "/api/v1/*".

It is important also to highlight that on production (when using binaries), we need to copy the assets to the target containers. I've decided not to pack the static assets in the binary and serve them in the filesystem. I believe this makes it more coherent with our architecture (but I'm open to discussion and suggestions). If you would like more details on this, please look at MakeFile and Docker file changes.

Changes on this PR:

  • Dockerfile: copying the static assets during build process and passing the target asset dir as parameter to binary
  • Makefile: also added the STATIC_ASSETS_DIR property, pointing to root static folder
  • main.go: added the new configuraton for static assets
  • app.go: in order to avoid class, I've to split the router in two. One for the /api and another (server mux) to also handle "/" for static assets.
  • app_Test.go: test file to make sure that we don't break this
  • middleware.go: I've ignored the enforecer to use headers when we are using static files
  • clients/ui/bff/internal/api/test_utils.go: as we can run the tests on the ide, it's annoying to hardcode the parameters of every test location to find the static folder. So I write this small traversal to find assets dir based on go.mod, not matter where the tests are located. THIS IS NOT INTEND FOR PRODUCTION BECAUSE WE SHOULD USE PARAMETERS there.
  • clients/ui/bff/internal/config/environment.go: new configurations
  • clients/ui/bff/static/index.html and clients/ui/bff/static/sub/test.html STUB files

How Has This Been Tested?

  • Loading the static assets:
Screenshot 2025-01-08 at 5 23 57 PM
  • Loading the API to make sure that keep working
Screenshot 2025-01-08 at 5 24 51 PM
making sure that if I pass a bad header keep blocking requests
curl -i -H "fsdfsdfs-userid: [email protected]" "localhost:4000/api/v1/healthcheck"                      (kind-up-running/default)
HTTP/1.1 400 Bad Request
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Wed, 08 Jan 2025 22:32:38 GMT
Content-Length: 92

{
	"error": {
		"code": "400",
		"message": "missing required header: kubeflow-userid"
	}
}

I've also started to test this with our production assets of frontend.

Screenshot 2025-01-08 at 4 59 28 PM

Kind of work, but I was not able to figure out how to fix the routing. I've asked for FE guys help to debug the proxy calls..

Merge criteria:

  • All the commits have been signed-off (To pass the DCO check)
  • The commits have meaningful messages; the author will squash them after approval or in case of manual merges will ask to merge with squash.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work.
  • Code changes follow the kubeflow contribution guidelines.

@ederign
Copy link
Member Author

ederign commented Jan 8, 2025

/assign @lucferbux

@ederign
Copy link
Member Author

ederign commented Jan 9, 2025

/assign @alexcreasy

Copy link
Contributor

@Griffin-Sullivan Griffin-Sullivan left a comment

Choose a reason for hiding this comment

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

I tested locally after rebasing and rebuilding the frontend with the proper env variables you can run the BFF with

make run MOCK_K8S_CLIENT=true MOCK_MR_CLIENT=true STATIC_ASSETS_DIR="../frontend/dist"

and you will get:
screenshot_from_2025-01-13_10-51-07_720

clients/ui/bff/Dockerfile Outdated Show resolved Hide resolved
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Griffin-Sullivan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Co-authored-by: Griffin Sullivan <[email protected]>
Signed-off-by: Eder Ignatowicz <[email protected]>
@ederign
Copy link
Member Author

ederign commented Jan 13, 2025

nice catch @Griffin-Sullivan

@Griffin-Sullivan
Copy link
Contributor

/lgtm

@google-oss-prow google-oss-prow bot added the lgtm label Jan 13, 2025
@google-oss-prow google-oss-prow bot merged commit 4cedb36 into kubeflow:main Jan 13, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants