Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cloudformation config to use pdm export instead of venv #6478

Closed
wants to merge 2 commits into from

Conversation

spwoodcock
Copy link
Member

What type of PR is this? (check all applicable)

  • πŸ• Feature
  • πŸ› Bug Fix
  • πŸ“ Documentation
  • πŸ§‘β€πŸ’» Refactor
  • βœ… Test
  • πŸ€– Build or CI
  • ❓ Other (please specify)

Describe this PR

  • Prod has an issue
+ pdm run -vv flask db upgrade
[PdmUsageError]: Command 'flask' is not found in your PATH.
  • The virtualenv for PDM is not being configured correctly.
  • Instead of using a virtualenv in prod, it's probably better to use the included python environment on a fresh machine (each deploy is to a fresh machine).
  • Using pdm export we can get the requirements in a txt file, then pip install the requirements.
  • This should solve the issue as the packages will definitely be available in the PYTHONPATH of the default python binary in PATH.

Checklist before requesting a review

[optional] What gif best describes this PR or how it makes you feel?

@spwoodcock
Copy link
Member Author

@dakotabenjamin I was going to also update Python 3.9 --> 3.10 in this script, as we use 3.10 in other places without issues (in the dockerfile for instance).

However I think this config runs on Ubuntu 20.04, where the python3.9 package is available.
We would need to upgrade to Ubuntu 22.04 for python3.10 (https://packages.ubuntu.com/jammy/python3.10).

@mahesh-naxa
Copy link
Collaborator

I replicated the exact PROD EC2 instance with the same AMI & Conf and landed at:

root@ip-10-0-8-64:/opt/tasking-manager# pdm install
+ pdm install
Lock file version is not compatible with PDM, installation may fail
Updating the lock file...
python.use_venv is on, creating a virtualenv for this project...
Virtualenv is created successfully at /opt/tasking-manager/.venv
See /tmp/pdm-lock-wv9xtlmw.log for detailed debug log.
[KeyError]: 'Requires-Python'
Add '-v' to see the detailed traceback

This is where the user-data code fails. With some digging i found that there's been some changes to importlib 5 days ago hence resulting in this.
References
https://importlib-metadata.readthedocs.io/en/latest/history.html#v8-0-0

pdm-project/pdm#2974

I downgraded with pip3 install importlib_metadata==v7.2.1 And everything ran as expected.

@mahesh-naxa
Copy link
Collaborator

I did try the fix by @spwoodcock, i believe this should have also fixed the issue alternatively. But i ran to

    Found existing installation: typing_extensions 4.12.2
    Uninstalling typing_extensions-4.12.2:
      Successfully uninstalled typing_extensions-4.12.2
  Attempting uninstall: setuptools
    Found existing installation: setuptools 52.0.0
    Uninstalling setuptools-52.0.0:
      Successfully uninstalled setuptools-52.0.0
  Attempting uninstall: PyYAML
    Found existing installation: PyYAML 5.3.1
error: uninstall-distutils-installed-package

Γ— Cannot uninstall PyYAML 5.3.1
╰─> It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

I think this could be due to existing python dependencies existing in the host. I have yet to figure this one out.

@mahesh-naxa
Copy link
Collaborator

Since we have python version differences & different use of pdm, i believe there are stuff that still need to be figured out, I am well opting right now to just downgrading:

          'pip install --upgrade pip pdm==2.7.4',
          echo "Downgrade for importlib KeyError on missing keys ref: https://importlib-metadata.readthedocs.io/en/latest/history.html#v8-0-0"
          pip3 install importlib_metadata==v7.2.1 
          'wget -6 https://s3.dualstack.us-east-1.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz -O /tmp/aws-cfn-bootstrap-py3-latest.tar.gz',

Then we can borrow time to decide on upgrading AMI to ubuntu 22.04 for python 3.10 & decide on use of pdm as well.
cc: @spwoodcock @dakotabenjamin @ramyaragupathy

@spwoodcock
Copy link
Member Author

@mahesh-naxa to fix the conflict with PyYaml use the --user flag with pip.
I will update the PR πŸ‘

@spwoodcock
Copy link
Member Author

Nice debugging to find the importlib error πŸ˜„

I would favour the --user fix, as you will have to remember to remove the importlib pin in the future otherwise

@mahesh-naxa
Copy link
Collaborator

Nice debugging to find the importlib error πŸ˜„

I would favour the --user fix, as you will have to remember to remove the importlib pin in the future otherwise

Yeah i agree.
Also @dakotabenjamin can you perform a test run of the commands on one of the unhealthy instance, I don't have access to the shell there. This should give us exactly what we need. **what works.
Also i see there are 8 unhealthy ones running since forever. Can't imagine the aws billing. 😰

@dakotabenjamin
Copy link
Member

dakotabenjamin commented Jun 28, 2024

The install works but I am getting a "Command not found" for the flask command. On the server the bin is /root/.local/bin/ but it's not on the path. Setting that dir on the path fixes it.

@dakotabenjamin dakotabenjamin changed the base branch from develop to main June 28, 2024 14:23
@dakotabenjamin dakotabenjamin changed the base branch from main to develop June 28, 2024 14:24
@dakotabenjamin dakotabenjamin mentioned this pull request Jun 28, 2024
7 tasks
@spwoodcock spwoodcock changed the base branch from develop to main June 28, 2024 15:16
@spwoodcock spwoodcock force-pushed the build/cloudformation-pdm branch from 71f3cc8 to 786fd37 Compare June 28, 2024 15:20
@spwoodcock
Copy link
Member Author

spwoodcock commented Jun 28, 2024

Would adding this be ok?

          'export PATH="/root/.local/bin:$PATH"',

@spwoodcock
Copy link
Member Author

Superseded by #6481

@spwoodcock spwoodcock closed this Jun 28, 2024
@spwoodcock spwoodcock deleted the build/cloudformation-pdm branch June 28, 2024 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants