Skip to content

Commit

Permalink
feat(docker): Skip volume mount if volume already mounted
Browse files Browse the repository at this point in the history
  • Loading branch information
paralta committed Jul 12, 2023
1 parent 0a5968d commit eb87105
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
16 changes: 15 additions & 1 deletion cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ var rootCmd = &cobra.Command{
return err
}
setMountPointsForFamiliesInput(mountPoints, config)
} else {
// Check if volume already mounted
scanPath := "/mnt/snapshot"
entries, err := os.ReadDir(scanPath)
if err != nil {
err = fmt.Errorf("failed to read %s directory: %w", scanPath, err)
if e := cli.MarkDone(ctx, []error{err}); e != nil {
logger.Errorf("Failed to update asset scan stat to completed with errors: %v", e)
}
return err
}
if len(entries) > 0 {
setMountPointsForFamiliesInput([]string{scanPath}, config)
}
}

err = cli.MarkInProgress(ctx)
Expand Down Expand Up @@ -196,7 +210,7 @@ func initConfig() {
}

func initLogger() {
log.InitLogger(logrus.InfoLevel.String(), os.Stderr)
log.InitLogger(logrus.DebugLevel.String(), os.Stderr)
logger = logrus.WithField("app", "vmclarity")
}

Expand Down
7 changes: 5 additions & 2 deletions runtime_scan/pkg/provider/docker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ func (c Client) RunAssetScan(ctx context.Context, config *provider.ScanJobConfig
}
}

// TODO(paralta) Check if config file exists
scanConfigFilePath, err := c.createScanConfigFile(config)
if err != nil {
return provider.FatalError{
Expand Down Expand Up @@ -286,9 +287,11 @@ func (c Client) startScan(ctx context.Context, volumeName string, scanConfigFile
/app/vmclarity-cli \
--config /tmp/%s \
--server %s \
--asset-scan-id %s
--asset-scan-id %s \
--output /var/opt/vmclarity
`, filepath.Base(scanConfigFilePath), config.VMClarityAddress, config.AssetScanID)

// TODO(paralta) Check if container already created
resp, err := c.dockerClient.ContainerCreate(
ctx,
&container.Config{
Expand All @@ -301,7 +304,7 @@ func (c Client) startScan(ctx context.Context, volumeName string, scanConfigFile
{
Type: mount.TypeVolume,
Source: volumeName,
Target: "/data",
Target: "/mnt/snapshot",
},
},
},
Expand Down

0 comments on commit eb87105

Please sign in to comment.