Last active
October 28, 2021 06:07
-
-
Save imjasonh/5d7ad824210f69554fd409b282e5ed3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
while read l; do | |
echo Removing $l | |
docker image rm $l | |
done < images.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Clear cached images | |
./clear.sh | |
# Pull using docker pull | |
time ./simple.sh | |
# Make sure the pulled image works | |
docker run gcr.io/cloud-builders/docker version | |
# Clear cached images | |
./clear.sh | |
# Pull using Go script | |
time go run main.go | |
# Make sure thep pulled image works | |
docker run gcr.io/cloud-builders/docker version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gcr.io/cloud-builders/docker | |
gcr.io/cloud-builders/npm | |
gcr.io/cloud-builders/yarn | |
gcr.io/cloud-builders/mvn | |
gcr.io/cloud-builders/gradle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"flag" | |
"fmt" | |
"log" | |
"os" | |
"strings" | |
"github.com/google/go-containerregistry/pkg/name" | |
"github.com/google/go-containerregistry/pkg/v1/daemon" | |
"github.com/google/go-containerregistry/pkg/v1/remote" | |
"golang.org/x/sync/errgroup" | |
) | |
var ( | |
filename = flag.String("f", "images.txt", "Name of file containing images to pull") | |
) | |
func main() { | |
flag.Parse() | |
f, err := os.Open(*filename) | |
if err != nil { | |
log.Fatalf("Error opening %q: %v", *filename, err) | |
} | |
defer f.Close() | |
var errg errgroup.Group | |
s := bufio.NewScanner(f) | |
for s.Scan() { | |
line := s.Text() | |
if line == "" || strings.HasPrefix(line, "#") { | |
continue | |
} | |
log.Printf("Pulling %q", line) | |
tag, err := name.NewTag(line, name.WeakValidation) | |
if err != nil { | |
log.Fatalf("Error parsing %q: %v", line, err) | |
} | |
errg.Go(func() error { | |
i, err := remote.Image(tag) | |
if err != nil { | |
return fmt.Errorf("Error pulling %q: %v", tag, err) | |
} | |
if _, err := daemon.Write(tag, i, daemon.WriteOptions{}); err != nil { | |
return fmt.Errorf("Error writing %q to daemon: %v", tag, err) | |
} | |
log.Printf("Finished pulling %q", tag) | |
return nil | |
}) | |
} | |
if err := s.Err(); err != nil { | |
log.Fatalf("Error reading %q: %v", *filename, err) | |
} | |
if err := errg.Wait(); err != nil { | |
log.Fatalf("Error pulling an image: %v", err) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
while read l; do | |
echo Pulling $l | |
docker pull $l | |
done < images.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment