This plugin for the mittwald CLI builds the application in the current directory and deploys it as a container in your mStudio project, without any configuration:
$ cd my-app
$ mw zerodeploy runThe same functionality is still available in the CLI itself as
mw experimental deploy, which will be removed in a future release of the CLI
in favour of this plugin.
Note
This plugin is still experimental; its flags and behaviour might change between minor versions.
You need the mittwald CLI (see its installation instructions), and locally installed Docker and Railpack.
$ mw plugins install zerodeploymw update updates the plugin along with the CLI. If you installed the CLI with
Homebrew, brew upgrade mw does not update the plugin; use mw plugins update
instead. To remove the plugin, use mw plugins uninstall zerodeploy.
Build the application in the current directory and deploy it as a container.
USAGE
$ mw zerodeploy run [--token <value>] [-q] [-p <value>] [-w] [--wait-timeout <value>] [-e <value>...] [--env-file
<value>...] [--uri-prefix <value> | --domain <value> | --no-domain] [--service-name <value>] [--image-name <value>]
[--image-tag <value>] [--build-only]
FLAGS
-e, --env=<value>... set environment variables in the container
-p, --project-id=<value> ID or short ID of a project; this flag is optional if a default project is set in the
context
-q, --quiet suppress process output and only display a machine-readable summary
-w, --wait wait for the resource to be ready.
--build-only build and push the image only
--domain=<value> full hostname to make the service available at
--env-file=<value>... read environment variables from a file
--image-name=<value> name of the Docker image to build and push
--image-tag=<value> tag of the Docker image to build and push
--no-domain do not create or update a domain for the service
--service-name=<value> name of the container service to deploy
--uri-prefix=<value> prefix for the generated default domain
--wait-timeout=<value> [default: 600s] the duration to wait for the resource to be ready (common units like 'ms',
's', 'm' are accepted).
AUTHENTICATION FLAGS
--token=<value> API token to use for authentication (overrides environment and config file). NOTE: watch out that
tokens passed via this flag might be logged in your shell history.
DESCRIPTION
Build the application in the current directory and deploy it as a container.
The command runs the following steps:
1. Checks that Docker and Railpack are installed locally.
2. Makes sure that the project has a working private container registry. The registry runs as the "project-registry"
container in a dedicated stack, is reachable at the "registry" subdomain of the project's default domain and is
configured as a registry of the project. Missing or misconfigured parts are created or repaired; existing parts
(including the stored images and the credentials) are reused. There is one such registry per project, shared by all
deployments.
3. Builds a container image from the current directory, using the Dockerfile in it if there is one, and Railpack
otherwise. The container ports are taken from the EXPOSE instructions of the Dockerfile; a PORT variable passed with
--env takes precedence. Without either, port 80 is used.
4. Pushes the image to the project registry.
5. Deploys the image as a container service. Each service runs in a stack of its own, named after the service; a
service that already exists is updated in the stack it is in.
6. Makes the service available at <uri-prefix>.<project-short-id>.project.space, or at the hostname given with
--domain. If a domain with that hostname already exists in the project, it is pointed to the service instead of
creating a new one.
With --build-only, the command stops after pushing the image. With --no-domain, the command stops after deploying the
service and leaves all domains of the project untouched.
The service name defaults to the name of the current directory (lowercased, with every run of characters other than
letters and digits replaced by a dash), and the image name and domain prefix default to the service name. Deploying
from different directories therefore creates independent deployments, while deploying again from the same directory
updates the existing one.
EXAMPLES
Deploy from current directory (auto-detects or creates Dockerfile)
$ mw zerodeploy run
Deploy with explicit project context
$ mw zerodeploy run --project-id p-abc123
Deploy with custom default domain prefix
$ mw zerodeploy run --uri-prefix myapp
Deploy and make the service available at a custom hostname
$ mw zerodeploy run --domain app.example.com
Deploy without creating or changing any domain
$ mw zerodeploy run --no-domain
Deploy the current directory as a second, independent service, e.g. for a feature branch
$ mw zerodeploy run --service-name my-app-feature --image-tag feature
Build and push image only, without deploying a service
$ mw zerodeploy run --build-only
FLAG DESCRIPTIONS
-e, --env=<value>... set environment variables in the container
Format: KEY=VALUE or KEY. If only KEY is provided, the value is resolved from the caller environment (exported
variables only). Multiple environment variables can be specified with multiple --env flags.
-p, --project-id=<value> ID or short ID of a project; this flag is optional if a default project is set in the context
May contain a short ID or a full ID of a project; you can also use the "mw context set --project-id=<VALUE>" command
to persistently set a default project for all commands that accept this flag.
-q, --quiet suppress process output and only display a machine-readable summary
This flag controls if you want to see the process output or only a summary. When using mw non-interactively (e.g. in
scripts), you can use this flag to easily get the IDs of created resources for further processing.
--build-only build and push the image only
Skips service deployment and domain creation after the image is pushed.
--domain=<value> full hostname to make the service available at
Replaces the generated <uri-prefix>.<project-short-id>.project.space domain entirely. The hostname must be one that
can be used in the project, e.g. a subdomain of a domain the project owns.
--env-file=<value>... read environment variables from a file
The file should contain lines in the format KEY=VALUE. Multiple files can be specified with multiple --env-file
flags.
--image-name=<value> name of the Docker image to build and push
Defaults to the service name.
--image-tag=<value> tag of the Docker image to build and push
Defaults to 'latest'.
--no-domain do not create or update a domain for the service
Deploys the service without touching any domain of the project. Existing domains keep pointing to the service if
they did before.
--service-name=<value> name of the container service to deploy
Also names the stack the service is deployed into. Defaults to the name of the current directory.
--uri-prefix=<value> prefix for the generated default domain
Defaults to the service name.
This plugin builds on the public plugin API of the CLI (@mittwald/cli,
@mittwald/cli/flags, @mittwald/cli/rendering and @mittwald/cli/resources).
$ yarn
$ yarn compile
$ yarn testTo try your changes, link the plugin into your CLI installation (or into a development build of the CLI):
$ mw plugins link --no-install /path/to/cli-plugin-zerodeploy
$ mw zerodeploy run --helpYou can also run the plugin as a standalone CLI with ./bin/run.js (or
./bin/dev.js to run from the TypeScript sources without compiling); it uses
the same configuration and API token as the mw CLI.