Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 2 additions & 3 deletions internal/cmd/serverless/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,8 @@ func newVolumesPutCmd(logger *log.Logger) *cobra.Command {
return printPutSummary(cmd.OutOrStdout(), cmdutil.FormatFor(cmd), summary)
},
}
cmd.Flags().StringVar(&to, toFlag, "", "Directory in the Volume the paths land under (default the Volume root)")
cmd.Flags().IntVar(&concurrency, concurrencyFlag, put.DefaultParallelism,
fmt.Sprintf("Parts to upload at once (1-%d); each part in flight holds about 1 MiB of memory", put.MaxParallelism))
cmd.Flags().StringVar(&to, toFlag, "", "Volume directory to upload under (default the root)")
cmd.Flags().IntVar(&concurrency, concurrencyFlag, put.DefaultParallelism, fmt.Sprintf("Parts to upload at once (1-%d)", put.MaxParallelism))
addVolumeEnvironmentFlag(cmd, logger)
return cmd
}
Expand Down
186 changes: 52 additions & 134 deletions internal/cmd/serverless/volumes_manage.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,18 @@ const (
var errNothingToUpdateOnVolume = errors.New("nothing to update; pass --description <text> or --clear description")

// volumesHelpLong is the help of the volumes group.
const volumesHelpLong = `Manage Shared Volumes: named, durable sets of files that apps mount.
const volumesHelpLong = `Manage Shared Volumes: named sets of files that apps mount read-only.

Shared Volumes are in beta. These commands need Shared Volumes enabled for the
organization, which 'volumes settings' shows, and they may change before general
availability.
Create a Volume with 'volumes create', upload files with 'volumes put', then
mount it into an app with 'deploy --mount'. Workers mount the Volume's latest
files when they start. Rolling an app back does not bring back older files. To
start clean, create a new Volume.

A Volume belongs to one environment, and only apps in that environment mount
it. Every command here except 'settings' takes --env to select that
environment, else the default environment (RUNWARE_ENV, else the config's) or
production.
A Volume belongs to one environment (--env) and is not the node-local folder
'deploy --volume' declares.

The lifecycle:

1. 'volumes create' makes an empty Volume. No app is needed.
2. 'volumes put' uploads files into it. Uploads are additive: they add or
replace the paths they name and keep every other file.
3. 'deploy --mount' mounts it into an app.

A Volume has one set of files, its latest files. Workers mount the latest
files when they start; running workers keep theirs until they stop. Rolling an
app back does not bring back older files. To start clean, create a new Volume.

A Shared Volume is not the node-local folder 'deploy --volume' declares: that
folder lives on one machine, while a Volume is stored by the platform and
mounted wherever the app's workers run.

Deleting a Volume is logical: it stops new mounts at once, and the platform
may reclaim the stored bytes later.`
These commands are in beta and need Shared Volumes enabled for the
organization; 'volumes settings' shows whether they are.`

// addVolumeEnvironmentFlag registers --env on a Volume command that addresses
// one environment.
Expand All @@ -65,18 +49,11 @@ func addVolumeEnvironmentFlag(cmd *cobra.Command, logger *log.Logger) {

func newVolumesListCmd(logger *log.Logger) *cobra.Command {
cmd := &cobra.Command{
Use: connectorsListUse,
Short: "List Volumes",
Long: `List every Volume in one environment, newest first, following every page.

The table shows sizes in binary units and short ids; --format json or yaml
prints the API objects with sizes in bytes and full ids.`,
Example: ` # list the Volumes of the default environment (production unless set)
runware serverless volumes list

# list the staging Volumes as JSON
runware serverless volumes list --env staging --format json`,
Args: cobra.NoArgs,
Use: connectorsListUse,
Short: "List Volumes",
Long: `List the Volumes in one environment, newest first.`,
Example: ` runware serverless volumes list --env staging`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
spin := cmdutil.NewSpinner("Fetching Volumes...")
spin.Start()
Expand All @@ -101,18 +78,11 @@ func newVolumesCreateCmd(logger *log.Logger) *cobra.Command {
var description string

cmd := &cobra.Command{
Use: "create <name>",
Short: "Create a Volume",
Long: `Create an empty Volume in one environment.

The name is unique among the environment's Volumes and never changes. Fill the
Volume with 'volumes put', then mount it with 'deploy --mount'.`,
Example: ` # create a Volume in the default environment (production unless set)
runware serverless volumes create model-weights

# create one in staging with a description
runware serverless volumes create model-weights --env staging --description "SDXL base and refiner weights"`,
Args: volumeNameArg,
Use: "create <name>",
Short: "Create a Volume",
Long: `Create an empty Volume. Upload files to it with 'volumes put'.`,
Example: ` runware serverless volumes create model-weights --description "SDXL weights"`,
Args: volumeNameArg,
RunE: func(cmd *cobra.Command, args []string) error {
body := serverlessapi.VolumeCreate{
Name: args[0],
Expand Down Expand Up @@ -141,7 +111,7 @@ Volume with 'volumes put', then mount it with 'deploy --mount'.`,
})
},
}
cmd.Flags().StringVar(&description, descriptionFlag, "", "Free-text description, at most 1024 characters")
cmd.Flags().StringVar(&description, descriptionFlag, "", "Description, at most 1024 characters")
addVolumeEnvironmentFlag(cmd, logger)
return cmd
}
Expand All @@ -150,19 +120,10 @@ func newVolumesShowCmd(logger *log.Logger) *cobra.Command {
cmd := &cobra.Command{
Use: "show <name>",
Short: "Show a Volume",
Long: `Show a Volume: its size, file count, the digest of its latest file list,
and the app versions that use it.

The digest changes exactly when the latest files change, so comparing it tells
whether they did. It is not an id: nothing accepts it.

--format json or yaml prints the API's Volume object; 'volumes references'
prints the uses on their own.`,
Example: ` runware serverless volumes show model-weights

# the staging Volume as JSON
runware serverless volumes show model-weights --env staging --format json`,
Args: volumeNameArg,
Long: `Show a Volume: its size, file count, the digest of its latest files and the
app versions that use it.`,
Example: ` runware serverless volumes show model-weights`,
Args: volumeNameArg,
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]

Expand Down Expand Up @@ -208,19 +169,11 @@ func newVolumesUpdateCmd(logger *log.Logger) *cobra.Command {
)

cmd := &cobra.Command{
Use: "update <name>",
Short: "Update a Volume's description",
Long: `Change a Volume's description, the only thing about a Volume that changes
here. Its name and environment never change, and its files change only through
'volumes put'.

--clear description removes the description.`,
Example: ` # replace the description
runware serverless volumes update model-weights --description "SDXL weights, fp16"

# remove it
runware serverless volumes update model-weights --clear description`,
Args: volumeNameArg,
Use: "update <name>",
Short: "Update a Volume's description",
Long: `Change a Volume's description, or remove it with --clear description.`,
Example: ` runware serverless volumes update model-weights --description "SDXL weights, fp16"`,
Args: volumeNameArg,
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]
body, err := volumeUpdateBody(cmd, description, clears)
Expand All @@ -247,7 +200,7 @@ here. Its name and environment never change, and its files change only through
})
},
}
cmd.Flags().StringVar(&description, descriptionFlag, "", "New free-text description, at most 1024 characters")
cmd.Flags().StringVar(&description, descriptionFlag, "", "New description, at most 1024 characters")
addClearFlag(cmd, &clears, []string{descriptionField})
addVolumeEnvironmentFlag(cmd, logger)
return cmd
Expand Down Expand Up @@ -281,33 +234,19 @@ func newVolumesDeleteCmd(logger *log.Logger) *cobra.Command {
cmd := &cobra.Command{
Use: "delete <name>",
Short: "Delete a Volume",
Long: `Delete a whole Volume: its latest files and any upload still open on it.
Individual files cannot be deleted.

The API currently deletes only a Volume that has never had files published
and that no app version uses. For any other Volume that passes the checks
below, including one that only older app versions use once that is confirmed,
it answers 501 Not Implemented and nothing is deleted.

The command reads the Volume and its references first. A Volume that a
current app version, a deploy in progress or a running worker uses is not
deleted: the command prints those uses and fails. When only older app
versions use it, a deletion takes their rollback, so the command names them
and asks before it goes ahead, and asks again if they change while it waits.
The API checks the uses again when the delete commits, and confirming never
overrides a current use. The delete names the Volume by the id it read, so it
never deletes a new Volume that took the name meanwhile.

The deletion is logical. New mounts of the Volume stop at once, and the
platform may reclaim its stored bytes later. A new Volume with the same name
is a different Volume, and never satisfies a mount of this one.
Long: `Delete a Volume. A Volume that a current app version, a deploy or a running
worker uses is not deleted; when only older app versions use it, the command
asks first, since they lose their rollback.

For now the API deletes only a Volume that has never had files published and
Comment thread
danmrichards marked this conversation as resolved.
Resolved
that no app version uses; for any other it answers 501 Not Implemented.

Confirmation is required unless --yes or --force is passed.`,
Example: ` # delete a Volume (prompts for confirmation)
runware serverless volumes delete model-weights

# delete the staging Volume without a prompt
runware serverless volumes delete model-weights --env staging --yes`,
# skip the confirmation prompt
runware serverless volumes delete model-weights --yes`,
Args: volumeNameArg,
RunE: func(cmd *cobra.Command, args []string) error {
return deleteVolume(cmd, logger, args[0], yes || force)
Expand Down Expand Up @@ -461,17 +400,10 @@ func newVolumesReferencesCmd(logger *log.Logger) *cobra.Command {
cmd := &cobra.Command{
Use: "references <name>",
Short: "List what uses a Volume",
Long: `List the app versions that use a Volume, following every page.

Current app versions, deploys in progress and running workers block a delete.
Older app versions do not, but a delete takes their rollback. The list is a
snapshot: 'volumes delete' reads it again, and the API checks again when the
delete commits.`,
Example: ` runware serverless volumes references model-weights

# as JSON, for a script
runware serverless volumes references model-weights --format json`,
Args: volumeNameArg,
Long: `List the app versions that use a Volume: those that block 'volumes delete'
and the older versions a delete takes the rollback from.`,
Example: ` runware serverless volumes references model-weights`,
Args: volumeNameArg,
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]

Expand Down Expand Up @@ -500,19 +432,11 @@ delete commits.`,

func newVolumesFilesCmd(logger *log.Logger) *cobra.Command {
cmd := &cobra.Command{
Use: "files <name>",
Short: "List a Volume's latest files",
Long: `List every one of a Volume's latest files, ordered by path, following every
page.

The listing reads file metadata only: paths, sizes, modes and digests. There is
no download. When an upload changes the files between two pages, the command
starts again, so the list always comes from one file set.`,
Example: ` runware serverless volumes files model-weights

# every path, size in bytes and digest as JSON
runware serverless volumes files model-weights --format json`,
Args: volumeNameArg,
Use: "files <name>",
Short: "List a Volume's latest files",
Long: `List a Volume's latest files by path, with their sizes, modes and digests.`,
Example: ` runware serverless volumes files model-weights`,
Args: volumeNameArg,
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]

Expand Down Expand Up @@ -541,17 +465,11 @@ starts again, so the list always comes from one file set.`,

func newVolumesSettingsCmd(logger *log.Logger) *cobra.Command {
return &cobra.Command{
Use: "settings",
Short: "Show the organization's Shared Volume access and limits",
Long: `Show whether Shared Volumes are enabled for the organization, and the
effective limits that apply to every environment.

Settings belong to the organization, so this command takes no --env.`,
Example: ` runware serverless volumes settings

# limits in bytes, for a script
runware serverless volumes settings --format json`,
Args: cobra.NoArgs,
Use: "settings",
Short: "Show the organization's Shared Volume access and limits",
Long: `Show whether Shared Volumes are enabled for the organization, and its limits.`,
Example: ` runware serverless volumes settings`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
spin := cmdutil.NewSpinner("Fetching Shared Volume settings...")
spin.Start()
Expand Down
9 changes: 5 additions & 4 deletions internal/cmd/serverless/volumes_manage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,13 @@ func TestVolumesGroupIsHiddenAndExplainsTheLifecycle(t *testing.T) {
if !cmd.Hidden {
t.Fatal("volumes is visible before release")
}
for _, want := range []string{"beta", "Shared Volumes enabled", "volumes create", "volumes put", "deploy --mount", "additive", "latest files", "does not bring back older files", "create a new Volume", "deploy --volume"} {
if !strings.Contains(cmd.Long, want) {
long := oneLine(cmd.Long)
for _, want := range []string{"beta", "Shared Volumes enabled", "volumes create", "volumes put", "deploy --mount", "read-only", "latest files when they start", "does not bring back older files", "create a new Volume", "deploy --volume"} {
if !strings.Contains(long, want) {
t.Errorf("group help missing %q", want)
}
}
lower := strings.ToLower(cmd.Long)
lower := strings.ToLower(long)
for _, promise := range []string{"download", "version history", "delete a file", "delete files"} {
if strings.Contains(lower, promise) {
t.Errorf("group help promises %q", promise)
Expand Down Expand Up @@ -982,7 +983,7 @@ func TestVolumesFilesKeepsTheRetryAdviceAfterStaleCursors(t *testing.T) {
}

func TestVolumesDeleteHelpSaysWhichVolumesTheAPIDeletes(t *testing.T) {
long := newVolumesDeleteCmd(log.New(io.Discard)).Long
long := oneLine(newVolumesDeleteCmd(log.New(io.Discard)).Long)
requireOutput(t, long, "never had files published", "no app version uses", "501 Not Implemented")
if strings.Contains(long, "can be deleted") {
t.Fatalf("help still says a Volume older versions use can be deleted:\n%s", long)
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/serverless/volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ func TestVolumesPutHelpDescribesAdditiveUploads(t *testing.T) {
if err != nil {
t.Fatal(err)
}
help := strings.ToLower(cmd.Long)
for _, want := range []string{"additive", "workers that start after an upload get the new files", "rolling an app back", "create a new volume", "run the same command again to continue the upload", "organization id", `"organization: <id>"`, "top level of ~/.runware/config.yaml (config set cannot set it)", strings.ToLower(config.OrganizationFromEnvVar), "--" + concurrencyFlag} {
help := strings.ToLower(oneLine(cmd.Long))
for _, want := range []string{"additive", "run the same command again to resume", "organization id", `"organization: <id>"`, "~/.runware/config.yaml", strings.ToLower(config.OrganizationFromEnvVar)} {
if !strings.Contains(help, want) {
t.Errorf("help does not say %q", want)
}
Expand Down
44 changes: 8 additions & 36 deletions internal/volumes/put/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,16 @@ import "github.com/runware/runware-cli/internal/config"

// Help text of volumes put: additive uploads, and no promise to delete.
const (
escapingSymlinkAdvice = "remove the link or replace it with a copy of its target"

HelpShort = "Upload files and directories to a Volume"

HelpLong = `Upload local files and directories to a Volume.

put needs your organization id. Copy it from the Runware console, then either set the
` + config.OrganizationFromEnvVar + ` environment variable or add the line "organization: <id>" at the
top level of ~/.runware/config.yaml (config set cannot set it).

Uploads are additive. The paths you give are added to the Volume's latest files, or
replace the file already at the same path; files you do not name stay as they are. A
directory's files keep their paths relative to the directory, under --to when you give
it and at the Volume root otherwise. Links inside a directory must point to files
within it. If a link points outside the local directory, ` + escapingSymlinkAdvice + `.

Workers that start after an upload get the new files. Workers that are already running
keep the files they started with.

Rolling an app back re-applies its earlier image, not earlier Volume files. To go
back to older files, upload them again.

To start from an empty set of files, create a new Volume and upload into it.

Content the organization already stores is never sent again, so repeating an upload
that changes nothing sends no bytes. A file must not change while it uploads: if one
does, put stops, names the file and publishes nothing.

put sends up to --concurrency parts at once, one connection each. Each part streams
from the file, so a part in flight holds about 1 MiB of memory.

If put is interrupted, run the same command again to continue the upload. Parts
whose acknowledgements were saved are skipped. If a file changed, put aborts the
saved upload. Run the command again to start a new session.`
HelpLong = `Upload local files and directories to a Volume. Uploads are additive: each
file adds or replaces the file at its path, and other files stay. A directory's
files keep their relative paths, under --to when given. If put is interrupted,
run the same command again to resume.

HelpExample = ` # upload a directory to the root of a Volume
runware serverless volumes put model-weights ./weights
put needs your organization id from the Runware console: set
` + config.OrganizationFromEnvVar + ` or add the top-level line "organization: <id>" to
~/.runware/config.yaml.`

# add one file under a directory in the Volume
runware serverless volumes put model-weights ./tokenizer.json --to tokenizer`
HelpExample = ` runware serverless volumes put model-weights ./weights`
)
11 changes: 3 additions & 8 deletions internal/volumes/put/put_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,22 +520,17 @@ func TestPutSummaryJSON(t *testing.T) {
func TestPutHelpText(t *testing.T) {
t.Parallel()
help := strings.Join(strings.Fields(HelpShort+" "+HelpLong+" "+HelpExample), " ")
const localLinkAdvice = "If a link points outside the local directory, remove the link or replace it with a copy of its target."
for _, want := range []string{
"Uploads are additive",
"files you do not name stay as they are",
"Workers that start after an upload get the new files",
"Rolling an app back re-applies its earlier image, not earlier Volume files",
"Links inside a directory must point to files within it",
localLinkAdvice,
"create a new Volume",
"adds or replaces the file at its path, and other files stay",
"run the same command again to resume",
} {
if !strings.Contains(help, want) {
t.Errorf("help lacks %q", want)
}
}
for _, banned := range []string{"delet", "remov", "prune", "sync"} {
if strings.Contains(strings.ToLower(strings.ReplaceAll(help, localLinkAdvice, "")), banned) {
if strings.Contains(strings.ToLower(help), banned) {
t.Errorf("help mentions %q, which reads as a promise to take files out of a Volume", banned)
}
}
Expand Down
Loading
Loading