Deployment
The Apprite CLI allows you to create and deploy collections and functions to your Appwrite project from a configuration file. This is especially helpful if you're trying to track functions and collection schemas using version control, or if you're promoting changes from development to production environments.
Initializing Your Project
After you're logged in, the CLI needs to be initialized with your Appwrite project. You can initialize the CLI using:
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 collections in your current project using:
appwrite init collection
You can fetch all the existing teams in your current project using:
appwrite init team
Deploying Cloud Functions
The CLI also handles the creation and deployment of Appwrite Functions. You can initialize a new function using:
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 using:
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 migrate your project's collections from a development server to a production server. You can deploy all the collections in your appwrite.json file using:
appwrite deploy collections
Avoiding 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.
Configurable Options
Here's a complete list of all configurable options in appwrite.json
:
Option | Type | Description |
---|---|---|
projectId | string | ID of your Appwrite Project. |
projectName | string | Name of your Appwrite Project. |
functions | array of functions | Configuration of functions in your project. |
collections | array of collections | Configuration of collections in your project. |
teams | array of teams | Configuration of teams in your project. |
Function Options
Option | Type | Description |
---|---|---|
$id | string | Function ID. |
name | string | Function Name. |
runtime | string | Function runtime, must be enabled. Learn more about runtimes. |
path | string | Path to folder containing the function's source code. |
entrypoint | string | Entry point of the function relative to the folder specified in path. |
ignore | array of strings | Files to ignore inside the function. Learn more about ignoring files. |
execute | array of strings | Grants execute permissions to users. Learn more about role strings. |
events | array of strings | Events that trigger the function to execute. Learn more about events. |
schedule | string | Execution schedule for the function as a cron expression. |
timeout | int | Execution timeout of the function in seconds, with a maximum configurable limit of 900 seconds. |
variables | JSON object | Variables provided to the function on execution stored as a key-value JSON object. |
Collection Options
Option | Type | Description |
---|---|---|
$id | string | Collection ID. |
name | string | Collection Name. |
databaseId | string | ID of the database to which this collection belongs. |
enabled | bool | If the collection is enabled. |
documentSecurity | bool | If access permissions can be defined at the document level. |
permissions | array of strings | Grants access permissions to users at the collection level. Learn more about permissions. |
attributes | array of objects | Defines a list of attributes in the collection. Learn more about the Attributes List Object. |
indexes | array of objects | Defines a list of indexes in the collection. Learn more about the Indexes List Object. |
Teams Options
Option | Type | Description |
---|---|---|
$id | string | Team ID. |
name | string | Team Name. |