OK, I think this so called "magic" command should look and work something like this.
Command usage
cast deploy [--app-path=<path to the application directory>] [--no-interactive]
Command options
- --app-path=<path to the application directory> - path to the directory where the application code and cast.json file is located (defaults to the current working directory)
- --no-interactive - don't interact with the user, immediately exit upon error with a non-zero exit code (this option will most likely be used when calling this command from the VCS's post receive hooks and other scripts)
Command actions in different contexts
cast.json file doesn't exist in the specified directory
Print an error message and ask the user if he want to create a new manifest file (calls cast init internally). If the user answers "no", exit, otherwise create a manifest file and continue with the deployment process.
cast.json file exists, instance with the version specified in the cast.json file doesn't exist on the server and there are no other versions for this application already deployed on the server - this is a first version
- Create and upload a bundle (if it doesn't already exist locally and on the server, calls cast bundles create and cast bundles upload internally)
- Create a new instance with the following name: instanceName = applicationName.replace(/\s/, '_').toLowerCase();
- Enable and start the new instance
- Print a success message - "Application Foo Bar 1.0.0 has been successfully deployed. If the application did not start properly, you can use the following command to view it's log file: cast services tail instanceName"
cast.json file exists, instance with the version specified in the cast.json file already exist on the server
Print an error message - "App Foo Bar 1.0.0 already exists on the server. If you want to deploy a new version of your application, you need to change the "version" attribute in the cast.json file."
As a bonus we could maybe also add a new command for increasing / decreasing the application version number. For example: cast bundles increase-version, cast bundles decrease-version. This commands would of course only work if user is using a classic major.minor.patch versioning scheme
cast.json file exists, instance with the version specified in the cast.json file doesn't exist on the server, but there is already an existing version of this application deployed on the server
- Create and upload a bundle (if it doesn't already exist locally and on the server)
- Upgrade the currently deployed version to the one which has just been uploaded (calls cast instances upgrade internally)
- Print a success message "App Foo Bar 1.1.0 has been successfully deployed (version 1.0.1 has been upgraded). If the application did not start properly, you can use the following command to view it's log file: cast services tail instanceName"
For all this to work, we would need to change the way the user specifies an application version. Currently the version is manually passed to the bundles command (cast bundles create <name> <version>, etc.), but for this to work, a version would need to be specified in the manifest file.
I think specifying version in the manifest file has multiple advantages and I have already proposed this in the past:
- it's more explicit
- it's easier to track version-to-revision mapping if you are using some kind of version control system
- requires less interaction with the user when using "magic" commands like this one
I need to point out that this command is primary there to help users get up and running as soon and with as few steps as possible. If a user has special needs and / or wants a more fine-grained control, all the existing commands will still be available.
Feedback?
Thanks