Skip to content

Commit

Permalink
embed UI in the operator-api
Browse files Browse the repository at this point in the history
Signed-off-by: David Viejo <[email protected]>
  • Loading branch information
dviejokfs committed Feb 27, 2023
1 parent e7fabce commit 1a826fd
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 4,764 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: 16

- name: Install dependencies
uses: bahmutov/npm-install@v1
with:
working-directory: ./ui

- name: Build project
run: npm run build
working-directory: ./ui

- name: Copy build to api
run: cp -r ./ui/dist ./api/dist
working-directory: .

- name: Set up Go
uses: actions/setup-go@v2
with:
Expand All @@ -33,3 +52,4 @@ jobs:
workdir: ./api
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
UI_PATH: ./ui/dist
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
.idea
.vscode
.DS_Store
.DS_Store
dist
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3


RUN \
microdnf update --nodocs && \
microdnf install curl ca-certificates shadow-utils --nodocs

COPY CREDITS /licenses/CREDITS
COPY LICENSE /licenses/LICENSE
LABEL name="HLF Operator UI" \
vendor="Kung Fu Software <[email protected]>" \
maintainer="Kung Fu Software <[email protected]>" \
version="v1.1.0" \
release="v1.1.0"

COPY hlf-operator-api /hlf-operator-api

CMD ["/hlf-operator-api"]
30 changes: 12 additions & 18 deletions api/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
package cmd

import (
"fmt"
"github.com/kfsoftware/hlf-operator-ui/api/cmd/serve"
"os"

"github.com/kfsoftware/hlf-operator-ui/api/config"
"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Use: "hlf-operator-api",
Short: "Hugo is a very fast static site generator",
Long: `A Fast and Flexible Static Site Generator built with
func NewRootCMD(conf config.ConfigCMD) *cobra.Command {
var rootCmd = &cobra.Command{
Use: "hlf-operator-api",
Short: "Hugo is a very fast static site generator",
Long: `A Fast and Flexible Static Site Generator built with
love by spf13 and friends in Go.
Complete documentation is available at http://hugo.spf13.com`,
Run: func(cmd *cobra.Command, args []string) {
// Do Stuff Here
},
}

func Execute() {
Run: func(cmd *cobra.Command, args []string) {
// Do Stuff Here
},
}
rootCmd.AddCommand(
serve.NewServeCommand(),
serve.NewServeCommand(conf),
)
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
return rootCmd
}
12 changes: 11 additions & 1 deletion api/cmd/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/rsa"
"crypto/tls"
"crypto/x509"
"embed"
"fmt"
gqlgengraphql "github.com/99designs/gqlgen/graphql"
"github.com/99designs/gqlgen/graphql/handler"
Expand All @@ -16,16 +17,19 @@ import (
jwtmiddleware "github.com/auth0/go-jwt-middleware"
"github.com/form3tech-oss/jwt-go"
"github.com/gin-contrib/cors"
"github.com/gin-contrib/static"
"github.com/gin-gonic/gin"
"github.com/hyperledger/fabric-gateway/pkg/client"
"github.com/hyperledger/fabric-gateway/pkg/identity"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
apiconfig "github.com/kfsoftware/hlf-operator-ui/api/config"
cmdconfig "github.com/kfsoftware/hlf-operator-ui/api/config"
"github.com/kfsoftware/hlf-operator-ui/api/gql"
"github.com/kfsoftware/hlf-operator-ui/api/gql/resolvers"
"github.com/kfsoftware/hlf-operator-ui/api/log"
"github.com/kfsoftware/hlf-operator-ui/api/ui"
"github.com/kfsoftware/hlf-operator/controllers/utils"
operatorv1 "github.com/kfsoftware/hlf-operator/pkg/client/clientset/versioned"
"github.com/lestrrat-go/jwx/jwk"
Expand Down Expand Up @@ -64,6 +68,7 @@ type serveCmd struct {
authJWKS string
authIssuer string
config string
views embed.FS
}

type IdentityStruct struct {
Expand Down Expand Up @@ -240,6 +245,10 @@ func (s serveCmd) run() error {
},
MaxAge: 12 * time.Hour,
}))

fileSystem := ui.NewFileSystemUI(s.views, "dist")
serverMux.Use(static.Serve("/", fileSystem))

graphqlHandler := gin.HandlerFunc(func(c *gin.Context) {
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
Expand Down Expand Up @@ -319,7 +328,7 @@ func newGrpcConnection(peerEndpoint string, tlsCert []byte) (*grpc.ClientConn, e
return connection, nil
}

func NewServeCommand() *cobra.Command {
func NewServeCommand(cmdConfig cmdconfig.ConfigCMD) *cobra.Command {
conf := &serveConfig{}
cmd := &cobra.Command{
Use: "serve",
Expand All @@ -334,6 +343,7 @@ func NewServeCommand() *cobra.Command {
authJWKS: conf.authJWKS,
authIssuer: conf.authIssuer,
config: conf.config,
views: cmdConfig.Views,
}
return s.run()
},
Expand Down
7 changes: 7 additions & 0 deletions api/config/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package config

import "embed"

type ConfigCMD struct {
Views embed.FS
}
3 changes: 2 additions & 1 deletion api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
github.com/auth0/go-jwt-middleware v1.0.1
github.com/form3tech-oss/jwt-go v3.2.2+incompatible
github.com/gin-contrib/cors v1.4.0
github.com/gin-contrib/static v0.0.1
github.com/gin-gonic/gin v1.8.1
github.com/golang/protobuf v1.5.2
github.com/hyperledger/fabric v2.1.1+incompatible
Expand All @@ -29,6 +30,7 @@ require (
github.com/slok/go-http-metrics v0.10.0
github.com/spf13/viper v1.10.1
google.golang.org/grpc v1.43.0
gopkg.in/yaml.v3 v3.0.1
sigs.k8s.io/yaml v1.2.0
)

Expand Down Expand Up @@ -105,7 +107,6 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.18.4 // indirect
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/utils v0.0.0-20211116205334-6203023598ed // indirect
Expand Down
Loading

0 comments on commit 1a826fd

Please sign in to comment.