mirror of
https://github.com/slimtoolkit/slim.git
synced 2025-06-03 04:00:23 +00:00
80 lines
2.2 KiB
Go
80 lines
2.2 KiB
Go
package registry
|
|
|
|
import (
|
|
//"github.com/google/go-containerregistry/pkg/crane"
|
|
//"github.com/google/go-containerregistry/pkg/name"
|
|
//gocrv1 "github.com/google/go-containerregistry/pkg/v1"
|
|
//"github.com/google/go-containerregistry/pkg/v1/daemon"
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"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"
|
|
)
|
|
|
|
// OnCopyCommand implements the 'registry copy' command
|
|
func OnCopyCommand(
|
|
xc *app.ExecutionContext,
|
|
gparams *commands.GenericParams) {
|
|
cmdName := fullCmdName(CopyCmdName)
|
|
logger := log.WithFields(log.Fields{
|
|
"app": appName,
|
|
"cmd": cmdName,
|
|
"sub": CopyCmdName})
|
|
|
|
viChan := version.CheckAsync(gparams.CheckVersion, gparams.InContainer, gparams.IsDSImage)
|
|
|
|
cmdReport := report.NewRegistryCommand(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 docker-slim 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, 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(),
|
|
})
|
|
}
|
|
}
|