sparse-umbrella-88444
11/02/2023, 2:22 PMfunc buildDockerImage(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>"
if username == "" || password == "" || server == "" {
return fmt.Errorf("DOCKERHUB_USERNAME, DOCKERHUB_PASSWORD and DOCKERHUB_SERVER environment variables must be set")
}
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
}
}
ref. doc: https://www.pulumi.com/registry/packages/docker/api-docs/image/stocky-restaurant-98004
11/02/2023, 2:25 PMsparse-umbrella-88444
11/02/2023, 2:36 PM+ docker:index/image:Image: (create)
[urn=urn:pulumi:dev::<stack name>::docker:index/image:Image::<username>/node:18-buster-slim-arm-debian-latest]
build : {
args : {
BUILDKIT_INLINE_CACHE: "1"
platform : "linux/amd64"
}
context : "."
contextDigest: <digest>
dockerfile : "Dockerfile.dev"
platform : "linux/amd64"
}
imageName: <image-name>
registry : {
password: <password>
server : "<https://index.docker.io/v1>"
username: <username>
}
skipPush : false
msg="Successfully built and pushed Docker image with ID <username>/node:18-buster-slim-amd-debian-latest" imageID="<username>/node:18-buster-slim-amd-debian-latest" imageName="<username>/node:18-buster-slim-amd-debian-latest" platform=linux/amd64
2. This project involves a set of steps/configs which are added to the docker image. We are trying to write it in go as much as possible. We were prev. using the docker client SDK for go to build the image, but the docker SDK for go does not support creating manifests (for building multi-arch images). From the github issue, I thought that pulumi's SDK allows us to create manifest and so we thought of using pulumi.shy-arm-32391
11/02/2023, 4:38 PMstocky-restaurant-98004
11/02/2023, 5:40 PMsparse-umbrella-88444
11/03/2023, 6:28 AM1. Create a docker.Image to build a single-arch image for e.g. arm64.
2. Create another docker.Image to build a single-arch image for e.g. amd64.
3. Create a pulumi.Command.local (Pulumi Command provider) to run docker manifest to create the multi-arch image.
but creating manifests is not supported by the docker client lib for go I guess. Even if I build the images using docker SDK instead of pulumi for different platforms - how do I create the manifestsstocky-restaurant-98004
11/03/2023, 1:38 PMdocker
CLI, since that seems to be the only way.shy-arm-32391
11/03/2023, 4:35 PMdocker manifest inspect
and you should be able to leverage pulumi-command to create the multi-arch image in the way you'd expect.