How to Set Up Python Deployment with .travis.yml?

Estimated read time 2 min read

To set up Python deployment with .travis.yml, you need to follow these steps:

  1. Sign up for a Travis CI account if you haven’t already: https://travis-ci.com/
  2. Create a new GitHub repository for your Python project.
  3. Create a .travis.yml file in the root directory of your project.
  4. Open the .travis.yml file and add the following lines to specify the Python version and install any necessary packages:
language: python
python:
  - "3.9"

install:
  - pip install -r requirements.txt

Note: Replace "3.9" with the Python version you want to use, and "requirements.txt" with the name of your requirements file if you have one.

  1. If you need to run any tests, add the following lines to your .travis.yml file:
script:
  - python tests.py

Note: Replace tests.py with the name of your test file.

  1. Add the following lines to your .travis.yml file to specify how Travis CI should deploy your application:
deploy:
  provider: heroku
  api_key:
    secure: <your encrypted API key>
  app: <your Heroku app name>
  on:
    branch: main

Note: Replace <your encrypted API key> with the encrypted API key for your Heroku account. You can generate an encrypted API key using the Travis CI command-line tool. Replace <your Heroku app name> with the name of your Heroku app.

  1. Encrypt your Heroku API key using the Travis CI command-line tool:
  • Install the Travis CI command-line tool if you haven’t already: gem install travis
  • Open a terminal window and navigate to your project directory.
  • Type the following command: travis encrypt $(heroku auth:token) --add deploy.api_key

Note: This command encrypts your Heroku API key and adds it to the .travis.yml file.

  1. Commit the .travis.yml file to your Git repository and push the changes to GitHub.
  2. Log in to your Travis CI account and enable Travis CI for your project.

That’s it! Travis CI will now automatically run your tests and deploy your application to Heroku when you push changes to the main branch of your GitHub repository.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply