Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remote cluster and platform CLI #94

Merged
merged 54 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
44e5251
feat: add support for platform login, cluster API CRUD methods
fubuloubu Jun 4, 2024
ecf49df
refactor: add workspaces
fubuloubu Jul 9, 2024
caad746
refactor: use different profile types for platform/cluster features
fubuloubu Jul 10, 2024
cb1110d
refactor: remove unused imports
fubuloubu Jul 11, 2024
0ed98fb
fix: add exception for fall-through case
fubuloubu Jul 11, 2024
8628bd3
fix: create dict for writing TOML config file out
fubuloubu Jul 11, 2024
79973a6
refactor: make sure that all commands are ordered by listing
fubuloubu Jul 11, 2024
9045bab
refactor: move `silverback cluster login` to `silverback login`
fubuloubu Jul 11, 2024
de2f8f0
refactor(CLI): Use arguments instead of options for platform
fubuloubu Jul 11, 2024
c65f632
refactor: clearer error handling for cluster client
fubuloubu Jul 11, 2024
7886328
feat(CLI): add cluster status command
fubuloubu Jul 11, 2024
833f032
fix: refine cli errors a bit for cluster optional args
fubuloubu Jul 12, 2024
703e2fc
fix: something weird when initializing this value w/ SQLModel
fubuloubu Jul 15, 2024
63934fd
refactor(cli): use better option defaults, show errors better
fubuloubu Jul 15, 2024
d0217d1
refactor(platform): use IntEnum for ClusterStatus; select values
fubuloubu Jul 15, 2024
46bb083
refactor: use yaml helper
fubuloubu Jul 17, 2024
4e9884f
refactor(cli): re-organize auth so that it we can just use a class
fubuloubu Jul 17, 2024
9e9c14e
refactor: display cluster state in a better way
fubuloubu Jul 17, 2024
cca4aad
feat(cluster): add /env support
fubuloubu Jul 17, 2024
0be9b09
refactor(cli): move `run_broker` helper function to it's own module
fubuloubu Jul 19, 2024
31dc9ad
refactor(cli): refactor platform/cluster client logic into click ext
fubuloubu Jul 19, 2024
63381b5
feat(cli): bot endpoints for cluster mgmt cli
fubuloubu Jul 19, 2024
29b33f0
feat: add ability to create "sections" of commands to help w/readability
fubuloubu Jul 31, 2024
e39cf94
refactor: remove custom yaml render fn
fubuloubu Jul 31, 2024
55f2eee
fix: remove duplicate `verbosity_option` (comes for free now)
fubuloubu Aug 1, 2024
4f4ba02
refactor: remove dynamic cluster option when not needed
fubuloubu Aug 1, 2024
a71d826
docs(cli): refactor help text
fubuloubu Aug 1, 2024
ea6cb42
refactor: don't try to catch client errors, let them raise
fubuloubu Aug 1, 2024
3a514f7
refactor: platform add `/c` to cluster routes by slug
fubuloubu Aug 1, 2024
f0d91f0
refactor: lots of changes; env -> vg, bot -> bots, api updates, hacks…
fubuloubu Aug 1, 2024
df54e64
docs(cli): add autogen docs for `silverback login` and `cluster` cmds
fubuloubu Aug 1, 2024
23ff0bf
docs(cli): clean up the autogen docs for run; add `silverback worker`
fubuloubu Aug 1, 2024
cbf0c75
feat(docs): add documentation for using the Platform and Cluster CLI
fubuloubu Aug 1, 2024
2f5222f
docs(cli): add some metavars and clean up some notes
fubuloubu Aug 1, 2024
ba2678c
docs: update development docs, add link to platform userguide
fubuloubu Aug 1, 2024
f0048c7
fix(cli): Make sure that all platform/cluster/auth commands work
fubuloubu Aug 1, 2024
fdc519c
fix(cli): corner case where it didn't work
fubuloubu Aug 1, 2024
e722166
fix(cli): bad callback, revert
fubuloubu Aug 1, 2024
2850498
feat(cli): show prettier display of config when creating a new cluster
fubuloubu Aug 1, 2024
bf465f8
style: fixup w/ mdformat
fubuloubu Aug 2, 2024
053ac15
refactor(cli): groups -> vargroups
fubuloubu Aug 2, 2024
cfb6f2e
fix: set click object to empty dict if DNE
fubuloubu Aug 2, 2024
efd2563
fix: if `ctx.obj` is empty, handle appropiately
fubuloubu Aug 2, 2024
d4a5d74
refactor(cli): make all confirm conditions exit
fubuloubu Aug 2, 2024
6e0b081
style: black
fubuloubu Aug 2, 2024
c828874
docs(cli): amend names for `silveback run` and `silverback worker`
fubuloubu Aug 2, 2024
5f1bad8
fix(cluster): wrong limit for cpu setting (6 not 16)
fubuloubu Aug 2, 2024
c3f62f9
fix(cluster): handle errors w/ openapi fetch
fubuloubu Aug 2, 2024
f0cab49
feat(cli): allow setting default workspaces and clusters per profile
fubuloubu Aug 2, 2024
46fea60
fix(client): follow redirects w/ cluster
fubuloubu Aug 2, 2024
8d299c8
refactor(client): allow getting latest revision for variable group
fubuloubu Aug 2, 2024
dd87f9e
fix: remove ability to select old variable group revisions
fubuloubu Aug 2, 2024
c1df33c
fix(cli): profile not set in order if `-p` option not provided
fubuloubu Aug 2, 2024
47d24a5
feat(cli): allow selecting default profile in ~/.silverback/profile.toml
fubuloubu Aug 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/commands/cluster.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Cloud Platform
**************

