Skip to content
Open
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
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Build the manager binary
FROM golang:1.21 AS backend-builder
COPY backend/ /build/backend
COPY build.sh /build/
WORKDIR /build
RUN sh -x ./build.sh --backend && ls /build/bin/ && sleep 10

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
#FROM gcr.io/distroless/static:nonroot
FROM node:21 AS frontend-builder
COPY frontend/ /build/frontend
COPY build.sh /build/
WORKDIR /build/frontend
RUN npm install
RUN npm run build

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
#FROM gcr.io/distroless/static:nonroot
FROM debian:latest
WORKDIR /src
COPY --from=backend-builder /build/bin/cfs-gui .
COPY --from=backend-builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=frontend-builder /build/frontend/dist ./dist/
EXPOSE 6007
ENTRYPOINT ["/src/cfs-gui","-c","/src/config/"]
18 changes: 16 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@

phony := build
phony += clean
phony += backend
phony += frontend

build: build.sh
sh build.sh
DOCKER_IMAGE="cubefs-dashboard"

build: frontend backend

docker-build:
docker build . -t "${DOCKER_IMAGE}"

docker-push:
docker push "${DOCKER_IMAGE}"

frontend:
sh build.sh --frontend

backend:
sh build.sh --backend
clean: bin
rm -rf bin

Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,35 @@ total 26256
-rw-r--r-- 1 root root 1009 Jul 27 17:26 config.yml
drwxr-xr-x 6 root root 4096 Jul 27 17:27 dist
```

# Configuration
## /src/config/config.yaml

```
server:
port: 6007
mode: dev
static_resource:
enable: true
relative_path: /portal
root_path: ./dist
prefix:
api: /api/cubefs
```
## /src/config/mysql.yaml
```
mysql:
host:
port:
slaveHost:
slavePort:
database:
user:
password:
maxIdleConn: 20
MaxOpenConn: 300
```

# Preview
## Cluster overview
<img src="https://github.com/cubefs/cubefs-dashboard/blob/main/pictures/cluster_overview.png" align=center/>
Expand Down
33 changes: 0 additions & 33 deletions backend/conf/config.yml

This file was deleted.

31 changes: 16 additions & 15 deletions backend/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,35 @@ package config

import (
"github.com/spf13/viper"

"github.com/cubefs/cubefs-dashboard/backend/helper/crypt"
)

var Conf *Config

func Init(configPath string) (err error) {
viper.SetConfigFile(configPath)
serverConfig := viper.New()
mysqlConfig := viper.New()
serverConfig.SetConfigFile(configPath + "config.yaml")
mysqlConfig.SetConfigFile(configPath + "mysql.yaml")

err = serverConfig.ReadInConfig()
if err != nil {
return err
}

err = mysqlConfig.ReadInConfig()
if err != nil {
return err
}

err = viper.ReadInConfig()
err = serverConfig.Unmarshal(&Conf)
if err != nil {
return err
}

err = viper.Unmarshal(&Conf)
err = mysqlConfig.Unmarshal(&Conf)
if err != nil {
return err
}
err = Conf.AesDecode()
return
}

Expand Down Expand Up @@ -72,12 +82,3 @@ type MysqlConfig struct {
MaxIdleConn int `mapstructure:"maxIdleConn"`
MaxOpenConn int `mapstructure:"maxOpenConn"`
}

func (c *Config) AesDecode() error {
mysqlPass, err := crypt.Decrypt(c.Mysql.Password)
if err != nil {
return err
}
c.Mysql.Password = mysqlPass
return nil
}
17 changes: 1 addition & 16 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,17 @@ package main

import (
"flag"
"fmt"
"os"

"github.com/cubefs/cubefs-dashboard/backend/config"
"github.com/cubefs/cubefs-dashboard/backend/helper"
"github.com/cubefs/cubefs-dashboard/backend/model/migrate"
"github.com/cubefs/cubefs-dashboard/backend/model/mysql"
"github.com/cubefs/cubefs-dashboard/backend/router"
"github.com/cubefs/cubefs-dashboard/backend/helper/crypt"
)

var confPath = flag.String("c", "", "please input your conf file path")
var enc = flag.String("e", "", "please input your encrypted string")
var confPath = flag.String("c", "", "please input your configuration directory")

func main() {
flag.Parse()
if *enc != "" {
str, err := crypt.Encrypt([]byte(*enc))
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(str)
os.Exit(0)
}

helper.Must(config.Init(*confPath))
helper.Must(mysql.Init())
helper.Must(migrate.Init())
Expand Down
2 changes: 1 addition & 1 deletion backend/model/op_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (o *OpType) Find(record *bool) ([]OpType, error) {
return optypes, err
}

func (o *OpType) FindByUniqKey(uri, method string) (*OpType, error) {
func (o *OpType) FindByUniqKey(uri, method string) (*OpType, error) {
if uri == "" || method == "" {
return nil, errors.New("uri and method are required")
}
Expand Down
71 changes: 38 additions & 33 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh
BIN_PATH=bin
FRONT_PATH=frontend
BACK_PATH=backend
Expand All @@ -9,38 +9,43 @@ BranchName=`git rev-parse --abbrev-ref HEAD 2>/dev/null`
CommitID=`git rev-parse HEAD 2>/dev/null`
BuildTime=`date +%Y-%m-%d\ %H:%M`

#SrcPath=${RootPath}/console
TargetFile=${1:-$RootPath/bin/cfs-gui}
TargetDic=$(dirname $TargetFile)
mkdir -p $TargetDic
if [ "${1}" = "--backend" ];
then
#SrcPath=${RootPath}/console
TargetFile=${2:-$RootPath/bin/cfs-gui}
TargetDic=$(dirname $TargetFile)
mkdir -p $TargetDic

LDFlags="-X github.com/cubefs/cubefs/proto.Version=${Version} \
-X github.com/cubefs/cubefs/proto.CommitID=${CommitID} \
-X github.com/cubefs/cubefs/proto.BranchName=${BranchName} \
-X 'github.com/cubefs/cubefs/proto.BuildTime=${BuildTime}' "
cd $BACK_PATH
go build \
-ldflags "${LDFlags}" \
-o $TargetFile \
*.go
if [[ $? -ne 0 ]];then
echo "go build error"
exit 13
LDFlags="-X github.com/cubefs/cubefs/proto.Version=${Version} \
-X github.com/cubefs/cubefs/proto.CommitID=${CommitID} \
-X github.com/cubefs/cubefs/proto.BranchName=${BranchName} \
-X 'github.com/cubefs/cubefs/proto.BuildTime=${BuildTime}' "
cd $BACK_PATH
go build \
-ldflags "${LDFlags}" \
-o $TargetFile \
*.go
if [[ $? -ne 0 ]];
then
echo "go build error"
exit 13
fi
fi
cd -
cp -rf ./$BACK_PATH/conf/config.yml $TargetDic/config.yml

#compile frontend
cd $FRONT_PATH
npm install
if [[ $? -ne 0 ]];then
echo "npm install error"
exit 11
fi
npm run build
if [[ $? -ne 0 ]];then
echo "npm run build error"
exit 12
fi
cd -
cp -rf ./$FRONT_PATH/dist $TargetDic/dist
if [ "${1}" = "--frontend" ];
then
#compile frontend
cd $FRONT_PATH
npm install
if [[ $? -ne 0 ]];then
echo "npm install error"
exit 11
fi
npm run build
if [[ $? -ne 0 ]];then
echo "npm run build error"
exit 12
fi
cd -
cp -rf ./$FRONT_PATH/dist $TargetDic/dist
fi
4 changes: 4 additions & 0 deletions deploy/chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
name: cubefs-dashboard
description: CubeFS Dashboard Helm Chart
version: 0.0.1
15 changes: 15 additions & 0 deletions deploy/chart/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: cubefs-dashboard-config
data:
config.yaml: |
server:
port: 6007
mode: dev
static_resource:
enable: true
relative_path: /portal
root_path: ./dist
prefix:
api: /api/cubefs
58 changes: 58 additions & 0 deletions deploy/chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: cubefs-dashboard
name: cubefs-dashboard
spec:
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: cubefs-dashboard
template:
metadata:
labels:
app: cubefs-dashboard
spec:
imagePullSecrets:
- name: {{.Values.image.pullSecret}}
containers:
- image: "{{.Values.image.registry}}/{{.Values.image.repository}}:{{.Values.image.tag}}"
imagePullPolicy: Always
name: dashboard
resources: {{- toYaml .Values.resources | indent 10 }}
volumeMounts:
- mountPath: /src/config
name: dashboard-config
- env:
- name: MARIADB_PASSWORD
value: {{ .Values.mariadb.auth.password}}
- name: MARIADB_DATABASE
value: {{ .Values.mariadb.auth.database}}
- name: MARIADB_USER
value: {{ .Values.mariadb.auth.username}}
- name: MARIADB_RANDOM_ROOT_PASSWORD
value: "True"
image: {{.Values.mariadb.image}}
imagePullPolicy: IfNotPresent
name: mariadb
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/lib/mysql
name: db
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
volumes:
- name: db
persistentVolumeClaim:
claimName: cubefs-dashboard
- name: dashboard-config
projected:
sources:
- secret:
name: cubefs-dashboard-mysql
- configMap:
name: cubefs-dashboard-config
Loading