-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3aa39d
commit 5e1bf41
Showing
1 changed file
with
47 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,71 @@ | ||
# CI On Modal | ||
# Run Continuous Integration Tests on Modal | ||
|
||
This repo is a demonstration of one pattern for running tests on Modal: | ||
bring your existing test suite and package (e.g. `my_pkg`), and add a Modal App (`my_pkg.ci`) and function (`.pytest`) that | ||
bring your existing package and test suite (here `my_pkg` and `tests`) | ||
and add a Modal App (`my_pkg.ci`) | ||
that mounts your tests | ||
and a Function (`pytest`) runs `pytest`. | ||
|
||
1. imports the code you want to test | ||
2. mounts your tests | ||
3. runs `pytest` | ||
That's as straightforward as | ||
|
||
```python | ||
# my_pkg/ci.py | ||
tests = modal.Mount.from_local_dir("path/to/tests", remote_path="/root/tests") | ||
|
||
|
||
@app.function(gpu="any", mounts=[tests]) | ||
def pytest(): | ||
import subprocess | ||
|
||
subprocess.run(["pytest", "-vs"], check=True, cwd="/root") | ||
``` | ||
|
||
## Setup | ||
|
||
- Create Python virtual environment | ||
- Create a Python virtual environment | ||
- `pip install modal` | ||
- That's it 😎 | ||
|
||
## Usage | ||
|
||
All commands below are run from the root of the repository. | ||
|
||
### Run tests remotely on Modal | ||
|
||
This can be executed from inside another, cheaper CI runner, e.g. on GitHub Actions. | ||
|
||
```bash | ||
modal run my_pkg.ci | ||
``` | ||
|
||
### Debug remote testing environment | ||
On the first execution, the [container image](https://modal.com/docs/guide/custom-container) | ||
for your application will be built. | ||
|
||
This image will be cached on Modal and only rebuilt if one of its dependencies, | ||
like the `requirements.txt` file, changes. | ||
|
||
### Run tests on Modal from GitHub Actions | ||
|
||
The same command can be executed from inside a CI runner on another platform. | ||
We provide a sample GitHub Actions workflow in `.github/workflows/ci.yml`. | ||
|
||
To run these tests on GitHub Actions, fork this repo and | ||
[create a new GitHub Actions secret](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions) | ||
that contains your `MODAL_TOKEN_ID` and `MODAL_TOKEN_SECRET`. | ||
You can find this info in the `.modal.toml` file in your home directory. | ||
|
||
Now you can [manually trigger the tests to run on GitHub Actions](https://docs.github.com/en/actions/using-workflows/manually-running-a-workflow) | ||
or trigger them by making a change on our fork and pushing to `main` or making a pull request. | ||
|
||
### Debug tests running remotely | ||
|
||
To debug the tests, you can open a shell | ||
in the exact same environment that the tests are run in: | ||
|
||
```bash | ||
modal shell my_pkg.ci | ||
``` | ||
|
||
I used the `shell` feature heavily while developing this pattern! | ||
We used the `shell` feature heavily while developing this pattern! | ||
|
||
_Note_: On the Modal worker, the `pytest` command is run from the home directory, `/root`, which contains the `tests` folder. | ||
_Note_: On the Modal worker, the `pytest` command is run from the home directory, `/root`, | ||
which contains the `tests` folder, but the `modal shell` command will | ||
drop you at the top of the filesystem, `/`. |