.. click:: silverback._cli:login
:prog: silverback login
:nested: none

.. click:: silverback._cli:cluster
:prog: silverback cluster
:nested: full
:commands: workspaces, new, list, info, health

.. click:: silverback._cli:vars
:prog: silverback cluster vars
:nested: full
:commands: new, list, info, update, remove

.. click:: silverback._cli:bots
:prog: silverback cluster bots
:nested: full
:commands: new, list, info, update, remove, health, start, stop, logs, errors
10 changes: 7 additions & 3 deletions docs/commands/run.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
run
***
Local Development
*****************

.. click:: silverback._cli:run
:prog: run
:prog: silverback run
:nested: none

.. click:: silverback._cli:worker
:prog: silverback worker
:nested: none
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

userguides/quickstart
userguides/development
userguides/platform
```

```{eval-rst}
Expand All @@ -15,6 +16,7 @@
:maxdepth: 1

commands/run.rst
commands/cluster.rst
```

```{eval-rst}
Expand Down
8 changes: 4 additions & 4 deletions docs/userguides/development.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Developing a Silverback Application
# Developing Applications

In this guide, we are going to show you more details on how to build an application with Silverback.

Expand Down Expand Up @@ -182,12 +182,12 @@ export SILVERBACK_RESULT_BACKEND_URI="redis://127.0.0.1:6379"
silverback worker -w 2 "example:app"
```

This will run one client and 2 workers and all queue data will be go through Redis.
The client will send tasks to the 2 worker subprocesses, and all task queue and results data will be go through Redis.

## Testing your Application

TODO: Add backtesting mode w/ `silverback test`

## Deploying to the Silverback Platform
## Deploying your Application

TODO: Add packaging and deployment to the Silverback platform, once available.
Check out the [Platform Deployment Userguide](./platform.html) for more information on how to deploy your application to the [Silverback Platform](https://silverback.apeworx.io).
179 changes: 179 additions & 0 deletions docs/userguides/platform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
# Deploying Applications

In this guide, we are going to show you more details on how to deploy your application to the [Silverback Platform](https://silverback.apeworx.io).

## Creating a Cluster

The Silverback Platform runs your Applications (or "Bots") on dedicated managed application Clusters.
These Clusters will take care to orchestrate infrastructure, monitor, run your triggers, and collect metrics for your applications.
Each Cluster is bespoke for an individual or organization, and isolates your applications from others on different infrastructure.

Before we deploy our Application, we have to create a Cluster.
If you haven't yet, please sign up for Silverback at [https://silverback.apeworx.io](https://silverback.apeworx.io).

Once you have signed up, you can actually create (and pay for) your Clusters from the Silverback CLI utility by first
logging in to the Platform using [`silverback login`][silverback-login],
and then using [`silverback cluster new`][silverback-cluster-new] to follow the steps necessary to deploy it.

```{note}
The Platform UI will let you create and manage Clusters using a graphical experience, which may be preferred.
The CLI experience is for those working locally who don't want to visit the website, or are locally developing their applications.
```

## Connecting to your Cluster

To connect to a cluster, you can use commands from the [`silverback cluster`][silverback-cluster] subcommand group.
For instance, to list all your available bots on your cluster, use [`silverback cluster bots list`][silverback-cluster-bots-list].
To obtain general information about your cluster, just use [`silverback cluster info`][silverback-cluster-info],
or [`silverback cluster health`][silverback-cluster-health] to see the current status of your Cluster.

If you have no bots, we will first have to containerize our Applications and upload them to a container registry that our Cluster is configured to access.

```{note}
Building a container for your application can be an advanced topic, we have included the `silverback build` subcommand to help assist in generating Dockerfiles.
```

## Building your Bot

TODO: Add build process and describe `silverback build --autogen` and `silverback build --upgrade`

TODO: Add how to debug containers using `silverback run` w/ `taskiq-redis` broker

## Adding Environment Variables

Once you have created your bot application container image, you might know of some environment variables the image requires to run properly.
Thanks to it's flexible plugin system, ape plugins may also require specific environment variables to load as well.
Silverback Clusters include an environment variable management system for exactly this purpose,
which you can manage using [`silverback cluster vars`][silverback-cluster-vars] subcommand.

The environment variable management system makes use of a concept called "Variable Groups" which are distinct collections of environment variables meant to be used together.
These variable groups will help in managing the runtime environment of your Applications by allowing you to segregate different variables depending on each bot's needs.

To create an environment group, use the [`silverback cluster vars new`][silverback-cluster-vars-new] command and give it a name and a set of related variables.
For instance, it may make sense to make a group of variables for your favorite Ape plugins or services, such as RPC Providers, Blockchain Data Indexers, Etherscan, etc.
You might have a database connection that you want all your bots to access.
johnson2427 marked this conversation as resolved.
Show resolved Hide resolved

```{warning}
All environment variables in Silverback Clusters are private, meaning they cannot be viewed after they are uploaded.
johnson2427 marked this conversation as resolved.
Show resolved Hide resolved
However, your Bots will have full access to their values from within their runtime environment, so be careful that you fully understand what you are sharing with your bots.

