Skip to content

Commit 5feadd9

Browse files
authored
use smb volume for case insensitive jobs (#472)
* use smb volume for case insensitive jobs * add `storage-image` command line option and script test * address review feedback * add clarifying comment
1 parent a61544f commit 5feadd9

File tree

7 files changed

+313
-18
lines changed

7 files changed

+313
-18
lines changed

cmd/dependabot/internal/cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var (
3131
updaterImage string
3232
proxyImage string
3333
collectorImage string
34+
storageImage string
3435
)
3536

3637
// rootCmd represents the base command when called without any subcommands
@@ -59,4 +60,5 @@ func init() {
5960
rootCmd.PersistentFlags().StringVar(&updaterImage, "updater-image", "", "container image to use for the updater")
6061
rootCmd.PersistentFlags().StringVar(&proxyImage, "proxy-image", infra.ProxyImageName, "container image to use for the proxy")
6162
rootCmd.PersistentFlags().StringVar(&collectorImage, "collector-image", infra.CollectorImageName, "container image to use for the OpenTelemetry collector")
63+
rootCmd.PersistentFlags().StringVar(&storageImage, "storage-image", infra.StorageImageName, "container image to use for the storage service")
6264
}

cmd/dependabot/internal/cmd/test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func NewTestCommand() *cobra.Command {
5050
ProxyCertPath: flags.proxyCertPath,
5151
ProxyImage: proxyImage,
5252
PullImages: flags.pullImages,
53+
StorageImage: storageImage,
5354
Timeout: flags.timeout,
5455
UpdaterImage: updaterImage,
5556
Volumes: flags.volumes,

cmd/dependabot/internal/cmd/update.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func NewUpdateCommand() *cobra.Command {
9696
ProxyCertPath: flags.proxyCertPath,
9797
ProxyImage: proxyImage,
9898
PullImages: flags.pullImages,
99+
StorageImage: storageImage,
99100
Timeout: flags.timeout,
100101
UpdaterImage: updaterImage,
101102
Volumes: flags.volumes,

internal/infra/run.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ type RunParams struct {
6868
CollectorImage string
6969
// CollectorConfigPath is the path to the OpenTelemetry collector configuration file
7070
CollectorConfigPath string
71+
// StorageImage is the image to use for the storage service
72+
StorageImage string
7173
// Writer is where API calls will be written to
7274
Writer io.Writer
7375
InputName string
@@ -369,6 +371,13 @@ func runContainers(ctx context.Context, params RunParams) (err error) {
369371
if err != nil {
370372
return err
371373
}
374+
375+
if params.Job.UseCaseInsensitiveFileSystem() {
376+
err = pullImage(ctx, cli, params.StorageImage)
377+
if err != nil {
378+
return err
379+
}
380+
}
372381
}
373382

374383
networks, err := NewNetworks(ctx, cli)
@@ -416,13 +425,18 @@ func runContainers(ctx context.Context, params RunParams) (err error) {
416425

417426
// put the clone dir in the updater container to be used by during the update
418427
if params.LocalDir != "" {
419-
if err = putCloneDir(ctx, cli, updater, params.LocalDir); err != nil {
428+
containerDir := guestRepoDir
429+
if params.Job.UseCaseInsensitiveFileSystem() {
430+
// since the updater is using the storage container, we need to populate the repo on that device because that's the directory that will be used for the update
431+
containerDir = caseSensitiveRepoContentsPath
432+
}
433+
if err = putCloneDir(ctx, cli, updater, params.LocalDir, containerDir); err != nil {
420434
return err
421435
}
422436
}
423437

424438
if params.Debug {
425-
if err := updater.RunShell(ctx, prox.url, params.ApiUrl); err != nil {
439+
if err := updater.RunShell(ctx, prox.url, params.ApiUrl, params.Job); err != nil {
426440
return err
427441
}
428442
} else {
@@ -432,7 +446,7 @@ func runContainers(ctx context.Context, params RunParams) (err error) {
432446
}
433447

434448
// Then run the dependabot commands as the dependabot user
435-
env := userEnv(prox.url, params.ApiUrl)
449+
env := userEnv(prox.url, params.ApiUrl, params.Job)
436450
if params.Flamegraph {
437451
env = append(env, "FLAMEGRAPH=1")
438452
}
@@ -473,33 +487,33 @@ func getFromContainer(ctx context.Context, cli *client.Client, containerID, srcP
473487
}
474488
}
475489

476-
func putCloneDir(ctx context.Context, cli *client.Client, updater *Updater, dir string) error {
490+
func putCloneDir(ctx context.Context, cli *client.Client, updater *Updater, localDir, containerDir string) error {
477491
// Docker won't create the directory, so we have to do it first.
478-
const cmd = "mkdir -p " + guestRepoDir
492+
cmd := fmt.Sprintf("mkdir -p %s", containerDir)
479493
err := updater.RunCmd(ctx, cmd, dependabot)
480494
if err != nil {
481495
return fmt.Errorf("failed to create clone dir: %w", err)
482496
}
483497

484-
r, err := archive.TarWithOptions(dir, &archive.TarOptions{})
498+
r, err := archive.TarWithOptions(localDir, &archive.TarOptions{})
485499
if err != nil {
486500
return fmt.Errorf("failed to tar clone dir: %w", err)
487501
}
488502

489503
opt := container.CopyToContainerOptions{}
490-
err = cli.CopyToContainer(ctx, updater.containerID, guestRepoDir, r, opt)
504+
err = cli.CopyToContainer(ctx, updater.containerID, containerDir, r, opt)
491505
if err != nil {
492506
return fmt.Errorf("failed to copy clone dir to container: %w", err)
493507
}
494508

495-
err = updater.RunCmd(ctx, "chown -R dependabot "+guestRepoDir, root)
509+
err = updater.RunCmd(ctx, "chown -R dependabot "+containerDir, root)
496510
if err != nil {
497511
return fmt.Errorf("failed to initialize clone dir: %w", err)
498512
}
499513

500514
// The directory needs to be a git repo, so we need to initialize it.
501515
commands := []string{
502-
"cd " + guestRepoDir,
516+
"cd " + containerDir,
503517
"git config --global init.defaultBranch main",
504518
"git init",
505519
"git config user.email 'dependabot@github.com'",

0 commit comments

Comments
 (0)