<commit_before>package dockerManager

import (
	"bytes"
	"log"

	docker "github.com/fsouza/go-dockerclient"
)

var client *docker.Client

func initClient() {
	// TODO: This requires that users haev pre-configured the environement to swarm manager
	if c, err := docker.NewClientFromEnv(); err != nil {
		log.Fatal("failed to get docker client: ", err)
	} else {
		client = c
	}
}

func RunImg(img string, args []string) (stdout string, stderr string, err error) {
	var (
		outBuf bytes.Buffer
		errBuf bytes.Buffer
	)
	if client == nil {
		initClient()
	} else {
		// Ensure we are actually connected...
		if _, err := client.Info(); err != nil {
			log.Println("failed to get info: %v", err)
		} else {
			// Create a new container, with correct args
			container, err := client.CreateContainer(docker.CreateContainerOptions{
				Config: &docker.Config{
					Cmd:          args,
					AttachStdout: true,
					AttachStderr: true,
					Image:        img,
				},
				HostConfig: &docker.HostConfig{},
			})
			// TODO: This case should attempt to pull container
			if err != nil {
				log.Println("failed to create container", err)
				return "", "", err
			}

			// Then run it
			err = client.StartContainer(container.ID, container.HostConfig)
			if err != nil {
				log.Println("failed to start container")
				return "", "", err
			}

			// Wait for container to finish
			code, err := client.WaitContainer(container.ID)
			if err != nil {
				log.Println("wait failed: ", code, err)
				return "", "", err
			}

			// Fill buffers with logs
			err = client.AttachToContainer(docker.AttachToContainerOptions{
				Container:    container.ID,
				OutputStream: &outBuf,
				ErrorStream:  &errBuf,
				Logs:         true,
				Stdout:       true,
				Stderr:       true,
			})
			if err != nil {
				log.Fatal("failed to attach to container\n", err)
			}

			// remove container
			err = client.RemoveContainer(docker.RemoveContainerOptions{
				ID: container.ID,
			})
			if err != nil {
				log.Println("failed to rm container")
				return "", "", nil
			}
		}
	}

	return outBuf.String(), errBuf.String(), nil
}<commit_msg>remove unnecesary docker info call<commit_after>package dockerManager

import (
	"bytes"
	"log"

	docker "github.com/fsouza/go-dockerclient"
)

var client *docker.Client

func initClient() {
	// TODO: This requires that users haev pre-configured the environement to swarm manager
	if c, err := docker.NewClientFromEnv(); err != nil {
		log.Fatal("failed to get docker client: ", err)
	} else {
		client = c
	}
}

func RunImg(img string, args []string) (stdout string, stderr string, err error) {
	var (
		outBuf bytes.Buffer
		errBuf bytes.Buffer
	)

	if client == nil {
		initClient()
	}

	// Create a new container, with correct args
	container, err := client.CreateContainer(docker.CreateContainerOptions{
		Config: &docker.Config{
			Cmd:          args,
			AttachStdout: true,
			AttachStderr: true,
			Image:        img,
		},
		HostConfig: &docker.HostConfig{},
	})
	// TODO: This case should attempt to pull container
	if err != nil {
		log.Println("failed to create container", err)
		return "", "", err
	}

	// Then run it
	err = client.StartContainer(container.ID, container.HostConfig)
	if err != nil {
		log.Println("failed to start container")
		return "", "", err
	}

	// Wait for container to finish
	code, err := client.WaitContainer(container.ID)
	if err != nil {
		log.Println("wait failed: ", code, err)
		return "", "", err
	}

	// Fill buffers with logs
	err = client.AttachToContainer(docker.AttachToContainerOptions{
		Container:    container.ID,
		OutputStream: &outBuf,
		ErrorStream:  &errBuf,
		Logs:         true,
		Stdout:       true,
		Stderr:       true,
	})
	if err != nil {
		log.Fatal("failed to attach to container\n", err)
	}

	// remove container
	err = client.RemoveContainer(docker.RemoveContainerOptions{
		ID: container.ID,
	})
	if err != nil {
		log.Println("failed to rm container")
		return "", "", nil
	}

	return outBuf.String(), errBuf.String(), nil
}
{'fraction_non_alphanumeric': 0.12587064676616916, 'fraction_numerical': 0.0, 'mean_word_length': 3.004980079681275, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1877359', 'n_tokens_mistral': 1476, 'n_tokens_neox': 1270, 'n_words': 376}