File: push.go

package info (click to toggle)
golang-github-openshift-imagebuilder 1.2.15%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,776 kB
  • sloc: makefile: 18; sh: 3; ansic: 1
file content (29 lines) | stat: -rw-r--r-- 973 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package imageprogress

import (
	"fmt"
	"io"
)

// NewPushWriter creates a writer that periodically reports
// on push progress of a Docker image. It only reports when the state of the
// different layers has changed and uses time thresholds to limit the
// rate of the reports.
func NewPushWriter(printFn func(string)) io.WriteCloser {
	return newWriter(pushReporter(printFn), pushLayersChanged)
}

func pushReporter(printFn func(string)) func(report) {
	return func(r report) {
		var pctComplete float32 = 0.0
		pctComplete += float32(r.count(statusComplete)) / float32(r.totalCount())
		pctComplete += float32(r.count(statusPushing)) / float32(r.totalCount()) * r.percentProgress(statusPushing) / 100.0
		pctComplete *= 100.0

		printFn(fmt.Sprintf("Pushed %d/%d layers, %.0f%% complete", r.count(statusComplete), r.totalCount(), pctComplete))
	}
}

func pushLayersChanged(older, newer report) bool {
	return older.count(statusComplete) != newer.count(statusComplete)
}