Skip to content

Functions

Deploy from Git

Learn to version and update your Appwrite Functions' code with deployments.

7 min read

Raw

Appwrite Functions are mini-applications in Appwrite with their own endpoints. Each function can have many deployments, which can be thought of as versions of the mini-application.

Appwrite Functions can be automatically deployed from Git repositories, so you can track changes to your function's code naturally as a part of you development workflow.

Create deployment

The recommended way to manage your Appwrite Function deployments is to use a version control system, like Git. This offers simple versioning and collaboration that will easily fit into the rest of your development workflow.

You can only use Git deployment for Appwrite Functions connected to Git. Create a new function with Git or connect your existing function to a Git repository in your function's Settings > Version control (Git).

Git repository
Git repository

  1. Using Git, checkout the branch you configured as the production branch when creating the Appwrite Function.
  2. Create a new commit.
  3. Push your new commit.
  4. A new deployment will be automatically created, built and activated.

Pushes deploy automatically while Deploy on push is on in the function's Git automation settings.

Commits to the production branch

When you push a commit to the production branch, usually main, a new deployment will be created, built, and activated. This means, the new deployments will immediately replace the current active deployment and handle all incoming requests.

Commits to other branches

When you push a commit to a branch other than the production branch, a new deployment will be created, but it will not be activated. This means, the new deployment will not handle any incoming requests until it is activated.

Git configuration

If you need to update your Git configuration, navigate to Functions > your function > Settings > Version control (Git).

Git automation

Git automation controls what Appwrite does when you push to the connected repository. Once your function is connected to a repository, open its Settings > Version control (Git) and find the Git automation card.

Git automation card in the Appwrite Console
Git automation card in the Appwrite Console

The card holds the Production branch and three switches, all on by default:

SwitchAPI parameterWhen it's on
Deploy on pushproviderDeploymentsEvery push that matches your build triggers creates a deployment. Pushes to the production branch activate it.
Post build summariesproviderCommentsAppwrite posts one comment on each pull request with the build status, and updates it as builds finish.
Report commit statusproviderStatusesAppwrite reports each build on its commit as building, passed, or failed. On GitHub, it adds a check run. On Entire, it adds a check run and a deployment entry. On GitLab and Gitea, it sets a commit status, and on Bitbucket, a build status.

Changes apply from the next push, without a redeploy.

Deploy on push

When Deploy on push is off, pushes no longer create deployments, and your function keeps serving its active deployment. The repository stays connected, so you can deploy a branch whenever you choose: open the function's Deployments tab, click Create deployment, and select Git. You pick the branch and whether to activate the deployment when it finishes building.

While it's off, the Console disables Production branch and Post build summaries, because a deployment you create yourself has no pull request and decides for itself whether to go live. Report commit status still works for the commits you deploy.

Post build summaries

Turn off Post build summaries to keep Appwrite's comment out of pull requests. If Report commit status stays on, each commit still shows whether the build passed.

Appwrite posts the summary when a pull request is opened or reopened, so turning the switch on doesn't add one to a pull request that's already open. Entire doesn't get build summaries.

Report commit status

Turn off Report commit status to stop Appwrite from adding checks, statuses, and deployment entries to your commits.

Silent mode

You can turn on Silent mode when you create a function from a repository. Silent mode turns off build summaries and commit statuses, whatever the switches say, and the Git automation card shows both as off while it's on. Saving the card turns silent mode off and saves both switches as the card shows them, so turn on the ones you want before you click Update. Silent mode doesn't affect Deploy on push.

Configure Git automation with a Server SDK

Pass providerDeployments, providerComments, and providerStatuses when you create or update a function. Settings you leave out of an update keep their current values.

const sdk = require('node-appwrite');
const client = new sdk.Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<PROJECT_ID>') // Your project ID
.setKey('<API_KEY>'); // Your secret API key
const functions = new sdk.Functions(client);
// Keep deploying on push, without comments on pull requests
await functions.update({
functionId: '<FUNCTION_ID>',
name: '<NAME>', // name is required by update
providerComments: false
});

To deploy a branch or commit while Deploy on push is off, call functions.createVcsDeployment() with type set to branch or commit, the branch name or commit hash as reference, and activate set to true to make it live once it builds.

Build triggers

Build triggers control which Git changes create automatic deployments. You can configure branch filters and path filters with glob patterns.

Branch filters match branch names. Add patterns to limit automatic deployments to specific branches.

Plain text
main
staging
preview/**

Path filters match files changed in a commit or pull request. Leave this field empty to create deployments for all file changes, or add patterns to deploy only when specific files change.

Plain text
functions/api/**
packages/shared/**
!docs/**

Use these formats to write glob patterns.

PatternWhat it doesExampleMatches
mainMatches exact textmainmain
*Matches within one path segmentrelease/*release/1.0
**Matches across nested path segmentspreview/**preview/test, preview/team/test
?Matches one character in one path segmentv?.?v1.0, v2.5
[abc]Matches one character from a set[Mm]ainmain, Main
[a-z]Matches one character in a rangerelease/[0-9]*release/1.0
\Escapes a special characterfile\?.txtfile?.txt
!Excludes matching branches or paths!docs/**Excludes changes under docs/

Skip a deployment

To push a commit without creating a deployment, add [skip appwrite] or [skip ci] to the commit message. [skip appwrite] skips only the Appwrite deployment. [skip ci] is also recognized by GitHub Actions and most other CI tools, so it skips those workflows too.

Plain text
docs: update readme [skip appwrite]

Entry point

The entry point is the code file contains the exported function that will be executed when the function is called. This entry point has a specific format that must be followed. You can find examples using a starter template or following the developing functions docs.

Root directory

The root directory is the root of the code that will be copied to the executor. If you have a monorepo, you can specify the subdirectory that contains the function's code using the root directory setting.

Share code between multiple functions

If you're sharing code between multiple Appwrite Functions in a monorepo, referencing files outside of the entry point file will not work. To share code between multiple functions, set the root directory to be the common root of the mono repo, and use cd <working directory> in your build commands, under Settings > Build > Commands, to navigate to the function's directory before building.

Another option is to use submodules in your Git repository to include shared code in each function's repository.

Debugging

  • If you updated your function's configuration but the deployment is not working as expected, you may need to first redeploy your function before the changes take effect.

  • If you notice your function is missing dependencies during build or at runtimes, update it's build settings. Navigate to Functions > your function > Settings > Build > Commands. These commands will be ran before the function is built and can be used to install dependencies.

  • If you're missing some code files at build time, make sure they are included in the Git configuration's Root directory. Only files in the root directory folder will be copied to the executor.

  • If you're self-hosting Appwrite, you will need to configure some environment variables to enable Git deployments.

Was this page helpful?

Share what worked or what we should fix. Once approved, our agents automatically apply suggested updates to the docs.