Skip to main content

Deploy Rookout on a Python container

This short tutorial will walk you through the perfect Rookout deployment for containerized Python applications in three quick steps.

Get Your Application

First things first, choose an application. If you don't have one readily available, use our sample application.

Start by:


git clone https://github.com/Rookout/python-tutorial-2022
cd python-tutorial-2022

1. Add the Python Package

Rookout for Python is a public PyPI Package. Add rook as a dependency to your requirements.txt file, pipenv configuration, or pip CLI.


pip install rook

2. Start Rookout

Load and start the package to connect to your Rookout account (if you haven't signed up, do that here).

The best place to do that is at the beginning of your main function or the bottom of the global scope in your main file (in our case - run.py):


import rook
rook.start(
token="[Your Rookout Token]",
labels={"env": "dev"}
)

Configuration is where you can get fancy. You have got additional options up your sleeve:

  1. Move options to secret or configuration managers.
  2. If you are using Rookout's hybrid architecture, set up the controller's host configuration.
  3. Dig deeper into other options available right here.

3. Embed Source Information

Rookout offers the smoothest debugging experience by fetching up-to-date source code for each server.

Set this up for containerized applications by adding a handful of files from your .git folder to the container image.

Edit (or add) your .Dockerignore file and adapt the traditional .git exclude:


# Keep ignoring .git
.git
# Allow specific files with !
!.git/HEAD
!.git/config
!.git/refs

Add a final COPY command to the Dockerfile.


COPY .git /.git

Note: in multi-stage builds, make all your changes on the final stage.

Test

One second! if you are not using our demo app, please commit and push your changes to a new branch.

Build and run your Docker image:


docker build . -t rookout-python-todo
docker run -it -p 8080:8080 rookout-python-todo

As your Python application spins up, search for this output at the top:

Interact with your application at http://localhost:8080 and use Rookout to debug it on the fly!

Questions?

  1. Check out this reference implementation.
  2. Dig into our Python docs.
  3. Reach out to us via chat or email.