Hi folks! I'm using poetry to manage the deps of m...
# python
q
Hi folks! I'm using poetry to manage the deps of my pulumi deployment script. When I use the Pulumi Github action, I have to install the deps via pip, though, and a generated
requirements.txt
file. A workflow like this runs: https://github.com/pulumi/actions/blob/master/examples/python-pulumi.yaml But I would like to do something like this:
Copy code
- id: "setup-python-pulumi"
        name: "Install Pulumi Python environment"
        uses: actions/setup-python@v3
        with:
          python-version: '3.10'
      
      - id: "get-deployment-deps"
        name: "Get deployment script deps"
        working-directory: iac
        run: |
          pipx install poetry
          poetry install

      - id: 'pulumi-deploy'
        name: 'Deploy from Pulumi IaC'
        uses: pulumi/actions@v3
        with:
          command: up
          stack-name: nocap/dev
          work-dir: iac
          refresh: true
However, the Pulumi action fails, saying it can't import pulumi. It doesn't use the environment Poetry created. Is there a way to specify your environment to the action?
1
The action runs the command
pulumi up --yes --skip-preview --parallel 2147483647 --exec-agent pulumi/actions@v3 --color auto --exec-kind auto.local --stack nocap/dev --non-interactive
(for example), and that fails due to not running in the env with the deps. When running pytest later, I just run
poetry run pytest
to make sure it's using the corrent env. I could also run
poetry shell
first to have future command run in that env. I assume this is also a problem for Pipenv.
And even with
pip
if you install in a virtualenv. The example uses
pip
to install to the system, which is fine for a disposable runner... Maybe I can just turn it off, like with
pipenv install --system
.
k
+ 1! AFAIK it’s only possible to specify which environment pulumi runs in in the Pulumi.yaml file which is project wide and static. It would be really handy to be able to specify which environment the stack runs in at runtime. I’ve tried overriding the runtime.options.virtualenv property for the stack since we can do that via the CLI during runtime but that didn’t get picked up.
1
1
❤️ 1
l
I have this configured:
poetry config virtualenvs.in-project true
which creates the virtual environment folder within the project setup. With that in place, you can use Poetry to manage dependencies, then run Pulumi with the
venv
folder configured in
Pulumi.yaml
.
q
Ah, that makes sense @limited-rainbow-51650. thanks! That got me working. I changed my Pulumi.yaml file to include:
Copy code
runtime:
  name: python
  options:
    virtualenv: venv
And ran
poetry config virtualenvs.in-project true --local
(just setting it for this project) and made sure
poetry.toml
was added to source control.
👍🏼 1