Skip to content

Commit

Permalink
Merge pull request #267 from srl-wim/pull-first
Browse files Browse the repository at this point in the history
pull images before deployment
  • Loading branch information
hellt committed Feb 10, 2021
2 parents 876d884 + 658a034 commit a1d2b9c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
19 changes: 19 additions & 0 deletions clab/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package clab

import (
"context"
"fmt"
"os"
"path"
Expand Down Expand Up @@ -721,6 +722,24 @@ func (c *CLab) verifyLinks() error {
return nil
}

// VerifyImages will check if image referred in the node config
// either pullable or present or is available in the local registry
// if it is not available it will emit an error
func (c *CLab) VerifyImages(ctx context.Context) error {
images := map[string]struct{}{}
for _, node := range c.Nodes {
images[node.Image] = struct{}{}
}

for image := range images {
err := c.PullImageIfRequired(ctx, image)
if err != nil {
return err
}
}
return nil
}

//resolvePath resolves a string path by expanding `~` to home dir or getting Abs path for the given path
func resolvePath(p string) (string, error) {
if p == "" {
Expand Down
5 changes: 0 additions & 5 deletions clab/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ func (c *CLab) DeleteBridge(ctx context.Context) (err error) {
func (c *CLab) CreateContainer(ctx context.Context, node *Node) (err error) {
log.Infof("Creating container: %s", node.ShortName)

err = c.PullImageIfRequired(ctx, node.Image)
if err != nil {
return err
}

nctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()
labels := map[string]string{
Expand Down
5 changes: 5 additions & 0 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ var deployCmd = &cobra.Command{
if err = c.ParseTopology(); err != nil {
return err
}

if err = c.VerifyImages(ctx); err != nil {
return err
}

if reconfigure {
if err != nil {
return err
Expand Down

0 comments on commit a1d2b9c

Please sign in to comment.