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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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.

Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from ederign. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@ederign
Copy link
Member Author

ederign commented Jan 8, 2025

/assign @lucferbux

@ederign
Copy link
Member Author

ederign commented Jan 9, 2025

/assign @alexcreasy

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.

3 participants