コード例 #1
0
ファイル: build.go プロジェクト: pombredanne/generator-1
func BuildDockerImageStartByHTTPReq(worker, imageName string, dockerfileTarReader io.Reader, tag string) {

	dockerClient, _ := NewDockerClient(worker, nil)

	buildImageConfig := &BuildImage{
		Context:        dockerfileTarReader,
		RepoName:       imageName,
		SuppressOutput: true,
	}

	reader, err := dockerClient.BuildImage(buildImageConfig)
	if err != nil {
		log.Println("[ErrorInfo]", err.Error())
	}

	buf := make([]byte, 4096)

	for {
		n, err := reader.Read(buf)
		if err != nil && err != io.EOF {
			panic(err)
		}

		if strings.Contains(string(buf[:n]), `"stream":"Successfully built`) {
			dockerClient.PushImage(buildImageConfig)
		}

		if 0 == n {
			err = models.PushMsgToList("buildLog:"+tag, "bye")
			if err != nil {
				log.Println("[ErrorInfo]", err.Error())
			}

			err = models.PublishMsg("buildLog:"+tag, "bye")
			if err != nil {
				log.Println("[ErrorInfo]", err.Error())
			}
			finishJob(worker)
			break
		}

		err = models.PushMsgToList("buildLog:"+tag, string(buf[:n]))
		if err != nil {
			log.Println("[ErrorInfo]", err.Error())
		}

		err = models.PublishMsg("buildLog:"+tag, string(buf[:n]))
		if err != nil {
			log.Println("[ErrorInfo]", err.Error())
		}
	}
}
コード例 #2
0
ファイル: build.go プロジェクト: zenlinTechnofreak/generator
func BuildDockerImageStartByHTTPReq(worker string, job *Job) {

	dockerClient, _ := NewDockerClient(worker, nil)

	reader, err := dockerClient.BuildImage(&(job.ImageConfig))
	if err != nil {
		log.Println("[ErrorInfo]", err.Error())

	} else if reader != nil {
		buf := make([]byte, 4096)

		for {
			n, err := reader.Read(buf)
			if err != nil && err != io.EOF {
				panic(err)
			}

			dockerClient.PushImage(&(job.ImageConfig))

			if 0 == n {
				err = models.PushMsgToList("buildLog:"+job.Tag, "bye")
				if err != nil {
					log.Println("[ErrorInfo]", err.Error())
				}

				err = models.PublishMsg("buildLog:"+job.Tag, "bye")
				if err != nil {
					log.Println("[ErrorInfo]", err.Error())
				}
				finishJob(worker)
				break
			}

			err = models.PushMsgToList("buildLog:"+job.Tag, string(buf[:n]))
			if err != nil {
				log.Println("[ErrorInfo]", err.Error())
			}

			err = models.PublishMsg("buildLog:"+job.Tag, string(buf[:n]))
			if err != nil {
				log.Println("[ErrorInfo]", err.Error())
			}
		}
	} else {

		log.Println("[ErrorInfo]", err.Error())
	}

}