Skip to content

Commit

Permalink
feat: use default docker creds if they are configured (#1006)
Browse files Browse the repository at this point in the history
Resolve BE-2430
  • Loading branch information
nickpetrovic authored Mar 3, 2025
1 parent 7e09028 commit b79cb5d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
22 changes: 21 additions & 1 deletion pkg/abstractions/image/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const (
pipCommandType string = "pip"
shellCommandType string = "shell"
micromambaCommandType string = "micromamba"

dockerHubRegistry string = "docker.io"
)

type Builder struct {
Expand Down Expand Up @@ -244,6 +246,10 @@ func (b *Builder) Build(ctx context.Context, opts *BuildOpts, outputChan chan co
containerSpinupTimeout = b.calculateImageArchiveDuration(ctx, opts)
}

if creds, err := b.shouldUseDefaultDockerCreds(opts); err == nil {
opts.BaseImageCreds = creds
}

containerId := b.genContainerId()

containerRequest, err := b.generateContainerRequest(opts, dockerfile, containerId, authInfo.Workspace)
Expand Down Expand Up @@ -440,6 +446,20 @@ func (b *Builder) Build(ctx context.Context, opts *BuildOpts, outputChan chan co
return nil
}

func (b *Builder) shouldUseDefaultDockerCreds(opts *BuildOpts) (string, error) {
isDockerHub := opts.BaseImageRegistry == dockerHubRegistry
credsNotSet := opts.BaseImageCreds == ""

if isDockerHub && credsNotSet {
username := b.config.ImageService.Registries.Docker.Username
password := b.config.ImageService.Registries.Docker.Password
if username != "" && password != "" {
return fmt.Sprintf("%s:%s", username, password), nil
}
}
return "", errors.New("docker creds not set in config")
}

// generateContainerRequest generates a container request for the build container
func (b *Builder) generateContainerRequest(opts *BuildOpts, dockerfile *string, containerId string, workspace *types.Workspace) (*types.ContainerRequest, error) {
baseImageId, err := b.GetImageId(&BuildOpts{
Expand Down Expand Up @@ -569,7 +589,7 @@ func ExtractImageNameAndTag(imageRef string) (BaseImage, error) {

registry := result["Registry"]
if registry == "" {
registry = "docker.io"
registry = dockerHubRegistry
}

repo := result["Repo"]
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/config.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ imageService:
pythonVersion: python3.10
registries:
docker:
username: beamcloud
username:
password:
s3:
bucketName: beta9-images
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type AppConfig struct {
Database DatabaseConfig `key:"database" json:"database"`
GatewayService GatewayServiceConfig `key:"gateway" json:"gateway_service"`
FileService FileServiceConfig `key:"fileService" json:"file_service"`
ImageService ImageServiceConfig `key:"imageservice" json:"image_service"`
ImageService ImageServiceConfig `key:"imageService" json:"image_service"`
Storage StorageConfig `key:"storage" json:"storage"`
Worker WorkerConfig `key:"worker" json:"worker"`
Providers ProviderConfig `key:"providers" json:"providers"`
Expand Down

0 comments on commit b79cb5d

Please sign in to comment.