func (c *Container) Clean(done chan bool) { util.PrintGreen("Cleaning", c.Name, "...") c.Kill(true, nil) c.Remove() done <- true }
func (gaudi *Gaudi) Init(content string) { err := goyaml.Unmarshal([]byte(content), &gaudi) if err != nil { util.LogError(err) } emptyCmdForContainers = strings.Split(*emptyCmdFlag, ",") // Init all containers gaudi.Applications.AddAmbassadors() gaudi.All = containerCollection.Merge(gaudi.Applications, gaudi.Binaries) if len(gaudi.All) == 0 { util.LogError("No application or binary to start. Are you missing a 'applications' or 'binaries' field in your configuration ?") } hasGaudiManagedContainer := gaudi.All.Init(gaudi.ApplicationDir) // Apply extends gaudi.applyInheritance() // Check if docker is installed if !docker.HasDocker() { util.LogError("Docker should be installed to use Gaudi (see: https://www.docker.io/gettingstarted/).") } // Check if base image is pulled if hasGaudiManagedContainer && !docker.ImageExists(DEFAULT_BASE_IMAGE) { util.PrintGreen("Pulling base image (this may take a few minutes) ...") docker.Pull(DEFAULT_BASE_IMAGE_WITH_TAG) } if gaudi.useNewVersion() { os.RemoveAll(TEMPLATE_DIR) } // Check if templates are present if !util.IsDir(TEMPLATE_DIR) { util.PrintGreen("Retrieving templates ...") retrieveTemplates() extractTemplates() } gaudi.build() }
func (c *Container) Kill(silent bool, done chan bool) { if !silent { util.PrintGreen("Killing", c.Name, "...") } docker.Kill(c.Name) c.Running = false if done != nil { done <- true } }
func (c *Container) Pull(done chan bool) { util.PrintGreen("Pulling", c.Image, "...") // prebuild type is deprecated if c.Type == "prebuild" { util.PrintRed("WARN: 'prebuild' type is deprecated, use 'index' instead") } docker.Pull(c.Image) done <- true }
/** * Starts a container as a server */ func (c *Container) Start(rebuild bool) { // Check if the container is already running if !rebuild { if c.IsRunning() { util.PrintGreen("Application", c.Name, "is already running", "("+c.Ip+":"+c.GetFirstPort()+")") return } cleanChan := make(chan bool, 1) go c.Clean(cleanChan) <-cleanChan } util.PrintGreen("Starting", c.Name, "...") startResult := docker.Start(c.Name, c.Image, c.Links, c.Ports, c.Volumes, c.Environments) c.Id = strings.TrimSpace(startResult) time.Sleep(3 * time.Second) c.RetrieveIp() c.Running = true util.PrintGreen("Application", c.Name, "started", "("+c.Ip+":"+c.GetFirstPort()+")") }
/** * Enter in a specific container */ func (gaudi *Gaudi) Enter(name string) { // Check if nsenter exists images, err := docker.GetImages() if err != nil { util.LogError(err) } if _, ok := images["jpetazzo/nsenter"]; !ok { // Pull ns-enter image util.PrintGreen("Retrieving ns-enter image ...") docker.Exec([]string{"run", "--rm", "-v", "/usr/local/bin:/target", "jpetazzo/nsenter"}, false) } container := gaudi.All[name] docker.Enter(container.GetFullName()) }
func (c *Container) Build(done chan bool) { buildName := "gaudi/" + c.Name buildPath := "/tmp/gaudi/" + c.Name if c.IsRemote() { // remote type is deprecated if c.Type == "remote" { util.PrintRed("WARN: 'remote' type is deprecated, use 'github' instead") } buildName = c.Image buildPath = c.Path } util.PrintGreen("Building", buildName, "...") docker.Build(buildName, buildPath) done <- true }
/** * Starts a container as a binary file */ func (c *Container) Run(currentPath string, arguments []string) { util.PrintGreen("Running", c.Name, strings.Join(arguments, " "), "...") docker.Run(c.Image, currentPath, arguments, c.Ports, c.Environments) }