mirror of
https://github.com/slimtoolkit/slim.git
synced 2025-06-03 04:00:23 +00:00
76 lines
2.0 KiB
Go
76 lines
2.0 KiB
Go
package server
|
|
|
|
import (
|
|
"github.com/slimtoolkit/slim/pkg/app"
|
|
"github.com/slimtoolkit/slim/pkg/app/master/commands"
|
|
"github.com/slimtoolkit/slim/pkg/app/master/version"
|
|
"github.com/slimtoolkit/slim/pkg/command"
|
|
"github.com/slimtoolkit/slim/pkg/docker/dockerclient"
|
|
"github.com/slimtoolkit/slim/pkg/report"
|
|
"github.com/slimtoolkit/slim/pkg/util/errutil"
|
|
"github.com/slimtoolkit/slim/pkg/util/fsutil"
|
|
v "github.com/slimtoolkit/slim/pkg/version"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
const appName = commands.AppName
|
|
|
|
type ovars = app.OutVars
|
|
|
|
// OnCommand implements the 'server' command
|
|
func OnCommand(
|
|
xc *app.ExecutionContext,
|
|
gparams *commands.GenericParams) {
|
|
logger := log.WithFields(log.Fields{"app": appName, "cmd": Name})
|
|
|
|
viChan := version.CheckAsync(gparams.CheckVersion, gparams.InContainer, gparams.IsDSImage)
|
|
|
|
cmdReport := report.NewServerCommand(gparams.ReportLocation, gparams.InContainer)
|
|
cmdReport.State = command.StateStarted
|
|
|
|
xc.Out.State("started")
|
|
|
|
client, err := dockerclient.New(gparams.ClientConfig)
|
|
if err == dockerclient.ErrNoDockerInfo {
|
|
exitMsg := "missing Docker connection info"
|
|
if gparams.InContainer && gparams.IsDSImage {
|
|
exitMsg = "make sure to pass the Docker connect parameters to the slim app container"
|
|
}
|
|
|
|
xc.Out.Info("docker.connect.error",
|
|
ovars{
|
|
"message": exitMsg,
|
|
})
|
|
|
|
exitCode := commands.ECTCommon | commands.ECCNoDockerConnectInfo
|
|
xc.Out.State("exited",
|
|
ovars{
|
|
"exit.code": exitCode,
|
|
"version": v.Current(),
|
|
"location": fsutil.ExeDir(),
|
|
})
|
|
xc.Exit(exitCode)
|
|
}
|
|
errutil.FailOn(err)
|
|
|
|
if gparams.Debug {
|
|
version.Print(xc, Name, logger, client, false, gparams.InContainer, gparams.IsDSImage)
|
|
}
|
|
|
|
xc.Out.State("completed")
|
|
cmdReport.State = command.StateCompleted
|
|
xc.Out.State("done")
|
|
|
|
vinfo := <-viChan
|
|
version.PrintCheckVersion(xc, "", vinfo)
|
|
|
|
cmdReport.State = command.StateDone
|
|
if cmdReport.Save() {
|
|
xc.Out.Info("report",
|
|
ovars{
|
|
"file": cmdReport.ReportLocation(),
|
|
})
|
|
}
|
|
}
|