Beispiel #1
0
// Execute container, wait for it to complete, collect output and send
func executeContainer(uid string, sidDetails map[string]interface{}, isLint int) (results []string, status int) {

	status = 1

	// Get language
	language := sidDetails["language"].(string)

	// Code dir
	dir := sidDetails["dir"].(string)

	// Docker cmd
	dockerCmd := "docker run -v " + "\"" + dir + ":/home/justrunit/services/myproject\"" +
		" justrunit/" + language
	if isLint == 1 {
		dockerCmd = dockerCmd + " /bin/bash -c '$LINT_CMD " + sidDetails["code_file"].(string) + "'"
	}
	if sidDetails["op"] == "install-deps" {
		dockerCmd = dockerCmd + " /bin/bash -c '" + sidDetails["install_deps"].(string) + "'"
	}

	// Docker run
	dockerRunCmd := exec.Command("bash", "-c", dockerCmd)
	dockerRunCmdOut, _ := dockerRunCmd.StdoutPipe()
	dockerRunCmdErr, _ := dockerRunCmd.StderrPipe()
	dockerRunCmd.Start()

	stdoutBytes, _ := ioutil.ReadAll(dockerRunCmdOut)
	stderrBytes, _ := ioutil.ReadAll(dockerRunCmdErr)

	str := string(stdoutBytes)
	if len(stderrBytes) > 0 {
		str = str + "\n" + string(stderrBytes)
	}

	// Check for lint errors
	if isLint == 1 {
		languageConfigs := languages.GetLanguageConfigs()
		lc := languageConfigs[language].(map[string]interface{})
		rs := lc["lint_error_regexes"].([]interface{})
		for _, regex := range rs {
			log.Println("Checking for lint error: " + regex.(string))
			match, _ := regexp.MatchString(regex.(string), str)
			if match {
				status = 0
			}
		}
		match, _ := regexp.MatchString("Cannot start container", str)
		if match {
			str = "An error occured in our execution context. Please run the operation again after a while"
			status = 0
		}
	}

	results = strings.Split(str, "\n")
	return
}
Beispiel #2
0
func getCodeFileName(language string) (codeFileStr string) {
	// Read config file for languages
	languageConfigs := languages.GetLanguageConfigs()

	// Language specific configs
	lc := languageConfigs[language].(map[string]interface{})
	codeFile := lc["code_file"]
	if codeFile == nil {
		codeFileStr = "code"
	} else {
		codeFileStr = codeFile.(string)
	}

	log.Println("File path " + codeFileStr)
	return codeFileStr
}
Beispiel #3
0
/* Set language context like dependency files/folder initializations */
func setLanguageContext(dir string, language string, depsInput interface{}) (lc map[string]interface{}) {

	// Read config file for languages
	languageConfigs := languages.GetLanguageConfigs()
	log.Println(languageConfigs)

	// Language specific configs
	lc = languageConfigs[language].(map[string]interface{})

	// Get code file path
	code := dir + getCodeFileName(language)

	// Generate deps
	deps := []byte("")
	if depsInput == nil {
		cmd := "cat " + code + " | " + lc["deps_grep"].(string) + " | " + "grep -v -P \"^\\s*$\""

		// Generate deps
		deps, _ = exec.Command("bash", "-c", cmd).Output()

		// Add any prefix
		if lc["deps_prefix"] != nil {
			lcdp := lc["deps_prefix"].([]interface{})
			prefix := ""
			for _, dp := range lcdp {
				prefix = prefix + dp.(string) + "\n"
			}
			deps = []byte(prefix + string(deps))
		}
	} else {
		str := depsInput.(string)
		deps = []byte(str)
		// log.Println(string(deps))
	}

	// Write to deps file
	ioutil.WriteFile(dir+"/"+lc["deps_file"].(string), []byte(deps), 0777)
	return
}