changes before switching to docker daemon pull
@@ -2,7 +2,9 @@ package main
import (
"bytes"
+ "fmt"
"os"
+ "time"
docker "github.com/fsouza/go-dockerclient"
log "github.com/sirupsen/logrus"
@@ -10,8 +12,10 @@ import (
func main() {
- // make a docker client
- dockerClient, err := docker.NewClientFromEnv()
+ // TODO: make this run from a docker server instead of a client
+ // make a local docker client
+ endpoint := "unix:///var/run/docker.sock"
+ dockerClient, err := docker.NewClient(endpoint)
if err != nil {
log.Errorln("failed to created new docker client", err)
os.Exit(1)
@@ -21,22 +25,38 @@ func main() {
b := new(bytes.Buffer)
// create channel that will read bytes from our buffer
- c := make(chan bytes.Buffer)
+ // c := make(chan bytes.Buffer)
- // set options for docker image pull
+ // set options/auth for docker image pull
opts := docker.PullImageOptions{
Repository: "nginx",
Tag: "1.21",
- // Platform: string,
OutputStream: b,
}
auth := docker.AuthConfiguration{}
// perform docker pull on target image
- err = dockerClient.PullImage(opts, auth)
+ pullImage(dockerClient, opts, auth)
+
+ fmt.Println(b.Len())
+
+}
+
+// timeTrack tracks the time it takes for a function to complete
+func timeTrack(start time.Time, name string) time.Duration {
+ elapsed := time.Since(start)
+ log.Printf("%s took %s", name, elapsed)
+ return elapsed
+}
+
+func pullImage(dockerClient *docker.Client, opts docker.PullImageOptions, auth docker.AuthConfiguration) {
+ // start timeTrack timer
+ defer timeTrack(time.Now(), "pullImage")
+
+ // pull image
+ err := dockerClient.PullImage(opts, auth)
if err != nil {
- log.Errorln("failed to pull docker image with options ", opts)
+ log.Errorln("failed to pull image ", err)
os.Exit(1)
}
-
}
