|
| 1 | +# Example using SkyPilot python API to run the echo app in a container. |
| 2 | +# |
| 3 | +# The echo example ingests a file, prints the contents and writes it back out. |
| 4 | +# In this YAML, the output is mapped to a Sky Storage object, which writes to a |
| 5 | +# cloud bucket. |
| 6 | +# |
| 7 | +# Usage: |
| 8 | +# python echo_app.py |
| 9 | + |
| 10 | +import random |
| 11 | +import sky |
| 12 | +import string |
| 13 | + |
| 14 | +with sky.Dag() as dag: |
| 15 | + # The setup command to build the container image |
| 16 | + setup = 'docker build -t echo:v0 /echo_app' |
| 17 | + |
| 18 | + # The command to run - runs the container and mounts volumes |
| 19 | + run = ('docker run --rm --volume="/inputs:/inputs:ro" ' |
| 20 | + '--volume="/outputs:/outputs:rw" ' |
| 21 | + 'echo:v0 /inputs/README.md /outputs/output.txt') |
| 22 | + |
| 23 | + echo_app = sky.Task( |
| 24 | + setup=setup, |
| 25 | + run=run, |
| 26 | + ) |
| 27 | + |
| 28 | + # Configure file mounts to copy local contents to remote |
| 29 | + echo_app.set_file_mounts({ |
| 30 | + '/inputs': './echo_app', |
| 31 | + '/echo_app': './echo_app', |
| 32 | + }) |
| 33 | + |
| 34 | + # Configure outputs for the task - we'll write to a bucket using Sky Storage |
| 35 | + output_bucket_name = ''.join(random.choices(string.ascii_lowercase, k=15)) |
| 36 | + output_storage = sky.Storage(name=output_bucket_name, |
| 37 | + mode=sky.StorageMode.MOUNT) |
| 38 | + echo_app.set_storage_mounts({ |
| 39 | + '/outputs': output_storage, |
| 40 | + }) |
| 41 | + |
| 42 | + # Set resources if required |
| 43 | + # echo_app.set_resources({ |
| 44 | + # sky.Resources(accelerators='V100'), |
| 45 | + # }) |
| 46 | + |
| 47 | +sky.launch(dag) |
| 48 | + |
| 49 | +print('Remember to clean up resources after this script is done!\n' |
| 50 | + 'Run sky status and sky storage ls to list current resources.\n' |
| 51 | + 'Run sky down <cluster_name> and sky storage delete <storage_name> to ' |
| 52 | + 'delete resources.') |
0 commit comments