Running Spin Applications
- Specifying the Application to Run
- Application Output
- Persistent Logs
- Trigger-Specific Options
- Monitoring Applications for Changes
- Next Steps
Once you have created and built your application, it’s ready to run. To run an application, use the
spin up command.
Specifying the Application to Run
spin up looks for a file named
spin.toml in the current directory.
If your manifest is named something different, or isn’t in your current directory, use the
--from) flag. You also use
-f to run remote applications.
|File name: ||Runs the specified manifest file|
|Directory name: ||Looks for a |
|Registry reference: ||Pulls the application from the registry and runs that|
If Spin misunderstands a registry reference as a file name, or vice versa, you can use
If you see the error
failed to resolve content at "example.wasm"(where
example.wasmis the module file of a component), check that the application has been built.
If your application doesn’t run, you can run
spin doctorto check for problems with your Spin configuration and tools.
Testing HTTP Applications
By default, HTTP applications listen on
localhost:3000. You can override this with the
--listen option. Spin prints links to the application components to make it easy to open them in the browser or copy them to
curl commands for testing.
By default, Spin prints application output, and any of its own error messages, to the console.
To hide application output, pass the
$ spin up --quiet
To limit application output to specific components, pass the
$ spin up --follow cart --follow cart-api
- If you run an application from the file system (a TOML file), Spin saves a copy of the application output and error messages. This is saved in the
.spin/logsdirectory, under the directory containing the manifest file.
- If you run an application from a registry reference, Spin does not save a copy of the application output and error messages; they are only printed to the console.
To control logging, pass the
--log-dir flag. The logs will be saved to the specified directory (no matter whether the application is local or remote).
$ spin up --log-dir ~/dev/bugbash
Some trigger types support additional
spin up flags. For example, HTTP applications can have a
--listen flag to specify an address and port to listen on. See the HTTP trigger and Redis trigger pages for more details.
Monitoring Applications for Changes
watch command rebuilds and restarts Spin applications whenever files change. You can use the
spin watch command in place of the
spin build and
spin up commands, to build, run and then keep your Spin application running without manual intervention while staying on the latest code and files.
watchcommand accepts valid Spin up options and passes them through to
spin upfor you when running/rerunning the Spin application. E.g.
spin watch --listen 127.0.0.1:3001
By default, Spin watch monitors:
- The application manifest (
- Any files specified in the
component.build.watchsections of the
- Any files specified in the
component.filessections of the
- The files specified in the
component.sourcesections of the
If any of these change, Spin will rebuild the application if necessary, then restart the application with the new files.
Spin watch does not consider changes to a file’s metadata (file permissions or when it was last modified) as a change.
spin.toml configuration (belonging to a Spin
http-rust application) is configured to ensure that the application is both rebuilt (via
cargo build --target wasm32-wasi --release) and rerun whenever changes occur in any Rust source (
.rs) files, the
Cargo.toml file or the
spin.toml file, itself. When changes occur in either the Wasm binary file (
target/wasm32-wasi/release/test.wasm) or the text file (
my-files/changing-file.txt) the application is only rerun using the initial
spin up command:
[[component]] // -- snip files = ["my-files/changing-file.txt"] source = "target/wasm32-wasi/release/test.wasm" [component.build] command = "cargo build --target wasm32-wasi --release" # Example watch configuration for a Rust application watch = ["src/**/*.rs", "Cargo.toml"]
build section specifies a
watch patterns are relative to that directory. Otherwise,
watch patterns are relative to the directory containing the
If you would prefer Spin watch to only rerun the application (without a rebuild) when changes occur, you can use the
--skip-build option when running the
spin watch command. In this case, Spin will ignore the
component.build.watch section, and monitor only the
The table below outlines exactly which files
spin watch will monitor for changes depending on how you run the command.
spin watch uses the configuration found on every component in your application.
|Application manifest ||Yes||Yes|
|No (Yes if the component has no build command)||Yes|
Spin watch waits up to 100 milliseconds before responding to filesystem events, then processes all events that occurred in that interval together. This is so that if you make several changes close together (for example, using a Save All command), you get them all processed in one rebuild/reload cycle, rather than going through a cycle for each one. You can override the interval by passing in the
--debounce option; e.g.
spin watch --debounce 1000 will make Spin watch respond to filesystem events at most once per second.
Note: If the build step (
spin build) fails,
spin upwill not be run.
--clear flag clears the screen anytime a rebuild or rerun occurs. Spin watch does not clear the screen between rebuild and rerun as this provides you with an opportunity to see any warnings.
For additional information about Spin’s
watch feature, please see the Spin watch - live reload for Wasm app development blog article.
- Learn how to create and update a Spin application
- Learn about how to configure your application at runtime
- See how to package and distribute your application
- Try deploying your application to run in the Fermyon Cloud