package apps import ( "bufio" "fmt" "github.com/crawlab-team/crawlab/core/interfaces" "github.com/crawlab-team/crawlab/core/sys_exec" "github.com/crawlab-team/crawlab/core/utils" "github.com/crawlab-team/crawlab/trace" "github.com/imroc/req" "github.com/spf13/viper" "os" "os/exec" "strings" "time" ) type Docker struct { // parent parent ServerApp // dependencies interfaces.WithConfigPath // seaweedfs log fsLogFilePath string fsLogFile *os.File fsReady bool } func (app *Docker) Init() { var err error app.fsLogFile, err = os.OpenFile(app.fsLogFilePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, os.FileMode(0777)) if err != nil { trace.PrintError(err) } // replace paths if err := app.replacePaths(); err != nil { panic(err) } // start nginx go app.startNginx() // start seaweedfs go app.startSeaweedFs() } func (app *Docker) Start() { // import demo //if utils.IsDemo() && utils.InitializedDemo() { // go app.importDemo() //} } func (app *Docker) Wait() { DefaultWait() } func (app *Docker) Stop() { } func (app *Docker) GetParent() (parent ServerApp) { return app.parent } func (app *Docker) SetParent(parent ServerApp) { app.parent = parent } func (app *Docker) Ready() (ok bool) { return app.fsReady && app.parent.GetApi().Ready() } func (app *Docker) replacePaths() (err error) { // read indexHtmlPath := "/app/dist/index.html" indexHtmlBytes, err := os.ReadFile(indexHtmlPath) if err != nil { return trace.TraceError(err) } indexHtml := string(indexHtmlBytes) // replace paths baseUrl := viper.GetString("base.url") if baseUrl != "" { indexHtml = app._replacePath(indexHtml, "js", baseUrl) indexHtml = app._replacePath(indexHtml, "css", baseUrl) indexHtml = app._replacePath(indexHtml, "