Dependency Registries

While using external packages with your services, it may be necessary to use a private registry. torero supports specifying PyPi and Ansible-galaxy registries for use with your Python and Ansible services.

Default Registries

torero comes with a default registry for both PyPi and Ansible Galaxy. The default for PyPi is called default-pypi and points at the public repository of https://pypi.org/simple. The default Ansible Galaxy registry is called default-galaxy and points at https://galaxy.ansible.com.

You can delete these registries if you wish. This will then allow you to create a new default registry via the torero create registry command and specifying the --default flag.

Creating a Registry Resource

torero allows you to create a registry resource to specify information about them. An example command used to create a resource would be

>_ torero create registry pypi my-pypi-registry --url 'http://private-repo-hostname:8080/simple' --username admin --password-name pip-password

This will create a Python pypi registry resource named my-pypi-registry that has a URL of http://private-repo-hostname:8080/simple and uses the username of admin. The password field is a reference to the name of a torero secret resource with a name of pip-password. For more information on creating secrets, see the torero create secret documentation.

Now, let's consider an example torero-resources repository that contains a Python script with dependencies that need to be fetched from our private repository specified in a requirements.txt file.

torero-resources (git repo)

├── README.md
├── ansibleplaybooks
├── pythonscripts
│   ├── main.py
│   └── requirements.txt
└── opentofuplans

We can create a Python script service as we normally would, but now specifying the private registry my-pypi-registry we created earlier.

>_ torero create service python-script my-py-service --filename main.py --repository t-scripts --working-dir pythonscripts --registry my-pypi-registry

Now, when the service is executed, torero will use the specified registry to fetch the dependencies listed in the requirements.txt file. This can be easily observed if the configuration variable TORERO_LOG_LEVEL is set to DEBUG or lower. e.g.

2024-11-26T01:04:08Z DBG running command '/Users/torerouser/.torero.d/venv/c4dcfa07a05afcf50a8f10a5f92106661a1b8815/bin/pip3 install -r /Users/torerouser/.torero.d/venv/c4dcfa07a05afcf50a8f10a5f92106661a1b8815/requirements.txt --index-url http://admin:****@private-repo-hostname:8080/simple'
2024-11-26T01:04:09Z DBG command exit status: 0, execution time: 815.119678ms
2024-11-26T01:04:09Z DBG pip dependency install succeeded.
Stdout:
Looking in indexes: http://admin:****@private-repo-hostname:8080/simple
Collecting isOdd (from -r /Users/torerouser/.torero.d/venv/c4dcfa07a05afcf50a8f10a5f92106661a1b8815/requirements.txt (line 1))
  Downloading http://private-repo-hostname:8080/packages/isOdd-0.1.2-py3-none-any.whl (1.8 kB)

If you would like to disable overriding the default registry, you can set the configuration variable TORERO_REGISTRY_DEFAULT_OVERRIDABLE to false.

That's it! Ansible Galaxy repositories can be specified in the same way as PyPi registries.