Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/dependabot/internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
updaterImage string
proxyImage string
collectorImage string
storageImage string
)

// rootCmd represents the base command when called without any subcommands
Expand Down Expand Up @@ -59,4 +60,5 @@ func init() {
rootCmd.PersistentFlags().StringVar(&updaterImage, "updater-image", "", "container image to use for the updater")
rootCmd.PersistentFlags().StringVar(&proxyImage, "proxy-image", infra.ProxyImageName, "container image to use for the proxy")
rootCmd.PersistentFlags().StringVar(&collectorImage, "collector-image", infra.CollectorImageName, "container image to use for the OpenTelemetry collector")
rootCmd.PersistentFlags().StringVar(&storageImage, "storage-image", infra.StorageImageName, "container image to use for the storage service")
}
1 change: 1 addition & 0 deletions cmd/dependabot/internal/cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func NewTestCommand() *cobra.Command {
ProxyCertPath: flags.proxyCertPath,
ProxyImage: proxyImage,
PullImages: flags.pullImages,
StorageImage: storageImage,
Timeout: flags.timeout,
UpdaterImage: updaterImage,
Volumes: flags.volumes,
Expand Down
1 change: 1 addition & 0 deletions cmd/dependabot/internal/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func NewUpdateCommand() *cobra.Command {
ProxyCertPath: flags.proxyCertPath,
ProxyImage: proxyImage,
PullImages: flags.pullImages,
StorageImage: storageImage,
Timeout: flags.timeout,
UpdaterImage: updaterImage,
Volumes: flags.volumes,
Expand Down
31 changes: 22 additions & 9 deletions internal/infra/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ type RunParams struct {
CollectorImage string
// CollectorConfigPath is the path to the OpenTelemetry collector configuration file
CollectorConfigPath string
// StorageImage is the image to use for the storage service
StorageImage string
// Writer is where API calls will be written to
Writer io.Writer
InputName string
Expand Down Expand Up @@ -369,6 +371,13 @@ func runContainers(ctx context.Context, params RunParams) (err error) {
if err != nil {
return err
}

if params.Job.UseCaseInsensitiveFileSystem() {
err = pullImage(ctx, cli, params.StorageImage)
if err != nil {
return err
}
}
}

networks, err := NewNetworks(ctx, cli)
Expand Down Expand Up @@ -416,13 +425,17 @@ func runContainers(ctx context.Context, params RunParams) (err error) {

// put the clone dir in the updater container to be used by during the update
if params.LocalDir != "" {
if err = putCloneDir(ctx, cli, updater, params.LocalDir); err != nil {
containerDir := guestRepoDir
if params.Job.UseCaseInsensitiveFileSystem() {
containerDir = caseSensitiveRepoContentsPath
}
if err = putCloneDir(ctx, cli, updater, params.LocalDir, containerDir); err != nil {
return err
}
}

if params.Debug {
if err := updater.RunShell(ctx, prox.url, params.ApiUrl); err != nil {
if err := updater.RunShell(ctx, prox.url, params.ApiUrl, params.Job); err != nil {
return err
}
} else {
Expand All @@ -432,7 +445,7 @@ func runContainers(ctx context.Context, params RunParams) (err error) {
}

// Then run the dependabot commands as the dependabot user
env := userEnv(prox.url, params.ApiUrl)
env := userEnv(prox.url, params.ApiUrl, params.Job)
if params.Flamegraph {
env = append(env, "FLAMEGRAPH=1")
}
Expand Down Expand Up @@ -473,33 +486,33 @@ func getFromContainer(ctx context.Context, cli *client.Client, containerID, srcP
}
}

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

r, err := archive.TarWithOptions(dir, &archive.TarOptions{})
r, err := archive.TarWithOptions(localDir, &archive.TarOptions{})
if err != nil {
return fmt.Errorf("failed to tar clone dir: %w", err)
}

opt := container.CopyToContainerOptions{}
err = cli.CopyToContainer(ctx, updater.containerID, guestRepoDir, r, opt)
err = cli.CopyToContainer(ctx, updater.containerID, containerDir, r, opt)
if err != nil {
return fmt.Errorf("failed to copy clone dir to container: %w", err)
}

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

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