Exemple #1
0
// PrepareDockerImage to set up the docker image.
func (buildManager *Manager) PrepareDockerImage(githubClient *github.Client, event *github.Event, buildSpec *Spec, buildRegister *Register) (*docker.Manager, string, error) {
	dockerSHA, err := githubClient.GetFileSHA(event.Organization, event.Repository, buildSpec.Docker.File, event.SHA)
	if err != nil {
		return nil, dockerSHA, err
	}
	log.Printf("Dockerfile '%s' with SHA '%s'", buildSpec.Docker.File, dockerSHA)

	dockerManager := buildManager.DockerManagers.Get()
	if !dockerManager.ExistsImage(event.Organization, event.Repository, dockerSHA) {
		dir, err := githubClient.DownloadProjectContent(event.Organization, event.Repository, event.SHA)
		if err != nil || dir == "" {
			log.Println("Error downloading the project")
			return nil, dockerSHA, err
		}
		defer os.RemoveAll(dir)

		dockerfileDir := filepath.Dir(filepath.Join(dir, buildSpec.Docker.File))
		log.Printf("Directory to build the docker image: %s", dockerfileDir)
		err = dockerManager.BuildImage(event.Organization, event.Repository, dockerSHA, dockerfileDir, buildRegister.BuildLogWriter)
		if err != nil {
			log.Println("Error building docker image", err)
			return nil, dockerSHA, err
		}
		log.Println("Dockerfile built successfully")
	} else {
		log.Println("Image already existed")
	}
	return dockerManager, dockerSHA, nil
}
Exemple #2
0
// GetSpec to retrieve .gocilla.yml from GitHub repository
func (buildManager *Manager) GetSpec(githubClient *github.Client, event *github.Event) (*Spec, error) {
	content, err := githubClient.GetFileContent(event.Organization, event.Repository, ".gocilla.yml", event.SHA)
	if err != nil {
		return nil, err
	}
	log.Printf("Spec for SHA %s: %s", event.SHA, content)
	var buildSpec Spec
	err = yaml.Unmarshal(content, &buildSpec)
	return &buildSpec, err
}