Ejemplo n.º 1
0
/*
	Start a container with specified port mapping(s)
*/
func Start(service string, image string, ports []PortMapping) {
	var portMappings = ""
	if len(ports) > 0 {
		portSlice := make([]string, len(ports))
		for idx, port := range ports {
			portSlice[idx] = fmt.Sprintf("-p %s:%s", strconv.FormatInt(port.External, 10), strconv.FormatInt(port.Internal, 10))
		}
		portMappings = strings.Join(portSlice, " ")
	}

	cmdStr := ""
	switch service {
	case "postgresql":
		cmdStr = fmt.Sprintf("docker run -d %s %s", portMappings, image)
	default:
		cmdStr = fmt.Sprintf("docker run -d %s %s workstation", portMappings, image)
	}

	fmt.Printf("%s\n", cmdStr)

	systemCmd := exec.Command("/bin/sh", "-c", cmdStr)
	systemCmd.Stdout = os.Stdout
	systemCmd.Stderr = os.Stderr
	err := systemCmd.Run()
	util.ExitIfError(err, fmt.Sprintf("Error running docker image"))
}
Ejemplo n.º 2
0
func Run() {
	errorlog, err := os.OpenFile("docker.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		util.ExitIfError(err, "Error opening file")
	}

	logger = log.New(errorlog, "docker.log: ", log.Lshortfile|log.LstdFlags)
}
Ejemplo n.º 3
0
func Push(tagName string, tagVersion string) {
	cmdStr := fmt.Sprintf("docker push %s:%s", tagName, tagVersion)
	fmt.Printf("%s\n", cmdStr)

	systemCmd := exec.Command("/bin/sh", "-c", cmdStr)
	systemCmd.Stdout = os.Stdout
	systemCmd.Stderr = os.Stderr
	err := systemCmd.Run()

	util.ExitIfError(err, fmt.Sprintf("Error pushing docker image"))
}
Ejemplo n.º 4
0
func Build(tagName string, tagVersion string, dockerFile string) {
	cmdStr := fmt.Sprintf("docker build -t %s:%s -f %s .", tagName, tagVersion, dockerFile)
	fmt.Printf("%s\n", cmdStr)

	systemCmd := exec.Command("/bin/sh", "-c", cmdStr)
	systemCmd.Stdout = os.Stdout
	systemCmd.Stderr = os.Stderr
	err := systemCmd.Run()

	util.ExitIfError(err, fmt.Sprintf("Error building docker image"))
}
Ejemplo n.º 5
0
/*
	Http (i.e. Play/Node) applications will use 'curl' to verify application health status
*/
func (httpReq HttpHealthCheck) check() bool {
	response, err := http.Get(httpReq.url())

	if err != nil {
		return false
	} else {
		switch response.StatusCode {
		case 200:
			defer response.Body.Close()
			contents, err := ioutil.ReadAll(response.Body)
			util.ExitIfError(err, fmt.Sprintf("Error reading HTTP response: %v", err))

			if strings.Contains(string(contents), "healthy") {
				return true
			} else {
				return false
			}
		default:
			return false
		}
	}
}
Ejemplo n.º 6
0
func Run() {
	errorlog, err := os.OpenFile("healthchecks.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	util.ExitIfError(err, fmt.Sprintf("Error opening file: %v", err))

	logger = log.New(errorlog, "healthchecks.log: ", log.Lshortfile|log.LstdFlags)
}