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

Deploy app on Heroku using Poetry #403

Closed
2 tasks done
karantan opened this issue Aug 22, 2018 · 18 comments
Closed
2 tasks done

Deploy app on Heroku using Poetry #403

karantan opened this issue Aug 22, 2018 · 18 comments

Comments

@karantan
Copy link

  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have searched the documentation and believe that my question is not covered.

Question

Let say you have a simple Flask web app but instead of using pipenv (or regular pip + requirements.txt) I want to use poetry. How do I deploy this app on heroku?

With pipenv it is easy because there already exists a buildpack for pipenv but it does not for poetry.

@jacebrowning
Copy link
Contributor

jacebrowning commented Sep 5, 2018

IMO, the best solution would be to update the Python buildpack to key off poetry.lock then run poetry commands. I'll see if I can put something together.

@yunti
Copy link

yunti commented Sep 18, 2018

This would work too #100

@nmunro
Copy link

nmunro commented Nov 17, 2018

I have a more general solution to this, if I may, I had begun working on a patch, but I'm still familiarising myself with the poetry package.

We need to use pip directly on EC2 instances and I threw together a solution to generate a traditional requirements.txt file, but using a make rule, ideally a command to regenerate a standard requirements.txt file for use with heroku/aws etc would be a good way to integrate quickly and easily with existing services etc, I wrote up kinda what we're doing here: http://neilmunro.herokuapp.com/blog/python_development_and_production_workflow

Something like:

poetry export-requirements --no-deps

@zyv
Copy link
Contributor

zyv commented Nov 26, 2018

Yet another pipenv refugee here... Would be great to have an analog to pipenv lock -r in poetry. This is what we are currently using for our Heroku deployments.

In the meantime, we are thinking of running pip freeze in poetry shell and filtering out the current project with grep, but native support for pipenv lock -r would be much appreciated. Thanks!

@sdispater
Copy link
Member

An export command is currently being worked on which will make exporting the lock file to other formats (requirements.txt being the only one for now) possible.

@zyv
Copy link
Contributor

zyv commented Nov 26, 2018

@sdispater sounds awesome! Would be great if that export command supported filtering dependencies by type (i.e. to be able to automatically filter out dev dependencies), and custom index sources. These are both pipenv features that we are currently using to generate our requirements.txt for Heroku.

@zyv
Copy link
Contributor

zyv commented Nov 29, 2018

Merged in develop in #675, yay! 👍 Will be testing when it hits the next release.

@woile
Copy link

woile commented Jan 27, 2019

Hey folks, could someone summarize the steps to deploy using poetry?
Thanks!

@zyv
Copy link
Contributor

zyv commented Jan 27, 2019

@woile the feature has been merged in develop, but, unfortunately, still not released :(

In the meantime, we use an internal tool that we have written to the same effect, which parses the lock-file and outputs requirements.txt for Heroku...

@jacebrowning
Copy link
Contributor

jacebrowning commented Jan 27, 2019

@woile If you don't care about leveraging Heroku's dependency cache, the following works for a Django project using the default Python buildpack:

requirements.txt

poetry==1.0.2

bin/post_compile

#!/usr/bin/env bash

set -eo pipefail

indent() {
  sed "s/^/       /"
}

puts-step() {
  echo "-----> $@"
}

puts-step "Installing dependencies with poetry..."
poetry config virtualenvs.create false 2>&1 | indent
poetry install --no-dev 2>&1 | indent

puts-step "Collecting static files..."
python manage.py collectstatic --no-input 2>&1 | indent

@sdispater
Copy link
Member

The export command is available in the 1.0.0 latest pre release

@joshfriend
Copy link

@jacebrowning i disagree with how heroku's dependency cache works anyways, so this is actually OK with me 😆

@CptSpaceToaster
Copy link

CptSpaceToaster commented Jul 31, 2019

Using Poetry 0.12.17, my install would fail, mentioning something about pip._vendor.urllib3.packages.rfc3986 when specifying a python-3.7.3 runtime.

I modified my install for a flask-app to allow poetry to keep its virtual env, but just in the repo

requirements.txt

poetry==0.12.17

bin/post_compile

#!/usr/bin/env bash

set -eo pipefail

indent() {
  sed "s/^/       /"
}

puts-step() {
  echo "-----> $@"
}

puts-step "Installing dependencies with poetry..."
# Use a venv, but install locally
poetry config settings.virtualenvs.in-project true 2>&1 | indent
poetry install --no-dev 2>&1 | indent

# Not using Django
# puts-step "Collecting static files..."
# python manage.py collectstatic --no-input 2>&1 | indent

This requires the Procfile to be mangled, as the script to launch gunicorn (.venv/bin/gunicorn) I needed wasn't receiving a functional hashbang

Procfile

web: .venv/bin/python3 .venv/bin/gunicorn package:flask_app

@herrbenesch
Copy link

herrbenesch commented Dec 21, 2019

I got it working (for poetry 1.0.0) by adding bin/pre_compile with the content

# Get poetry from source
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python
# Make poetry available to $PATH
source $HOME/.poetry/env
# Export poetry packages to requirements.txt to be used for installing the pipy packages
poetry export -f requirements.txt -o requirements.txt

pre_compile will be made executable by the buildpack:

@CptSpaceToaster
Copy link

CptSpaceToaster commented Dec 21, 2019

Now that poetry 1.0.0 is out, you can run poetry export. If you you have a pre-1.0.0 release, you'll still need a work around.

@laike9m
Copy link
Contributor

laike9m commented Jan 27, 2020

poetry config settings.virtualenvs.create false 2>&1 | indent

@jacebrowning

As of Poetry 1.0,

poetry config settings.virtualenvs.create false

has changed to

poetry config virtualenvs.create false

Could you help update it to help future readers? Also, it's better to use --local because you don't want to affect other projects.

@zyv
Copy link
Contributor

zyv commented Feb 1, 2020

FYI, we've eventually created a buildpack and moved to Poetry also on Heroku:

https://github.com/moneymeets/python-poetry-buildpack

/cc @marns93

Copy link

github-actions bot commented Mar 3, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests