Hey all, I'm using AWS CDK to deploy infra, includ...
# general
a
Hey all, I'm using AWS CDK to deploy infra, including a docker image. The
DockerImageAsset
construct it exposes expects a
Dockerfile
, and tries to actually build it. By the time I'm deploying, pants will have already built my image including x-platform support and embedding a pex file, so I don't want to redo the build using AWS's build tooling. The alternative option is to provide it with a
TarballImageAsset
, which would work on the output of a command like
docker save my-pants-built-image:latest -o my-pants-built-image.tar
. I'd like to get this to work, but I'm trying to figure out the most idiomatic way to get from an image packaged via my
docker_image
pants target to this tar. Does anyone have suggestions? I'm pretty brand new to the pants ecosystem, so apologies if I mangle any terminology
The route I'm starting to go down is just using
run_shell_command
to run
docker save ...
, and put the file in my dist directory manually
c
I can look a little further later but I believe we push our pants built images to ecr at build time.
👍 1
Just looked. We build the image with pants
docker_image
and then use pants publish to push the image to ecr. In cdk we use the
DockerImageFunction
construct and for code you pass in
DockerImageCode.from_ecr(repo)
a
Thanks for checking @cold-jackal-89755, I super appreciate it! That makes sense. My CDK logic can target any stack (dev personal stacks, beta, prod) which are in different AWS accounts, so I didn't want to rely on pants for deployment, since the private ECR repo I'm deploying to has to be deployment context aware. I was able to get around this with (anonymized):
Copy code
docker_image(
    name="my_img",
)

run_shell_command(
    name="my_img_tar_export",
    command="mkdir -p dist && docker save my_img:latest -o dist/my_img.tar",
    execution_dependencies=[":my_img"],
)
Then I had CDK reference a
TarballImageAsset
pointing to
full/path/to/this/pants/BUILD/dist/my_img.tar
c
I actually like your way because you can eliminate the need for ecr!
🔥 1
a
Thanks! It feels a little weird because it's just ending up in a random sidecar dist in the middle of my project (not even the top level pants dist directory), it would be nice to have a target (or param to the existing
docker_image
one) that would get the
package
goal to handle saving the tar and putting it in the main dist
I'm conceptually considering my build as 3 steps: 1. Run pants to build everything except the frontend, and put artifacts in
dist/
2. Run typescript+react build toolchain and put artifacts in
webdist/
3. Run CDK deploy, which should be able to work only off of those two directories