Automate creation of Nextflow Tower resources
Project description
twkit
twkit is a Python wrapper for the Nextflow Tower CLI. It can be leveraged to automate the creation of all of the entities in Nextflow Tower via a simple configuration file in YAML format.
The key features are:
- Simple configuration: All of the command-line options available when using the Nextflow Tower CLI can be defined in simple YAML format.
- Infrastructure as Code: Enable users to manage and provision their infrastructure specifications.
- Automation: End-to-end creation of entities within Nextflow Tower, all the way from adding an Organization to launching pipeline(s) within that Organization.
Prerequisites
You will need to have an account on Nextflow Tower (see Plans and pricing).
1. Dependencies
twkit requires the following dependencies:
Alternatively, you can install the dependencies via Conda by downloading and using the Conda environment file that has been supplied in this repository:
conda env create -f environment.yml
conda activate twkit
2. Installation
The scripts in this repository are packaged and available on PyPI. They can be installed via pip:
pip install twkit
You can force overwrite the installation to use the latest changes with the command below:
pip install --upgrade --force-reinstall twkit
3. Configuration
Create a Tower access token using the Nextflow Tower web interface via the Your Tokens page in your profile.
twkit reads this token from the environment variable TOWER_ACCESS_TOKEN. Please export it into your terminal as shown below:
export TOWER_ACCESS_TOKEN=<your access token>
Usage
Use the -h or --help parameter to list the available commands and their associated options:
twkit -h
Dryrun
To print the commands that would executed with tw when using a YAML file, you can run twkit with the --dryrun flag:
twkit file.yaml --dryrun
Recursively delete
Instead of adding or creating resources, you can recursively delete resources in your YAML file by specifying the --delete flag:
twkit file.yaml --delete
For example, if you have a YAML file that defines an Organization -> Workspace -> Team -> Credentials -> Compute Environment that have already been created, with the --delete flag, twkit will recursively delete the Compute Environment -> Credentials -> Team -> Workspace -> Organization.
Using tw specific CLI options
tw specific CLI options can be specified with the --cli= flag:
twkit file.yaml --cli="--arg1 --arg2"
You can find the full list of options by running tw -h.
The Tower CLI expects to connect to a Tower instance that is secured by a TLS certificate. If your Tower instance does not present a certificate, you will need to qualify and run your tw commands with the --insecure flag.
To use tw specific CLI options such as --insecure, use the --cli= flag, followed by the options you would like to use enclosed in double quotes.
For example:
twkit file.yaml --cli="--insecure"
To use an SSL certificate that is not accepted by the default Java certificate authorities and specify a custom cacerts store as accepted by the tw CLI, you can specify the -Djavax.net.ssl.trustStore=/absolute/path/to/cacerts option enclosed in double quotes to twkit as you would to tw, preceded by --cli=.
For example:
twkit hello-world-config.yml --cli="-Djavax.net.ssl.trustStore=/absolute/path/to/cacerts"
Note: Use of --verbose option for the tw CLI is currently not supported by twkit. Supplying --cli="--verbose" will raise an error.
Quick start
You must provide a YAML file that defines the options for each of the entities you would like to create in Nextflow Tower.
You will need to have an account on Nextflow Tower (see Plans and pricing). You will also need access to a Workspace and a pre-defined Compute Environment where you can launch a pipeline.
Launch via YAML
-
Create a YAML file called
hello-world-config.ymlwith the contents below, and customise the<YOUR_WORKSPACE>and<YOUR_COMPUTE_ENVIRONMENT>entries as required:launch: - name: 'hello-world' # Workflow name workspace: '<YOUR_WORKSPACE>' # Workspace name compute-env: '<YOUR_COMPUTE_ENVIRONMENT>' # Compute environment revision: 'master' # Pipeline revision pipeline: 'https://github.com/nextflow-io/hello' # Pipeline URL -
Launch the pipeline with
twkit:twkit hello-world-config.yml -
Login to your Tower instance and check the Runs page in the appropriate Workspace for the pipeline you just launched!
Launch via a Python script
You can also launch the same pipeline via a Python script. This will essentially allow you to extend the functionality on offer within the Tower CLI by leveraging the flexibility and customisation options available in Python.
-
Download the
launch_hello_world.pyPython script and customise the<YOUR_WORKSPACE>and<YOUR_COMPUTE_ENVIRONMENT>entries as required. -
Launch the pipeline with
twkit:python launch_hello_world.py -
Login to your Tower instance and check the Runs page in the appropriate Workspace for the pipeline you just launched!
Real world example
Please see twkit-e2e.yml for an end-to-end example that highlights how you can use twkit to create everything sequentially in Nextflow Tower all the way from creating a new Organization to launching a pipeline.
You can modify this YAML to similarly create Nextflow Tower resources end-to-end for your setup. This YAML encodes environment variables to protect sensitive keys, usernames, and passwords that are required to create or add certain resources (i.e. credentials, compute environments). Prior to running it with twkit examples/yaml/twkit-e2e.yml, you will have to set the following environment variables:
$TOWER_GITHUB_PASSWORD
$DOCKERHUB_PASSWORD
$AWS_ACCESS_KEY_ID
$AWS_SECRET_ACCESS_KEY
$AWS_ASSUME_ROLE_ARN
$AZURE_BATCH_KEY
$AZURE_STORAGE_KEY
$GOOGLE_KEY
$SENTIEON_LICENSE_BASE64
Templates
We have provided template YAML files for each of the entities that can be created on Tower. These can be found in the templates/ directory and should form a good starting point for you to add your own customization:
- organizations.yml
- teams.yml
- workspaces.yml
- participants.yml
- credentials.yml
- secrets.yml
- compute-envs.yml
- actions.yml
- datasets.yml
- pipelines.yml
- launch.yml
Contributions and Support
If you would like to contribute to twkit, please see the contributing guidelines.
For further information or help, please don't hesitate to create an issue in this repository.
Credits
twkit was written by Esha Joshi, Adam Talbot and Harshil Patel from the Scientific Development Team at Seqera Labs.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file twkit-0.3.0.tar.gz.
File metadata
- Download URL: twkit-0.3.0.tar.gz
- Upload date:
- Size: 36.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
512174263599de840684aa33b61893bc36f1a0dc56da38975e004365cc3fecfb
|
|
| MD5 |
e7d567e34e1b2f2916d38460ebc6cec4
|
|
| BLAKE2b-256 |
b4cb7450626ac3411c3d5a45f7a277c61bbc26880ceea3d5fed78ca5e44d0cbe
|
File details
Details for the file twkit-0.3.0-py3-none-any.whl.
File metadata
- Download URL: twkit-0.3.0-py3-none-any.whl
- Upload date:
- Size: 24.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1e4274ea96ebbe47c495e72c58b2ca265a17102a76d66f29f06a80c25047432
|
|
| MD5 |
18b00d9ae2710f98b49336a4a40fcc82
|
|
| BLAKE2b-256 |
bb975adbafe1da542d5eb6610d09f4cf2533dfd40622911a534ffd0d0089731c
|