package merge import ( "github.com/docker-slim/docker-slim/pkg/app" "github.com/docker-slim/docker-slim/pkg/app/master/commands" "github.com/docker-slim/docker-slim/pkg/app/master/version" "github.com/docker-slim/docker-slim/pkg/command" "github.com/docker-slim/docker-slim/pkg/docker/dockerclient" "github.com/docker-slim/docker-slim/pkg/report" "github.com/docker-slim/docker-slim/pkg/util/errutil" "github.com/docker-slim/docker-slim/pkg/util/fsutil" v "github.com/docker-slim/docker-slim/pkg/version" log "github.com/sirupsen/logrus" ) const appName = commands.AppName type ovars = app.OutVars // OnCommand implements the 'merge' command func OnCommand( xc *app.ExecutionContext, gparams *commands.GenericParams, cparams *CommandParams) { const cmdName = Name logger := log.WithFields(log.Fields{"app": appName, "command": cmdName}) viChan := version.CheckAsync(gparams.CheckVersion, gparams.InContainer, gparams.IsDSImage) cmdReport := report.NewEditCommand(gparams.ReportLocation, gparams.InContainer) cmdReport.State = command.StateStarted xc.Out.State("started") xc.Out.Info("params", ovars{ "image.first": cparams.FirstImage, "image.last": cparams.LastImage, }) 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.ECNoDockerConnectInfo 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, cmdName, 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(), }) } }