https://pulumi.com logo
#getting-started
Title
# getting-started
e

elegant-gigabyte-8733

06/21/2023, 3:30 PM
Is there a way to build a docker image for a specific platform architecture with the
awsx.ecr.Image
resource. I tried to set it with the
args
but it seems like that didn’t work either
Copy code
const plaidContainerImage = new awsx.ecr.Image("plaid-container-image", {
    repositoryUrl: ecrRepositoryUrl,
    path: "..",
    args: {"platform": "linux/amd64"}
})
c

curved-kitchen-24115

06/21/2023, 3:35 PM
@elegant-gigabyte-8733 there are a lot of parts at play here including the Dockerfile you're using, the base image, etc.
e

elegant-gigabyte-8733

06/21/2023, 3:36 PM
The
docker.Image
allows you to build for a specific platform
Copy code
Yes, you can set the platform architecture for a Docker image using the platform property of build in the docker.Image resource. Here's a Pulumi TypeScript program that demonstrates how to do this:

import * as pulumi from "@pulumi/pulumi";
import * as docker from "@pulumi/docker";

// Build a Docker image with a specific platform architecture
const myImage = new docker.Image("my-image", {
    build: {
        context: "./path/to/docker-context",
        platform: "linux/arm64", // Set the platform architecture here
        dockerfile: "./path/to/Dockerfile",
    },
    imageName: "my-docker-image",
    // Set registry credentials if needed
    // registry: {
    //     server: "my-docker-registry-server",
    //     username: "my-docker-registry-username",
    //     password: "my-docker-registry-password",
    // },
});
Wasn’t sure if this one did, seems like it doesn’t though
c

curved-kitchen-24115

06/21/2023, 3:38 PM
Note that that's
docker.Image
not
awsx.ecr.Image
e

elegant-gigabyte-8733

06/21/2023, 3:38 PM
args
is the wrong place those after reading the docs closer
Yeah my question was if
awsx.ecr.Image
will let you set this architecture. It seems like the answer is no
Actually this might be it
image.png
Gonna give it a try
I can pass
--platform linux/arm64
here should work
c

curved-kitchen-24115

06/21/2023, 3:40 PM
reading the ECR multi-arch announcement makes me think it's not that simple: https://aws.amazon.com/blogs/containers/introducing-multi-architecture-container-images-for-amazon-ecr/
mind you that is 3 years old, so maybe your solution may work.
e

elegant-gigabyte-8733

06/21/2023, 3:42 PM
Oof
If I do a
pulumi up
from Github on an ubuntu machine it works fine because it builds a
linux/amd64
image but if I do it from my Mac it breaks because I have an M1
I don’t necessarily want to build a multi-platform image but sounds like that may be the best option
c

curved-kitchen-24115

06/21/2023, 3:44 PM
typically in this sort of world you'd want to use CI/CD to build your images so that you can have control over the build platform so that your local environment doesn't cause these problems.
e

elegant-gigabyte-8733

06/21/2023, 3:46 PM
Agreed, I like to test the new flows and get them working first and then add to CI/CD
Trail and error through CI/CD is really time consuming
c

curved-kitchen-24115

06/21/2023, 3:47 PM
agree 😩
c

curved-kitchen-24115

06/21/2023, 3:49 PM
neat 👍🏼
also, I'm not sure what you run CI/CD on - but I've found https://github.com/marketplace/actions/debugging-with-ssh to be an incredible timesaver for github actions.
e

elegant-gigabyte-8733

06/21/2023, 3:52 PM
Wow that would be really helpful
Thanks @curved-kitchen-24115
m

miniature-musician-31262

06/22/2023, 12:13 AM
I believe setting
DOCKER_DEFAULT_PLATFORM="linux/amd64"
also works, either in the shell that runs
pulumi
or as an environment variable on the
Image
resource itself. I'll verify though
e.g.:
Copy code
const image = new awsx.ecr.Image("image", {
    repositoryUrl: repo.url,
    path: "./app",
    env: {
        DOCKER_DEFAULT_PLATFORM: "linux/amd64",
    }
});
Yep, both on the shell and on the resource both seem to work!
So a couple of additional options for ya
e

elegant-gigabyte-8733

06/22/2023, 2:21 AM
Thank you! Very helpful
2 Views