https://pulumi.com logo
Title
d

dry-journalist-60579

03/14/2023, 9:47 PM
Ok so it’s me again… posted in #getting-started before not realizing this channel exists… I’m trying to get deployments to run with Poetry. I’d like to not specify
runtime:
  name: python
  options:
    virtualenv: venv
in my Pulumi.yaml because locally we use
poetry run pulumi up
and poetry uses the correct virtualenv automatically. Side note: we are using a custom docker image for deployments because we’re using python 3.10 so I built one:
# based on <https://github.com/pulumi/pulumi-docker-containers/blob/main/docker/pulumi/Dockerfile>

FROM python:3.10-slim

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

# Passing --build-arg PULUMI_VERSION=vX.Y.Z will use that version
# of the SDK. Otherwise, we use whatever <http://get.pulumi.com|get.pulumi.com> thinks is
# the latest
ARG PULUMI_VERSION

# Install the Pulumi SDK, including the CLI and language runtimes.
RUN curl -fsSL <https://get.pulumi.com/> | bash -s -- --version $PULUMI_VERSION

# Install Poetry
ENV POETRY_HOME=/usr/local
RUN curl -sSL <https://install.python-poetry.org> | python3 -

# Create wrappers such that pulumi commands always run with poetry
COPY ./create-poetry-wrappers.sh /usr/local/bin
RUN create-poetry-wrappers.sh

ENTRYPOINT ["/bin/bash", "-c"]
CMD [ "/bin/bash" ]
I thought that I could create some wrapper scripts to force
poetry run …
on pulumi, but it seems like the
/pulumi-deploy-executor
is not ? somehow? using the pulumi located in the container’s $PATH?
/usr/bin/pulumi-language-python-exec
<= where is this file coming from…? It’s not in my image. I’m installing to
~/.pulumi/bin
and wrappers in
/usr/local/bin
r

red-match-15116

03/14/2023, 10:21 PM
Just catching up with what's going on here...
pulumi-language-python-exec
should be installed along with the pulumi python SDK when you run
poetry install
for your project.
d

dry-journalist-60579

03/14/2023, 10:22 PM
Hmm isn’t that installed by
curl -fsSL <https://get.pulumi.com/> | bash -s -- --version $PULUMI_VERSION
r

red-match-15116

03/14/2023, 10:25 PM
I believe that only installs the Pulumi CLI :thinking-taco: - I'm not 100% on that though
okay you're right that is installed with the CLI
d

dry-journalist-60579

03/14/2023, 10:29 PM
I install the CLI during my docker build….
so I’m wondering if the deploy executor re-installs it?
r

red-match-15116

03/14/2023, 10:30 PM
the deploy executor uses automation api and calls out to the pulumi on path.
d

dry-journalist-60579

03/14/2023, 10:30 PM
Is there any way I can see the source for
curl -H "Authorization: token $PULUMI_ACCESS_TOKEN" "$PULUMI_SERVICE_URL/preview/deployments/executor" |gzip -d >/pulumi-deploy-executor && chmod +x /pulumi-deploy-executor
r

red-match-15116

03/14/2023, 10:31 PM
backing up, is the issue here the
ModuleNotFoundError: No module named pulumi
?
d

dry-journalist-60579

03/14/2023, 10:31 PM
yeah, I’m trying to use poetry
image.png
image.png
poetry is finding my pyproject.toml and installing the correct packages
but then the operation fails:
r

red-match-15116

03/14/2023, 10:35 PM
okay yeah, i'm following now. so that's because the deployment executor is using automation api to run the program, and the program doesn't know about where the poetry env is. interesting.
d

dry-journalist-60579

03/14/2023, 10:36 PM
I tried to write a wrapper:
#!/bin/bash

for file_path in ~/.pulumi/bin/*; do
  file_name=$(basename "$file_path")
  wrapper_path="/usr/bin/$file_name"

  cat <<EOF > "$wrapper_path"
#!/bin/bash
echo poetry run "$file_path" "\$@"
EOF

  chmod +x "$wrapper_path"
done
this basically creates a file in
/usr/bin/pulumi-language-python-exec
that just does
poetry run
I made it do
echo poetry run
to confirm it was being called
but it’s not
r

red-match-15116

03/14/2023, 10:38 PM
I think maybe
poetry run
should wrap
/pulumi-deploy-executor
instead?
since the deploy executor is what eventually calls out to pulumi
d

dry-journalist-60579

03/14/2023, 10:39 PM
potentially… but the deployment executor gets downloaded into the container at runtime
I guess I could add a pre-run command to overwrite it
r

red-match-15116

03/14/2023, 10:41 PM
yah - i appreciate all the effort you're putting into this and definitely want this to be a better experience for you! i'm following up internally to see what else I can find
d

dry-journalist-60579

03/14/2023, 10:44 PM
❤️ thank you so much for all your help @red-match-15116!!
getting closer! gotta run for now, but will try later
l

limited-rainbow-51650

03/15/2023, 7:31 AM
With the virtual environments, within the project folder, you can drop the
poetry run ...
way of doing things.
d

dry-journalist-60579

03/15/2023, 2:40 PM
ahh interesting, thank you, @limited-rainbow-51650!
I don’t love treating each Pulumi project as a separate virtualenv… but it makes sense
I’ll talk to my team to see how they feel about it
I was able to get things to run with our set up (not using virtual envs) by wrapping the executor in a
poetry run…
I may go this route for now as I don’t want to change the way our team is running pulumi and poetry locally
but thank you again!