func streamOutput(c *gin.Context, output *streams.Output, replay bool) { c.Writer.WriteHeader(http.StatusOK) c.Writer.Header().Set("Cache-Control", "no-cache") c.Writer.Header().Set("Connection", "keep-alive") var w io.Writer if c.Request.Header.Get("Accept") == "text/event-stream" { c.Writer.Header().Set("Content-Type", "text/event-stream") w = NewSSEWriter(c.Writer) } else { c.Writer.Header().Set("Content-Type", "text/plain") w = flushwriter.New(c.Writer) } waitChan := make(chan bool, 1) notify := c.Writer.CloseNotify() go func() { <-notify waitChan <- true }() if replay { output.Replay(w) } output.Add(w, waitChan) <-waitChan output.Remove(w) }
func (b *DockerBuilder) PushImage(build *Build, stream *streams.Output) error { name := fmt.Sprintf("%s/%s", b.registryURL, build.RepositoryName) stream.Write([]byte(fmt.Sprintf("Pushing %s:%s...", name, build.ImageTag))) err := b.dockerClient.PushImage(docker.PushImageOptions{ Name: name, Tag: build.ImageTag, OutputStream: stream, }, docker.AuthConfiguration{}) if err != nil { return err } stream.Write([]byte(fmt.Sprintf("Pushing %s:latest...", name))) err = b.dockerClient.PushImage(docker.PushImageOptions{ Name: name, Tag: "latest", OutputStream: stream, }, docker.AuthConfiguration{}) return err }