Skip to main content

A tool for developing Node.js and Python projects

Project description

dotrun

A tool for developing Node.js and Python projects

dotrun makes use of a Docker image to provide a predictable sandbox for running Node and Python projects.

Features:

  • Make use of standard package.json script entrypoints:
    • dotrun runs yarn run start within the Docker container
    • dotrun foo runs yarn run foo within the Docker container
  • Detect changes in package.json and only run yarn install when needed
  • Detect changes in requirements.txt and only run pip3 install when needed
  • Run scripts using environment variables from .env and .env.local files
  • Keep python dependencies in .venv in the project folder for easy access

Usage

$ dotrun          # Install dependencies and run the `start` script from package.json
$ dotrun serve    # Run the python app only
$ dotrun clean    # Delete `node_modules`, `.venv`, `.dotrun.json`, and run `yarn run clean`
$ dotrun install  # Force install node and python dependencies
$ dotrun exec     # Start a shell inside the dotrun environment
$ dotrun exec {command}          # Run {command} inside the dotrun environment
$ dotrun {script-name}           # Install dependencies and run `yarn run {script-name}`
$ dotrun -s {script}             # Run {script} but skip installing dependencies
$ dotrun --env FOO=bar {script}  # Run {script} with FOO environment variable
$ dotrun -m "/path/to/mount":"localname"       # Mount additional directory and run `dotrun`
$ dotrun serve -m "/path/to/mount":"localname" # Mount additional directory and run `dotrun serve`
$ dotrun refresh image # Download the latest version of dotrun-image
$ dotrun --release {release-version} # Use a specific image tag for dotrun. Useful for switching versions
$ dotrun --image {image-name} # Use a specific image for dotrun. Useful for running dotrun off local images
$ dotrun use python 3.8 && dotrun clean && dotrun install # Use a specific python version for dotrun.
  • Note that the --image and --release arguments cannot be used together, as --image will take precedence over --release

Installation

Requirements

  • Docker (Get Docker): on Linux, you can install the Docker snap instead.
  • Python 3.10 or later
  • On MacOS: Homebrew is required
  • curl command-line tool (usually pre-installed on macOS and most Linux distributions)

Linux and MacOS

Quick installation

To install dotrun simply run:

curl -sSL https://raw.githubusercontent.com/canonical/dotrun/main/scripts/install.sh | bash

Verifying the Installation

After installation, you can verify that dotrun is installed correctly by running:

dotrun version

Manual Installation

If you prefer to install manually or encounter any issues with the installation script, you can install dotrun using the following steps:

  1. Install pipx if you haven't already:

    • On macOS: brew install pipx
    • On Linux: Follow the installation instructions for your distribution from the pipx documentation
  2. Ensure pipx is in your PATH:

pipx ensurepath
  1. Install dotrun using pipx:
pipx install dotrun

If you experience problems, please open a GitHub issue.

macOS performance

For optimal performance on Docker we recommend enabling a new experimental file sharing implementation called virtiofs. Virtiofs is only available to users of the following macOS versions:

  • macOS 12.2 and above (for Apple Silicon)
  • macOS 12.3 and above (for Intel)

How to enable virtiofs

Add dotrun on new projects

To fully support dotrun in a new project you should do the following:

  • For Python projects, ensure Talisker is at 0.16.0 or greater in requirements.txt
  • Add .dotrun.json and .venv to .gitignore
  • Create a start script in package.json to do everything needed to set up local development. E.g.: "start": "concurrently --raw 'yarn run watch' 'yarn run serve'"
    • The above command makes use of concurrently - you might want to consider this
  • Older versions of Gunicorn are incompatible with strict confinement so we need Gunicorn >= 20
    • The update landed in Talisker but at the time of writing hasn't made it into a new version
    • If there's no new version of Talisker, simply add gunicorn==20.0.4 to the bottom of requirements.txt

However, once you're ready to completely switch over to dotrun, simply go ahead and remove the run script.

Automated tests of pull requests

The "PR" action builds the Python package and runs a project with dotrun. This will run against every pull request.

Publish

All the changes made to the main branch will be automatically published as a new version on PyPI.

To publish a new version manually, run:

docker buildx create --name mybuilder
docker buildx use mybuilder
docker buildx build --push --platform linux/arm/v7,linux/arm64/v8,linux/amd64 --tag canonicalwebteam/dotrun-image:latest .

Hacking

You can install the package locally using either pip or poetry.

Using pip

pip3 install . requests==2.31.0

Using Poetry

pip install poetry
poetry install --no-interaction

To run dotrun off alternative base images such as local images, you can use the --image flag.

dotrun --image "localimage" exec echo hello

To run dotrun off alternative releases, besides the :latest release, you can use the --release flag.

dotrun --release "latest" serve

Note that before changing the base image you should run

dotrun clean

to get rid of the old virtualenv.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dotrun-2.6.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dotrun-2.6.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file dotrun-2.6.1.tar.gz.

File metadata

  • Download URL: dotrun-2.6.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for dotrun-2.6.1.tar.gz
Algorithm Hash digest
SHA256 eb3d0cea03ac95915308d4d0cfe460fe676363c11c324df9ba604d58d63615bf
MD5 f3fd783d9a84bc54ae819ffef4e9815b
BLAKE2b-256 87d0766e1cc2a7653e7db46fa5682e4af1c9a587be46d30aa5c4a671a3155bcc

See more details on using hashes here.

File details

Details for the file dotrun-2.6.1-py3-none-any.whl.

File metadata

  • Download URL: dotrun-2.6.1-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for dotrun-2.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1e28b6e33cd377b955c50d8da8e63cd97480d3275cbf14cd1264938f4ae6033
MD5 8fccb7956779c193ccf55547f3132caf
BLAKE2b-256 dbfd2f80e4b9be2a96209fae013a85fa0e449500617df5a0b612dbe6a6b4c3dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page