यह मानते हुए कि आपने पायथन 3.6, Pipenv और हेरोकू CLI स्थानीय रूप से सेट अप कर लिया है और यहां बताए गए चरणों का उपयोग करके हेरोकू CLI से लॉग इन हैं: https://devcenter.heroku.com/articles/getting-started-with-python#set-up।
पूर्वापेक्षाएं
- आपके एप्लिकेशन का एक Git रिपॉजिटरी होना चाहिए
- अपने Git रिपॉजिटरी कोड के रूट वाली डायरेक्टरी में `cd` करें
हेरोकू एप्लिकेशन बनाएं
$ heroku create
Creating lit-bastion-5032 in organization heroku... done, stack is cedar-14
https://lit-bastion-5032.herokuapp.com/ | https://git.heroku.com/lit-bastion-5032.git
Git remote heroku added
जब आप एक ऐप बनाते हैं, तो एक Git रिमोट (जिसे `heroku` कहा जाता है) भी बनाया जाता है और आपके स्थानीय Git रिपॉजिटरी से जुड़ा होता है। हेरोकू आपके ऐप के लिए एक रैंडम नाम (इस मामले में `lit-bastion-5032`) उत्पन्न करता है, या आप अपना खुद का ऐप नाम निर्दिष्ट करने के लिए एक पैरामीटर पास कर सकते हैं।
कोड पुश करें
$ git push heroku master
Counting objects: 232, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (217/217), done.
Writing objects: 100% (232/232), 29.64 KiB | 0 bytes/s, done.
Total 232 (delta 118), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing python-3.6.0
remote: -----> Installing requirements with latest pipenv...
remote: Installing dependencies from Pipfile.lock...
remote: $ python manage.py collectstatic --noinput
remote: 58 static files copied to '/app/gettingstarted/staticfiles', 58 post-processed.
remote:
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing...
remote: Done: 39.3M
remote: -----> Launching...
remote: Released v4
remote: https://lit-bastion-5032.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To git@heroku.com:lit-bastion-5032.git
* [new branch] master -> master
आवश्यकताएं निर्दिष्ट करें
ध्यान दें कि आपको अपनी आवश्यकताओं (थर्ड-पार्टी मॉड्यूल जिन्हें आप इम्पोर्ट कर रहे हैं) को उनके संस्करण संख्या के साथ `requirements.txt` में निर्दिष्ट करने की आवश्यकता है (या बिना यदि आपको नवीनतम चाहिए)। उदाहरण के लिए:
Flask==0.8
Jinja2==2.6
Werkzeug==0.8.3
certifi==0.0.8
chardet==1.0.1
आधुनिक हेरोकू डिप्लॉयमेंट (2024+)
1. पायथन रनटाइम निर्दिष्ट करें (runtime.txt)
python-3.11.6
2. Procfile
web: gunicorn myapp:app
# या Django के लिए
web: gunicorn myproject.wsgi
3. Pipenv / Poetry / uv
# Pipfile (Pipenv)
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
django = "*"
gunicorn = "*"
[dev-packages]
pytest = "*"
[requires]
python_version = "3.11"
4. GitHub Actions से ऑटो-डिप्लॉय
# .github/workflows/deploy.yml
name: Deploy to Heroku
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: akhileshns/heroku-deploy@v3.12.12
with:
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_app_name: my-app
heroku_email: user@example.com
5. हेरोकू कंटेनर रजिस्ट्री (Docker)
heroku container:login
heroku container:push web -a my-app
heroku container:release web -a my-app
मुख्य फ़ाइलें चेकलिस्ट
| फ़ाइल | आवश्यक | उद्देश्य |
|---|---|---|
| requirements.txt / Pipfile / pyproject.toml | हां | निर्भरता |
| Procfile | हां | प्रोसेस प्रकार घोषित करें |
| runtime.txt | वैकल्पिक | पायथन संस्करण पिन करें |
| .python-version | वैकल्पिक | पायथन संस्करण (वैकल्पिक) |
अधिक जानकारी
हेरोकू पायथन डॉक्स पर अधिक पढ़ें: https://devcenter.heroku.com/articles/python-pip