-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2cda06a
commit e8f6da0
Showing
654 changed files
with
58,288 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/views/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.vue linguist-language=Go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
resources/vue/node_moudules | ||
/logs/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# 使用基础镜像,比如 alpine 或者 debian,alpine 体积较小 | ||
FROM alpine:latest | ||
|
||
VOLUME /app/config | ||
VOLUME /app/data | ||
VOLUME /app/logs | ||
VOLUME /app/plugins | ||
VOLUME /app/plugin_store | ||
VOLUME /app/plugin_logs | ||
VOLUME /app/store_file_dir | ||
|
||
# 设置工作目录 | ||
WORKDIR /app | ||
|
||
# 将本地的二进制文件和配置文件复制到容器中 | ||
COPY ev_linux_amd64 /app/ | ||
COPY config /app/config/ | ||
|
||
# 确保二进制文件有可执行权限 | ||
RUN chmod +x /app/ev_linux_amd64 | ||
|
||
EXPOSE 8090 | ||
|
||
# 定义容器启动时执行的命令 | ||
CMD ["./ev_linux_amd64", "-configFile=config/config.yml"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"flag" | ||
"fmt" | ||
"github.com/1340691923/ElasticView/pkg/infrastructure/config" | ||
"github.com/1340691923/ElasticView/pkg/util" | ||
"github.com/pkg/errors" | ||
_ "net/http/pprof" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
var args *config.CommandLineArgs | ||
|
||
func init() { | ||
args = &config.CommandLineArgs{} | ||
flag.StringVar(&args.HomePath, "homePath", util.GetCurrentDirectory(), "ev程序所在文件夹") | ||
flag.StringVar(&args.CmdName, "cmdName", "build", "二进制名称") | ||
flag.StringVar(&args.ConfigFile, "configFile", "config/config.yml", "配置文件路径") | ||
flag.Parse() | ||
} | ||
|
||
func main() { | ||
cfg, err := config.InitConfig(args) | ||
if err != nil { | ||
fmt.Println("InitConfig err", err) | ||
panic(err) | ||
} | ||
|
||
err = BuildVue(cfg) | ||
if err != nil { | ||
fmt.Println("BuildVue err", err) | ||
panic(err) | ||
} | ||
|
||
outputZipPath := fmt.Sprintf("resources/dist/ev_%s", strings.ReplaceAll(cfg.Version, ".", "_")) | ||
|
||
err = util.WriteVersionGoFile(fmt.Sprintf(`package config | ||
const Version = "v%s" | ||
`, cfg.Version)) | ||
|
||
if err != nil { | ||
fmt.Println("BuildVue err", err) | ||
panic(err) | ||
} | ||
|
||
fmt.Println("开始检测是否已有该版本打包", cfg.Version) | ||
if util.CheckFileIsExist(outputZipPath) { | ||
fmt.Println("检测到已经该版本打包,正在删除老包", cfg.Version) | ||
os.RemoveAll(outputZipPath) | ||
} else { | ||
fmt.Println("暂无该版本打包") | ||
} | ||
|
||
for _, osAndArch := range []string{ | ||
"linux_arm64", | ||
"linux_amd64", | ||
"darwin_amd64", | ||
"windows_amd64", | ||
} { | ||
osAndArchArr := strings.Split(osAndArch, "_") | ||
os := osAndArchArr[0] | ||
arch := osAndArchArr[1] | ||
err = BuildEvSvr(cfg, os, arch) | ||
if err != nil { | ||
fmt.Println("BuildEvSvr err", err) | ||
panic(err) | ||
} | ||
} | ||
|
||
fmt.Println("BuildEvSvr success") | ||
} | ||
|
||
type BuildConfig struct { | ||
OS string // GOOS | ||
GOARCH string | ||
Env map[string]string | ||
OutputPath string | ||
} | ||
|
||
func getExecutableName(os, arch string) (string, error) { | ||
exname := "ev" | ||
|
||
exeName := fmt.Sprintf("%s_%s_%s", exname, os, arch) | ||
if os == "windows" { | ||
exeName = fmt.Sprintf("%s.exe", exeName) | ||
} | ||
return exeName, nil | ||
} | ||
|
||
func buildBackend(cfg BuildConfig) error { | ||
|
||
exeName, err := getExecutableName(cfg.OS, cfg.GOARCH) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
//-H windowsgui | ||
ldFlags := fmt.Sprintf("-w -s%s%s ", " ", `-extldflags "-static"`) | ||
|
||
/*if cfg.OS == "windows" { | ||
ldFlags = fmt.Sprintf("-w -s%s%s -H windowsgui", " ", `-extldflags "-static"`) | ||
}*/ | ||
|
||
outputPath := cfg.OutputPath | ||
|
||
args := []string{ | ||
"build", "-o", filepath.Join(outputPath, exeName), | ||
} | ||
|
||
args = append(args, "-ldflags", ldFlags) | ||
|
||
rootPackage := "./cmd/ev" | ||
|
||
args = append(args, rootPackage) | ||
|
||
cfg.Env["GOOS"] = cfg.OS | ||
cfg.Env["CGO_ENABLED"] = "0" | ||
cfg.Env["GOARCH"] = cfg.GOARCH | ||
return RunGoBuild(cfg.Env, args...) | ||
} | ||
|
||
func newBuildConfig(os, arch, outputPath string) BuildConfig { | ||
return BuildConfig{ | ||
OS: os, | ||
GOARCH: arch, | ||
OutputPath: outputPath, | ||
Env: map[string]string{}, | ||
} | ||
} | ||
|
||
func BuildVue(cfg *config.Config) (err error) { | ||
cmd := exec.Command("npm", "run", "build") | ||
cmd.Dir = "resources/vue" | ||
|
||
stdout, err := cmd.StdoutPipe() | ||
if err != nil { | ||
return errors.WithStack(err) | ||
} | ||
if err = cmd.Start(); err != nil { | ||
return errors.WithStack(err) | ||
} | ||
scanner := bufio.NewScanner(stdout) | ||
fmt.Println("=================build vue================") | ||
|
||
for scanner.Scan() { | ||
fmt.Println(scanner.Text()) | ||
} | ||
if err = cmd.Wait(); err != nil { | ||
return errors.WithStack(err) | ||
} | ||
|
||
return | ||
} | ||
|
||
func BuildEvSvr(cfg *config.Config, buildOs, buildArch string) (err error) { | ||
|
||
fmt.Println("开始编译ev二进制文件,版本:", cfg.Version, buildOs, buildArch) | ||
|
||
outputPath := fmt.Sprintf("resources/dist/ev_%s_%s_%s", cfg.Version, buildOs, buildArch) | ||
|
||
err = buildBackend(newBuildConfig(buildOs, buildArch, outputPath)) | ||
if err != nil { | ||
return | ||
} | ||
|
||
os.MkdirAll(filepath.Join(outputPath, "config"), os.ModePerm) | ||
err = util.DirCopy("config", filepath.Join(outputPath, "config")) | ||
if err != nil { | ||
return | ||
} | ||
|
||
versionString := strings.ReplaceAll(cfg.Version, ".", "_") | ||
|
||
outputZipPath := fmt.Sprintf("resources/dist/ev_%s", versionString) | ||
|
||
fmt.Println("开始打包", cfg.Version, buildOs, buildArch) | ||
|
||
os.MkdirAll(outputZipPath, os.ModePerm) | ||
|
||
outputZip := filepath.Join(outputZipPath, fmt.Sprintf("ev_%s_%s_%s.zip", versionString, buildOs, buildArch)) | ||
|
||
err = util.CompressPathToZip(outputPath, outputZip) | ||
if err != nil { | ||
return | ||
} | ||
fmt.Println("打包成功,开始清理临时文件", cfg.Version, buildOs, buildArch) | ||
os.RemoveAll(outputPath) | ||
fmt.Println("清理临时文件完毕") | ||
|
||
return | ||
} | ||
|
||
func RunGoBuild(env map[string]string, args ...string) (err error) { | ||
if len(env) > 0 { | ||
envArr := []string{"env", "-w"} | ||
for k, v := range env { | ||
envArr = append(envArr, fmt.Sprintf("%s=%s", k, v)) | ||
} | ||
|
||
fmt.Println(fmt.Sprintf("start build cmd: go %v", envArr)) | ||
|
||
cmd := exec.Command("go", envArr...) | ||
|
||
err = cmd.Run() | ||
if err != nil { | ||
return | ||
} | ||
} | ||
|
||
fmt.Println(fmt.Sprintf("start build cmd: go %v", args)) | ||
cmd := exec.Command("go", args...) | ||
err = cmd.Run() | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
_ "embed" | ||
"flag" | ||
"fmt" | ||
"github.com/1340691923/ElasticView/pkg/infrastructure/config" | ||
"github.com/1340691923/ElasticView/pkg/server" | ||
"github.com/1340691923/ElasticView/pkg/util" | ||
"log" | ||
_ "net/http/pprof" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
) | ||
|
||
var args *config.CommandLineArgs | ||
|
||
func init() { | ||
args = &config.CommandLineArgs{} | ||
flag.StringVar(&args.HomePath, "homePath", util.GetCurrentDirectory(), "ev程序所在文件夹") | ||
flag.StringVar(&args.CmdName, "cmdName", "ev", "二进制名称") | ||
flag.StringVar(&args.ConfigFile, "configFile", "config/config.yml", "配置文件路径") | ||
flag.StringVar(&args.AdminPwd, "adminPwd", "", "需要重置的管理员密码") | ||
flag.Parse() | ||
} | ||
|
||
// @title ElasticView | ||
// @description 励志成为陪伴你一生的elasticsearch可视化客户端 | ||
|
||
// @contact.name 肖文龙 | ||
// @contact.url http://www.elastic-view.cn/suporrt.html | ||
// @contact.email 1340691923@qq.com | ||
|
||
// @license.name Apache 2.0 | ||
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html | ||
func main() { | ||
|
||
svr, err := server.Initialize(args) | ||
if err != nil { | ||
log.Println(fmt.Sprintf("初始化ev失败:%+v", err)) | ||
panic(err) | ||
} | ||
if args.AdminPwd != "" { | ||
err = svr.ResetAdminPwd(args.AdminPwd) | ||
if err != nil { | ||
log.Println(fmt.Sprintf("初始化管理员密码失败:%+v", err)) | ||
panic(err) | ||
} | ||
log.Println(fmt.Sprintf("初始化管理员密码成功")) | ||
return | ||
} | ||
|
||
err = svr.RunMigrator() | ||
if err != nil { | ||
log.Println(fmt.Sprintf("初始化ev失败:%+v", err)) | ||
panic(err) | ||
} | ||
svr.InitSwagger() | ||
err = svr.Init() | ||
if err != nil { | ||
log.Println(fmt.Sprintf("初始化ev失败:%+v", err)) | ||
panic(err) | ||
} | ||
|
||
go listenToSystemSignals(context.Background(), svr) | ||
|
||
if err = svr.Run(func(svr *server.Server) error { | ||
log.Println("服务退出成功") | ||
return nil | ||
}, func(svr *server.Server) error { | ||
return svr.CloseLog() | ||
}); err != nil { | ||
log.Println("启动EV失败") | ||
panic(err) | ||
} | ||
} | ||
|
||
func listenToSystemSignals(ctx context.Context, s *server.Server) { | ||
signalChan := make(chan os.Signal, 1) | ||
|
||
signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM) | ||
|
||
for { | ||
select { | ||
case <-signalChan: | ||
ctx, cancel := context.WithTimeout(ctx, 30*time.Second) | ||
defer cancel() | ||
if err := s.Shutdown(ctx); err != nil { | ||
log.Println(fmt.Sprintf("%+v", err)) | ||
fmt.Fprintf(os.Stderr, "ev服务关闭超时\n") | ||
} | ||
return | ||
} | ||
} | ||
} |
Oops, something went wrong.