@@ -48,19 +48,14 @@ func (d *DockerClient) PullImage(ctx context.Context, imageName string) error {
4848}
4949
5050// BuildImage builds a Docker image using the provided tar build context.
51- // It validates that the image if name does not already exist before building .
51+ // It overwrites any existing image with the same name .
5252func (d * DockerClient ) BuildImage (
5353 ctx context.Context ,
5454 imageName string ,
5555 tarfile io.Reader ,
5656 out io.Writer ,
5757) error {
5858
59- err := d .CheckImageName (ctx , imageName )
60- if err != nil {
61- return fmt .Errorf ("failed to check image name: %w" , err )
62- }
63-
6459 image , err := d .cli .ImageBuild (ctx , tarfile , client.ImageBuildOptions {
6560 Tags : []string {imageName },
6661 Dockerfile : "Dockerfile" ,
@@ -130,24 +125,18 @@ func (d *DockerClient) PushImage(ctx context.Context, target string) error {
130125
131126 // Only include registry auth for non-localhost registries.
132127 // localhost:5000 doesn't require authentication.
133- isLocalRegistry := strings .HasPrefix (registry , "localhost" ) ||
134- strings .HasPrefix (registry , "127.0.0.1" )
135-
136- if ! isLocalRegistry && username != "" && password != "" {
137- auth := map [string ]string {
138- "username" : username ,
139- "password" : password ,
140- "serveraddress" : registry ,
141- }
142-
143- authJSON , err := json .Marshal (auth )
144- if err != nil {
145- return fmt .Errorf ("failed to marshal registry auth: %w" , err )
146- }
128+ auth := map [string ]string {
129+ "username" : username ,
130+ "password" : password ,
131+ "serveraddress" : registry ,
132+ }
147133
148- opts .RegistryAuth = base64 .StdEncoding .EncodeToString (authJSON )
134+ authJSON , err := json .Marshal (auth )
135+ if err != nil {
136+ return fmt .Errorf ("failed to marshal registry auth: %w" , err )
149137 }
150138
139+ opts .RegistryAuth = base64 .StdEncoding .EncodeToString (authJSON )
151140 imagePush , err := d .cli .ImagePush (ctx , target , opts )
152141 if err != nil {
153142 return fmt .Errorf ("failed to push image: %w" , err )
0 commit comments