kreuzwerker / terraform-provider-docker

Terraform Docker provider
Mozilla Public License 2.0
609 stars 187 forks source link

`docker_image` doesn't build specified platform #599

Closed garysassano closed 8 months ago

garysassano commented 8 months ago

Community Note

Terraform (and docker Provider) Version

cdktf v0.20.1 kreuzwerker/docker v3.0.2

Affected Resource(s)

Terraform Configuration Files

main.ts

const backImage = new Image(this, "BackImage", {
  buildAttribute: {
    context: path.join(__dirname, "back"),
    platform: "linux/arm64",
  },
  name: `${backRepo.repositoryUrl}:latest`,
  triggers: { filesha256: backDockerfileDigest },
});

Dockerfile

FROM public.ecr.aws/docker/library/node:20-slim
COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.8.1 /lambda-adapter /opt/extensions/lambda-adapter
ENV AWS_LWA_PORT=4000
WORKDIR /var/task
ADD . /var/task
RUN yarn install && yarn build
EXPOSE 4000
CMD [ "yarn", "run", "start" ]

Debug Output

Panic Output

Expected Behaviour

Actual Behaviour

I deploy the image to a containerized Lambda function with arm64 architecture and it doesn't work. Switching to x86_x64 architecture works. In fact, if I run the built image locally, it works (I use Ubuntu 22.04.3 LTS on WSL2 with x86_x64 architecture).

It's not clear to me if this Terraform provider uses BuildKit to create a multi-platform image. If so, I guess it should accept TARGETPLATFORM as an ARG.

Steps to Reproduce

  1. terraform apply

Important Factoids

References