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

Serve UI from api server #6954

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ pkg/**/mock.go linguist-generated=true
pkg/**/mock_Backend.go linguist-generated=true
pkg/**/mock_Client.go linguist-generated=true
ui/src/app/api-gen/**/* linguist-generated=true
pkg/apiserver-impl/ui/**/* linguist-generated=true
25 changes: 25 additions & 0 deletions .github/workflows/check-generated-files.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: check-generated-files
on:
pull_request:
branches:
- main

jobs:
check-ui-static-files:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Generate static files for UI
run: make ui-static

- name: Verify Changed files
uses: tj-actions/verify-changed-files@7f1b21ceb7ef533b97b46e89e2f882ee5cb17ae0
id: verify-changed-files

- name: Some files have changed
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: |
echo "::error Changed files: ${{ steps.verify-changed-files.outputs.changed_files }} -- Please regenerate with make ui-static"
exit 1
2 changes: 1 addition & 1 deletion .sonarcloud.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sonar.organization=redhat-developer
# Path to sources
sonar.sources=cmd,pkg
# Source File Exclusions: Patterns used to exclude some source files from analysis.
sonar.exclusions=**/*_test.go
sonar.exclusions=**/*_test.go,pkg/apiserver-impl/ui/**
# Source File Inclusions : Patterns used to include some source files and only these ones in analysis.
# sonar.inclusions=

Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ default: bin
help: ## Show this help.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

.PHONY: ui-static
ui-static: ## build static files for UI to be served by embedded API server
(cd ui && npm install && npm run build) && rm -rf pkg/apiserver-impl/ui/* && mv ui/dist/devfile-builder/* pkg/apiserver-impl/ui/

.PHONY: bin
bin: ## build the odo binary
go build ${BUILD_FLAGS} cmd/odo/odo.go
Expand Down
14 changes: 13 additions & 1 deletion pkg/apiserver-impl/starterserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package apiserver_impl

import (
"context"
"embed"
"fmt"
"io/fs"
"net"
"net/http"

Expand All @@ -15,6 +17,9 @@ import (
"k8s.io/klog"
)

//go:embed ui/*
var staticFiles embed.FS

type ApiServer struct {
PushWatcher <-chan struct{}
}
Expand All @@ -28,6 +33,7 @@ func StartServer(
stateClient state.Client,
preferenceClient preference.Client,
) ApiServer {
var err error

pushWatcher := make(chan struct{})
defaultApiService := NewDefaultApiService(
Expand All @@ -42,7 +48,13 @@ func StartServer(

router := openapi.NewRouter(defaultApiController)

var err error
fSys, err := fs.Sub(staticFiles, "ui")
if err != nil {
// Assertion, error can only happen if the path "ui" is not valid
panic(err)
}
staticServer := http.FileServer(http.FS(fSys))
router.PathPrefix("/").Handler(staticServer)

if port == 0 {
port, err = util.NextFreePort(20000, 30001, nil, "")
Expand Down
1 change: 1 addition & 0 deletions pkg/apiserver-impl/ui/103.a91ee51a71a891e1.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading