Is there a way to build a docker image for a speci...
# getting-started
e
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
@elegant-gigabyte-8733 there are a lot of parts at play here including the Dockerfile you're using, the base image, etc.
e
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
Note that that's
docker.Image
not
awsx.ecr.Image
e
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
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
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
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
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
agree 😩
c
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
Wow that would be really helpful
Thanks @curved-kitchen-24115
m
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
Thank you! Very helpful