本文整理汇总了Golang中github.com/marmelab/gaudi/util.LogError函数的典型用法代码示例。如果您正苦于以下问题:Golang LogError函数的具体用法?Golang LogError怎么用?Golang LogError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LogError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: copyRelativeFiles
func (g *Gaudi) copyRelativeFiles(filePath, destination string) bool {
// File cannot be absolute
if util.IsFile(filePath) && filePath[0] == '/' {
util.LogError("File '" + filePath + "' cannot be an absolute path")
}
// Check if the relative file exists
absolutePath := g.ApplicationDir + "/" + filePath
if util.IsFile(absolutePath) {
// Move file to the build context (and keep the same file tree)
directories := strings.Split(filePath, "/")
if len(directories) > 1 {
os.MkdirAll(destination+strings.Join(directories[0:len(directories)-1], "/"), 0755)
}
err := util.Copy(destination+filePath, absolutePath)
if err != nil {
util.LogError(err)
}
return true
}
return false
}
示例2: parseTemplate
func (gaudi *Gaudi) parseTemplate(sourceDir, destinationDir string, file os.FileInfo, includes map[string]string, currentContainer *container.Container) {
emptyCmd := shouldEmptyCmdForContainer(currentContainer.Name)
templateData := TemplateData{gaudi.All, nil, emptyCmd}
funcMap := template.FuncMap{
"ToUpper": strings.ToUpper,
"ToLower": strings.ToLower,
}
// Create destination directory if needed
destination := destinationDir + currentContainer.Name + "/" + file.Name()
if file.IsDir() {
err := os.MkdirAll(destination, 0755)
if err != nil {
util.LogError(err)
}
return
}
// Read the template
filePath := sourceDir + "/" + file.Name()
rawContent, err := ioutil.ReadFile(filePath)
if err != nil {
util.LogError(err)
}
content := string(rawContent)
// Add includes
for name, include := range includes {
content = strings.Replace(content, "[[ "+name+" ]]", include, -1)
}
// Parse it
// We need to change default delimiters because sometimes we have to parse values like ${{{ .Val }}} which cause an error
tmpl, templErr := template.New(filePath).Funcs(funcMap).Delims("[[", "]]").Parse(content)
if templErr != nil {
util.LogError(templErr)
}
templateData.Container = currentContainer
var result bytes.Buffer
err = tmpl.Execute(&result, templateData)
if err != nil {
util.LogError(err)
}
// Create the destination file
ioutil.WriteFile(destination, []byte(result.String()), 0644)
}
示例3: Run
/**
* Start a container as binary
*/
func Run(name, currentPath string, arguments []string, ports, environments map[string]string) {
runFunc := reflect.ValueOf(exec.Command)
rawArgs := []string{getDockerBinaryPath(), "run", "-v=" + currentPath + ":" + currentPath, "-w=" + currentPath}
// Add environments
util.Debug(environments)
for envName, envValue := range environments {
rawArgs = append(rawArgs, "-e="+envName+"="+envValue)
}
// Add ports
for portIn, portOut := range ports {
rawArgs = append(rawArgs, "-p="+string(portIn)+":"+string(portOut))
}
rawArgs = append(rawArgs, name)
// Add user arguments
for _, argument := range arguments {
rawArgs = append(rawArgs, argument)
}
runCmd := runFunc.Call(util.BuildReflectArguments(rawArgs))[0].Interface().(*exec.Cmd)
runCmd.Stdout = os.Stdout
runCmd.Stdin = os.Stdin
runCmd.Stderr = os.Stderr
util.Debug("Run command:", runCmd.Args)
if err := runCmd.Start(); err != nil {
util.LogError(err)
}
}
示例4: Build
func Build(name, path string) {
buildFunc := reflect.ValueOf(exec.Command)
rawArgs := []string{getDockerBinaryPath(), "build"}
if *noCache {
rawArgs = append(rawArgs, "--no-cache")
}
rawArgs = append(rawArgs, "-t", name, path)
util.Debug(rawArgs)
buildCmd := buildFunc.Call(util.BuildReflectArguments(rawArgs))[0].Interface().(*exec.Cmd)
buildCmd.Stdin = os.Stdin
out, err := buildCmd.CombinedOutput()
if err != nil {
util.Print(string(out))
util.LogError("Error while starting container '" + name + "'")
}
buildCmd.Wait()
time.Sleep(1 * time.Second)
}
示例5: Build
func Build(name, path string) {
buildFunc := reflect.ValueOf(exec.Command)
rawArgs := []string{getDockerBinaryPath(), "build"}
if *noCache {
rawArgs = append(rawArgs, "--no-cache")
}
rawArgs = append(rawArgs, "-t", name, path)
util.Debug(rawArgs)
buildCmd := buildFunc.Call(util.BuildReflectArguments(rawArgs))[0].Interface().(*exec.Cmd)
buildCmd.Stderr = os.Stderr
if !*quiet {
buildCmd.Stdout = os.Stdout
}
if err := buildCmd.Run(); err != nil {
util.LogError(err)
}
buildCmd.Wait()
time.Sleep(1 * time.Second)
}
示例6: Start
/**
* Start a container as a server
*/
func Start(name, image string, links []string, ports, volumes, environments map[string]string) string {
runFunc := reflect.ValueOf(exec.Command)
rawArgs := []string{getDockerBinaryPath(), "run", "-d", "-i", "-t", "--privileged", "--name=" + name}
// Add environments
util.Debug(environments)
for envName, envValue := range environments {
rawArgs = append(rawArgs, "-e="+envName+"="+envValue)
}
// Add links
for _, link := range links {
rawArgs = append(rawArgs, "--link="+link+":"+link)
}
// Add ports
for portIn, portOut := range ports {
rawArgs = append(rawArgs, "-p="+string(portIn)+":"+string(portOut))
}
// Add volumes
for volumeHost, volumeContainer := range volumes {
rawArgs = append(rawArgs, "-v="+volumeHost+":"+volumeContainer)
}
rawArgs = append(rawArgs, image)
// Initiate the command with several arguments
runCmd := runFunc.Call(util.BuildReflectArguments(rawArgs))[0].Interface().(*exec.Cmd)
util.Debug("Start command:", runCmd.Args)
out, err := runCmd.CombinedOutput()
if err != nil {
util.LogError(string(out))
}
// Inspect container to check status code
exitCodeBuff, _ := Inspect(name, "--format", "{{.State.ExitCode}}")
exitCode, _ := strconv.Atoi(strings.TrimSpace(string(exitCodeBuff)))
if exitCode != 0 {
error, _ := Logs(name)
util.LogError("Error while starting container '" + name + "' : " + error)
}
return string(out)
}
示例7: RetrieveIp
func (c *Container) RetrieveIp() {
inspect, err := docker.Inspect(c.Id)
if err != nil {
util.LogError(err)
}
c.retrieveInfoFromInspection(inspect)
}
示例8: Init
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()
}
示例9: Remove
func Remove(name string) {
removeCmd := exec.Command(getDockerBinaryPath(), "rm", name)
removeErr := removeCmd.Start()
if removeErr != nil {
util.LogError(removeErr)
}
time.Sleep(1 * time.Second)
}
示例10: Kill
func Kill(name string) {
killCommand := exec.Command(getDockerBinaryPath(), "kill", name)
killErr := killCommand.Start()
if killErr != nil {
util.LogError(killErr)
}
time.Sleep(1 * time.Second)
}
示例11: Init
func (collection ContainerCollection) Init(relativePath string) bool {
hasGaudiManagedContainer := false
// Fill name & dependencies
for name, currentContainer := range collection {
currentContainer.Name = name
currentContainer.Init()
if currentContainer.IsGaudiManaged() {
hasGaudiManagedContainer = true
currentContainer.Image = "gaudi/" + name
}
for _, dependency := range currentContainer.Links {
if depContainer, exists := collection[dependency]; exists {
currentContainer.AddDependency(depContainer)
} else {
util.LogError(name + " references a non existing application : " + dependency)
}
}
// Add relative path to volumes
for volumeHost, volumeContainer := range currentContainer.Volumes {
// Relative volume host
if string(volumeHost[0]) != "/" {
delete(currentContainer.Volumes, volumeHost)
volumeHost = relativePath + "/" + volumeHost
currentContainer.Volumes[volumeHost] = volumeContainer
}
// Create directory if needed
if !util.IsDir(volumeHost) {
err := os.MkdirAll(volumeHost, 0755)
if err != nil {
util.LogError(err)
}
}
}
}
return hasGaudiManagedContainer
}
示例12: retrieveConfigPath
func retrieveConfigPath(configFile string) string {
if len(configFile) == 0 {
util.LogError("Config file name cannot be empty.")
}
if string(configFile[0]) != "/" {
currentDir, err := os.Getwd()
if err != nil {
util.LogError(err)
}
configFile = currentDir + "/" + configFile
}
if !util.IsFile(configFile) {
util.LogError("Configuration file not found: '" + configFile + "'. Use --config to specify a custom file")
}
return configFile
}
示例13: InitFromFile
func (gaudi *Gaudi) InitFromFile(file string) {
gaudi.ConfigurationPath = file
gaudi.ApplicationDir = path.Dir(file)
fileContent, err := ioutil.ReadFile(file)
if err != nil {
util.LogError(err)
}
gaudi.Init(string(fileContent))
}
示例14: retrieveTemplates
func retrieveTemplates() {
os.MkdirAll(TEMPLATE_DIR, 0755)
archive, err := os.Create(TEMPLATE_DIR + "templates.tar")
if err != nil {
util.LogError(err)
}
defer archive.Close()
content, err := http.Get(TEMPLATE_REMOTE_PATH)
if err != nil {
util.LogError(err)
}
defer content.Body.Close()
_, err = io.Copy(archive, content.Body)
if err != nil {
util.LogError(err)
}
}
示例15: extractTemplates
func extractTemplates() {
tarFile, _ := os.Open(TEMPLATE_DIR + "templates.tar")
defer tarFile.Close()
tar := tar.NewReader(tarFile)
for {
header, err := tar.Next()
if err == io.EOF {
break
}
if err != nil {
util.LogError(err)
}
// Remove first path part
filePath := strings.Join(strings.Split(header.Name, "/")[1:], "/")
// Check if we should create a folder or a file
if header.Size == 0 {
err := os.MkdirAll(TEMPLATE_DIR+filePath, 0755)
if err != nil {
util.LogError(err)
}
} else {
f, err := os.Create(TEMPLATE_DIR + filePath)
if err != nil {
util.LogError(err)
}
defer f.Close()
_, err = io.Copy(f, tar)
if err != nil {
util.LogError(err)
}
}
}
os.Remove(TEMPLATE_DIR + "templates.tar")
}