Deployment

The Apprite CLI allows you to create and deploy databases, collections, buckets, teams and functions to your Appwrite project from a configuration file. This is especially helpful if you're trying to track project setup using version control.

Initialization

After you're logged in, the CLI needs to be initialized with your Appwrite project. You can initialize the CLI using:

Shell
appwrite init project

The following prompts will guide you through the setup process. The init command also creates an appwrite.json file representing your Appwrite project.

You can fetch all the existing databases and collections in your current project using:

Shell
appwrite init collection

You can fetch all the existing teams in your current project using:

Shell
appwrite init team

Deploying Functions

The CLI also handles the creation and deployment of Appwrite Functions. Run this command in the folder holding your appwrite.json file.

Shell
appwrite init function
? What would you like to name your function? My Awesome Function
? What runtime would you like to use? Node.js (node-15.5)
✓ Success

This command creates a new function My Awesome Function in your current Appwrite project and also creates a template function for you to get started.

You can now deploy this function by running this command in the folder holding your appwrite.json file.

Shell
appwrite deploy function
? Which functions would you like to deploy? Awesome Function (621229798628cf5bf712)
ℹ Info Deploying function Awesome Function ( 621229798628cf5bf712 )
✓ Success Deployed Awesome Function ( 621229798628cf5bf712 )

Deploying Collections

The Appwrite CLI also helps you deploy your project's databases and collections schema from one project to another.

You can deploy all the databases and collections in your appwrite.json file by running this command in the folder holding your appwrite.json file.

The deploy command will overwrite existing collections causing existing data to be lost. If you already have data in your project, you will need to write your own migration script using a Server SDK instead of using the CLI.

Shell
appwrite deploy collection

Deploying Teams

The Appwrite CLI can create teams to organize users. Teams can be used to grant access permissions to a group of users. Learn more about permissions.

Deploy teams by running this command in the folder holding your appwrite.json file.

Shell
appwrite deploy team

Deploying Storage

The Appwrite CLI allows you to configure and deploy buckets across projects. All the bucket's settings are available through the appwrite.json file.

Deploy storage buckets by running this command in the folder holding your appwrite.json file.

Shell
appwrite deploy bucket

Conflicts

When using appwrite.json, changes made in the Appwrite Console can cause conflicts with the local config. To avoid conflicts, prefer updating configuration locally and deploying instead of using the Console.

The appwrite.json file

An appwrite.json file is created by the CLI when you initialize your project. It stores all the configuration for the CLI to be able to interact with your Appwrite project in JSON format. When using the appwrite deploy command, the CLI uses information from appwrite.json to deploy your functions and collections.

Configuration

Here's a complete list of all configurable options in appwrite.json:

OptionTypeDescription
projectIdstringID of your Appwrite Project.
projectNamestringName of your Appwrite Project.
functionsarray of functionsConfiguration of functions in your project.
databasesarray of databasesConfiguration of databases in your project.
collectionsarray of collectionsConfiguration of collections in your project.
teamsarray of teamsConfiguration of teams in your project.
bucketsarray of bucketsConfiguration of teams in your project.

Function options

OptionTypeDescription
$idstringFunction ID.
namestringFunction Name.
runtimestringFunction runtime, must be enabled. Learn more about runtimes.
pathstringPath to folder containing the function's source code.
entrypointstringEntry point of the function relative to the folder specified in path.
ignorearray of stringsFiles from your source code that should be ignored when creating a deployment.
executearray of stringsGrants execute permissions to users. Learn more about role strings.
eventsarray of stringsEvents that trigger the function to execute. Learn more about events.
schedulestringExecute schedule for the function. Learn more about scheduled executions.
timeoutintExecution timeout of the function in seconds, with a maximum configurable limit of 900 seconds.
variablesJSON objectVariables provided to the function on execution stored as a key-value JSON object.

Databases options

OptionTypeDescription
$idstringDatabase ID.
namestringDatabase Name.

Collection options

OptionTypeDescription
$idstringCollection ID.
namestringCollection Name.
databaseIdstringID of the database to which this collection belongs.
enabledboolIf the collection is enabled.
documentSecurityboolIf access permissions can be defined at the document level.
$permissionsarray of stringsGrants access permissions to users at the collection level. Learn more about permissions.
attributesarray of objectsDefines a list of attributes in the collection. Learn more about the Attributes List Object.
indexesarray of objectsDefines a list of indexes in the collection. Learn more about the Indexes List Object.

Buckets options

OptionTypeDescription
$idstringBucket ID.
namestringBucket Name.
$permissionsarray of stringsGrants access permissions to users at the bucket level. Learn more about permissions.
fileSecuritybooleanWhether file-level security is enabled. Learn more about permissions.
enabledbooleanWhether the bucket is enabled or disabled.
maximumFileSizeintegerMaximum file size supported.
allowedFileExtensionsstring[]List of allowed file extensions.
compressionstringPreferred algorithm for compression. Will be one of none, gzip, or zstd.
encryptionbooleanWhether the bucket's content is encrypted.
antivirusbooleanWhether virus scanning is enabled for the bucket's content.

Teams options

OptionTypeDescription
$idstringTeam ID.
namestringTeam Name.