Hi guys Does pulumi support creating multi-platfor...
# getting-started
s
Hi guys Does pulumi support creating multi-platform docker images. I want to avoid using buildx cli command and wanted to know if there using pulumi's go SDK can we create image with platform arm64 and amd64
s
s
hey @straight-cartoon-24485 needed a bit of help. i have tried to use the above doc, but am fairly new to pulumi. i am trying to use pulumi to replace the way I built docker image and written functions to build the image. on running the go app, I am getting error: Error processing image: missing project name I believe this is from the pulumi project setup. i have also created a Pulumi.yaml file in the root folder folder structure frontend backend .gitignore other config files pulumi.yaml with code
Copy code
name: docker-pulumi-test
runtime: go
description: A minimal Go Pulumi program
Any idea what config I am missing?
@cuddly-computer-18851 @rich-alligator-53421 please help if you have context. this is a go project. i didn't setup using pulumi new cmd as it already had some code in it (I was prev. using docker go SDK to build image)
s
did you create a stack?
r
What?
why would you tag me here? 😄
c
Yeah bizarre
s
@cuddly-computer-18851 @rich-alligator-53421 saw a thread where you were discussing pulumi docker SDK, so tagged you.
Hi, i am trying to build docker image with specific platform in my go app. the aim is to build the docker image for specific platforms and push them to my dockerhub and then use them to create a manifest for multi-arch images. but the image is not getting built/pushed using this. am I missing any config? function
Copy code
func buildImage(ctx *pulumi.Context, imageName string, platform string, dockerfilePath string) error {
	if ctx == nil {
		log.Error("Pulumi context is nil")
		return fmt.Errorf("Pulumi context is nil")
	}
	if _, err := os.Stat(dockerfilePath); os.IsNotExist(err) {
		log.WithField("dockerfilePath", dockerfilePath).Error("Dockerfile does not exist")
		return fmt.Errorf("Dockerfile does not exist at the specified path")
	}

	username := os.Getenv("DOCKERHUB_USERNAME")
	password := os.Getenv("DOCKERHUB_PASSWORD")
	server := "<https://index.docker.io/v1>"

	builtImage, err := docker.NewImage(ctx, imageName, &docker.ImageArgs{
		Build: &docker.DockerBuildArgs{
			Context:    pulumi.String("."),
			Dockerfile: pulumi.String(dockerfilePath),
			Args: pulumi.StringMap{
				"BUILDKIT_INLINE_CACHE": pulumi.String("1"),
				"platform":              pulumi.String(platform),
			},
			Platform: pulumi.String(platform),
		},
		ImageName: pulumi.String(imageName),
		Registry: &docker.RegistryArgs{
			Server:   pulumi.String(server),
			Username: pulumi.String(username),
			Password: pulumi.String(password),
		},
	})
	if err != nil {
		log.WithFields(log.Fields{
			"imageName": imageName,
			"platform":  platform,
		}).Errorf("Error building Docker image: %s", err)
		return fmt.Errorf("Error building Docker image: %w", err)
	} else {
		builtImage.ImageName.ApplyT(func(name string) error {
			log.WithFields(log.Fields{
				"imageName": imageName,
				"platform":  platform,
				"imageID":   name,
			}).Infof("Successfully built and pushed Docker image with ID %s", name)
			return nil
		})
		return nil
	}
}