Using dockerized cdktf executable with local python code

Hi all,

Can someone suggest the best way how to setup cdktf-cli with all additional tools/libraries for python (like python, pipenv, …) in docker container?

I found couple of examples where the code is also dockerized together with libs, but I wonder is it possible only to dockerize libraries and CLIs.

I was trying to follow prerequisites Install CDK for Terraform and Run a Quick Start Demo | Terraform | HashiCorp Developer and was trying to build docker container using Docker image

FROM node:18.14.2-slim

SHELL ["/bin/bash", "-c"]

RUN apt-get update \
    && apt-get install -y unzip shellcheck npm curl

RUN curl -o /tmp/terraform.zip https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip && \
    unzip /tmp/terraform.zip && \
    mv terraform /bin && \
    chmod 0755 /bin/terraform && \
    rm /tmp/terraform.zip && \
    npm install -g npm@9.5.1 \
    && npm install -g cdktf-cli@0.15.5

RUN apt-get update \
    && apt-get install -y pip

RUN pip install cdktf==0.15.5 \
    && pip install pytest

ENTRYPOINT ["/bin/bash"]

When try to execute script, I’m getting an error

docker run --rm cdktf_test:latest cdktf
/usr/local/bin/cdktf: cdktf: line 2: syntax error near unexpected token `"./cdktf.js"'
/usr/local/bin/cdktf: cdktf: line 2: `require("./cdktf.js");'

On the other side I can run the command from docker container.

I would appreciate any suggestion.

Thanks

Hi @gsmiljanic :wave:

You could base your image off of the one we use in CI, which is hashicorp/jsii-terraform. In that image you could install cdktf-cli through npm.