Also, understand your build dependencies within your container and make sure you are not using any vulnerable or malicious packages.

**NEVER** upload your private key in a plaintext format!

Use _Ape Account Plugins_ such as [`ape-aws`](https://github.com/ApeWorX/ape-aws) to safely manage access to your hosted keys.
```

```{note}
The Etherscan plugin _will not function_ without an API key in the cloud environment.
This will likely create errors running your applications if you use Ape's `Contract` class.
```

To list your Variable Groups, use [`silverback cluster vars list`][silverback-cluster-vars-list].
To see information about a specific Variable Group, including the Environment Variables it includes, use [`silverback cluster vars info`][silverback-cluster-vars-info]
To remove a variable group, use [`silverback cluster vars remove`][silverback-cluster-vars-remove],

```{note}
You can only remove a Variable Group if it is not referenced by any existing Bot.
```

Once you have created all the Variable Group(s) that you need to operate your Bot, you can reference these groups by name when adding your Bot to the cluster.

## Deploying your Bot

You are finally ready to deploy your bot on the Cluster and get it running!

To deploy your Bot, use the [`silverback cluster bots new`][silverback-cluster-bots-new] command and give your bot a name,
container image, network to run on, an account alias (if you want to sign transactions w/ `app.signer`),
and any environment Variable Group(s) the bot needs.
If everything validates successfully, the Cluster will begin orchestrating your deployment for you.

You should monitor the deployment and startup of your bot to make sure it enters the RUNNING state successfully.
You can do this using the [`silverback cluster bots health`][silverback-cluster-bots-health] command.

```{note}
It usually takes a minute or so for your bot to transition from PROVISIONING to STARTUP to the RUNNING state.
If there are any difficulties in downloading your container image, provisioning your desired infrastructure, or if your application encounters an error during the STARTUP phase,
the Bot will not enter into the RUNNING state and will be shut down gracefully into the STOPPED state.

Once in the STOPPED state, you can make any adjustments to the environment Variable Group(s) or other runtime parameters in the Bot config;
or, you can make code changes and deploy a new image for the Bot to use.
Once ready, you can use the `silverback cluster bots start` command to re-start your Bot.
```

If at any time you want to view the configuration of your bot, you can do so using the [`silverback cluster bots info`][silverback-cluster-bots-info] command.
You can also update metadata or configuration of your bot using the [`silverback cluster bots update`][silverback-cluster-bots-update] command.
Lastly, if you want to shutdown and delete your bot, you can do so using the [`silverback cluster bots remove`][silverback-cluster-bots-remove] command.

```{note}
Configuration updates do not redeploy your Bots automatically, you must manually stop and restart your bots for changes to take effect.
```

```{warning}
Removing a Bot will immediately trigger a SHUTDOWN if the Bot is not already STOPPED.
```

## Monitoring your Bot

Once your bot is successfully running in the RUNNING state, you can monitor your bot with a series of commands
under the [`silverback cluster bots`][silverback-cluster-bots] subcommand group.
We already saw how you can use the [`silverback cluster bots list`][silverback-cluster-bots-list] command to see all bots managed by your Cluster (running or not).

To see runtime health information about a specific bot, again use the [`silverback cluster bots health`][silverback-cluster-bots-health] command.
You can view the logs that a specific bot is generating using the [`silverback cluster bots logs`][silverback-cluster-bots-logs] command.
Lastly, you can view unacknowledged errors that your bot has experienced while in the RUNNING state
using the [`silverback cluster bots errors`][silverback-cluster-bots-errors] command.

```{warning}
Once in the RUNNING state, your Bot will not stop running unless it experiences a certain amount of errors in quick succession.
Any task execution that experiences an error will abort execution (and therefore not produce any metrics) but the Bot **will not** shutdown.

All errors encountered during task exeuction are reported to the Cluster for later review by any users with appriopiate access.
Tasks do not retry (by default), but updates to `app.state` are maintained up until the point an error occurs.

It is important to keep track of these errors and ensure that none of them are in fact critical to the operation of your Application,
and to take corrective or preventative action if it is determined that it should be treated as a more critical failure condition.
```

```{note}
Your Bots can also be monitored from the Platform UI at [https://silverback.apeworx.io](https://silverback.apeworx.io).
```

## Controlling your Bot

As we already saw, once a Bot is configured in a Cluster, we can control it using commands from the [`silverback cluster bots`][silverback-cluster-bots] subcommand group.
For example, we can attempt to start a Bot that is not currently running (after making configuration or code changes)
using the [`silverback cluster bots start`][silverback-cluster-bots-start] command.
We can also stop a bot using [`silverback cluster bots stop`][silverback-cluster-bots-stop] that is currently in the RUNNING state if we desire.

```{note}
Controlling your bots can be done from the Platform UI at [https://silverback.apeworx.io](https://silverback.apeworx.io), if you have the right permissions to do so.
```

TODO: Updating runtime parameters

## Viewing Measured Metrics

TODO: Downloading metrics from your Bot

[silverback-cluster]: ../commands/cluster.html#silverback-cluster
[silverback-cluster-bots]: ../commands/cluster.html#silverback-cluster-bots
[silverback-cluster-bots-errors]: ../commands/cluster.html#silverback-cluster-bots-errors
[silverback-cluster-bots-health]: ../commands/cluster.html#silverback-cluster-bots-health
[silverback-cluster-bots-info]: ../commands/cluster.html#silverback-cluster-bots-info
[silverback-cluster-bots-list]: ../commands/cluster.html#silverback-cluster-bots-list
[silverback-cluster-bots-logs]: ../commands/cluster.html#silverback-cluster-bots-logs
[silverback-cluster-bots-new]: ../commands/cluster.html#silverback-cluster-bots-new
[silverback-cluster-bots-remove]: ../commands/cluster.html#silverback-cluster-bots-remove
[silverback-cluster-bots-start]: ../commands/cluster.html#silverback-cluster-bots-start
[silverback-cluster-bots-stop]: ../commands/cluster.html#silverback-cluster-bots-stop
[silverback-cluster-bots-update]: ../commands/cluster.html#silverback-cluster-bots-update
[silverback-cluster-health]: ../commands/cluster.html#silverback-cluster-health
[silverback-cluster-info]: ../commands/cluster.html#silverback-cluster-info
[silverback-cluster-new]: ../commands/cluster.html#silverback-cluster-new
[silverback-cluster-vars]: ../commands/cluster.html#silverback-cluster-vars
[silverback-cluster-vars-info]: ../commands/cluster.html#silverback-cluster-vars-info
[silverback-cluster-vars-list]: ../commands/cluster.html#silverback-cluster-vars-list
[silverback-cluster-vars-new]: ../commands/cluster.html#silverback-cluster-vars-new
[silverback-cluster-vars-remove]: ../commands/cluster.html#silverback-cluster-vars-remove
[silverback-login]: ../commands/cluster.html#silverback-login
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
"packaging", # Use same version as eth-ape
"pydantic_settings", # Use same version as eth-ape
"taskiq[metrics]>=0.11.3,<0.12",
"tomlkit>=0.12,<1", # For reading/writing global platform profile
"fief-client[cli]>=0.19,<1", # for platform auth/cluster login
],
entry_points={
"console_scripts": ["silverback=silverback._cli:cli"],
Expand Down
Loading
Loading