-
Notifications
You must be signed in to change notification settings - Fork 116
Functions G4 #398
Functions G4 #398
Changes from all commits
a0ebf26
3ee6a1f
d491591
4537a2b
52bdc62
6b2da17
6fbc33a
3610aad
3858af8
71439b8
16267be
9819ffb
db582b5
4a56433
db2286b
b5ec443
5741154
29fc3c1
31c7c44
d9c2d5d
2296a8b
a6e319c
6617811
1e34f71
30e2d29
df07548
4502515
ac6deba
b4c0b27
ed8c6a2
aaf8168
75600e0
01d5a4c
f6d14bf
0f2d54a
0ea520d
3826826
54615e4
e78f4be
c1f4e3b
e6bbd1d
9a76ab5
afd026e
3dc7180
02574b2
a11daf8
d3645b2
1ffc8e2
ca02087
dbabc60
54097a4
b04e153
94b8c5a
f088a1e
2cd56dd
e7b9b1c
780b5e4
b2902ed
e4e8b0a
75e79cb
0f51947
ab0cab2
4d54192
86d262a
4548a4d
3f57c8d
c0e4011
e1681af
c6e548c
8337b4e
28cd6fe
a1c0aac
9673f04
8872899
4de62dc
29f897f
77337c1
7228e69
7a24d8e
e3683ed
67f2c43
870726e
a84c565
f70b767
7a307fb
e9fb637
e22eee1
8d9be11
dd7fe4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ The Apprite CLI allows you to create and deploy databases, collections, buckets, | |
|
||
<h2><a href="/docs/command-line-deployment#deployFunctions" id="deployFunctions">Deploying Appwrite Functions</a></h2> | ||
|
||
<p>The CLI also handles the creation and deployment of Appwrite Functions. You can initialize a new function using:</p> | ||
<p>The CLI also handles the creation and deployment of Appwrite Functions. Run this command in the folder holding your <code>appwrite.json</code> file.</p> | ||
|
||
<div class="ide margin-bottom" data-lang="bash" data-lang-label="CLI"> | ||
<pre class="line-numbers"><code class="prism language-bash" data-prism>appwrite init function | ||
|
@@ -36,7 +36,9 @@ The Apprite CLI allows you to create and deploy databases, collections, buckets, | |
✓ Success</code></pre> | ||
</div> | ||
|
||
<p>This command creates a new function <b>My Awesome Function</b&g 8000 t; in your current Appwrite project and also creates a template function for you to get started. You can now deploy this function using: </p> | ||
<p>This command creates a new function <b>My Awesome Function</b> in your current Appwrite project and also creates a template function for you to get started.</p> | ||
|
||
<p>You can now deploy this function by running this command in the folder holding your <code>appwrite.json</code> file.</p> | ||
|
||
<div class="ide margin-bottom" data-lang="bash" data-lang-label="CLI"> | ||
<pre class="line-numbers"><code class="prism language-bash" data-prism>appwrite deploy function | ||
|
@@ -47,7 +49,16 @@ The Apprite CLI allows you to create and deploy databases, collections, buckets, | |
|
||
<h2><a href="/docs/command-line-deployment#deployCollections" id="deployCollections">Deploying Databases and Collections</a></h2> | ||
|
||
<p>The Appwrite CLI also helps you migrate your project's databases and collections from a development server to a production server. You can deploy all the databases and collections in your <a href="/docs/command-line-deployment#appwriteJSON">appwrite.json</a> file using:</p> | ||
<p>The Appwrite CLI also helps you deploy your project's databases and collections schema from one project to another.</p> | ||
|
||
<p> | ||
You can deploy all the databases and collections in your <a href="/docs/command-line-deployment#appwriteJSON">appwrite.json</a> file by running this command in the folder holding your <code>appwrite.json</code> file. | ||
</p> | ||
|
||
<p> | ||
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. | ||
</p> | ||
|
||
<div class="ide margin-bottom" data-lang="bash" data-lang-label="CLI"> | ||
<pre class="line-numbers"><code class="prism language-bash" data-prism>appwrite deploy collection</code></pre> | ||
|
@@ -57,15 +68,17 @@ The Apprite CLI allows you to create and deploy databases, collections, buckets, | |
|
||
<p>The Appwrite CLI can create teams to organize users. Teams can be used to grant access permissions to a group of users. <a href="/docs/permissions#permission-roles">Learn more about permissions</a>.</p> | ||
|
||
<p>Deploy teams by running this command in the folder holding your <code>appwrite.json</code> file. </p> | ||
<div class="ide margin-bottom" data-lang="bash" data-lang-label="CLI"> | ||
<pre class="line-numbers"><code class="prism language-bash" data-prism>appwrite deploy team</code></pre> | ||
</div> | ||
|
||
|
||
<h2><a href="/docs/command-line-deployment#deployBucket" id="deployBucket">Deploying Storage Buckets</a></h2> | ||
|
||
<p>The Appwrite CLI allows you to configure and deploy buckets across projects. All the bucket's settings are available through the <a href="/docs/command-line-deployment#appwriteJSON">appwrite.json</a> file.</p> | ||
|
||
<p>Deploy storage buckets by running this command in the folder holding your <code>appwrite.json</code> file. </p> | ||
|
||
<div class="ide margin-bottom" data-lang="bash" data-lang-label="CLI"> | ||
<pre class="line-numbers"><code class="prism language-bash" data-prism>appwrite deploy bucket</code></pre> | ||
</div> | ||
6D47
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
<p> | ||
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. | ||
</p> | ||
|
||
<p> | ||
Functions can be created and deployed in different ways to meet your unique development habits. | ||
You can automatically deploy Appwrite Functions from source control, build your own deployment pipelines using the Appwrite CLI, or upload code files manually. | ||
Here's everything you need to know to deploy your first Appwrite Function. | ||
</p> | ||
|
||
<h2><a href="#git" id="git">Git</a></h2> | ||
<p> | ||
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. | ||
</p> | ||
|
||
<h3>Create Function</h3> | ||
<p>Before deploying your function with Git, create a new function attached to your Git repo.</p> | ||
<ol class="margin-top margin-bottom-large text-size-normal"> | ||
<li> | ||
Navigate to <b>Functions</b> from the side bar of the Appwrite Console. | ||
</li> | ||
<li> | ||
Click <b>Create function</b>. | ||
</li> | ||
<li> | ||
When asked to <b>Choose your source</b>, under <b>Connect Git repository</b>, select your provider. | ||
</li> | ||
<li> | ||
Search for the Git repository that hold your function and click <b>connect</b>. | ||
</li> | ||
<li> | ||
Select a production branch. New commits pushed to the production branch will be <b>automatically activated</b>. Commits to any other branch will still be deployed, but not be activated. | ||
</li> | ||
<li> | ||
Input the root directory of the function inside the repository. If you have only one function in your repository, you can leave this empty. If you have multiple, root directory should point to the folder of your function. This should be the directory in which your custom build commands can run successfully. It also improves efficiency because only what's necessary is cloned. | ||
</li> | ||
<li> | ||
If you don't want deploy comments to be made on your pull requests or commits, select <b>Silent mode</b>. | ||
</li> | ||
<li> | ||
Name your function, select a runtime that matches your function, and enter entrypoint, relative to the root directory from the previous step. Entrypoint is path to the main file of your function, which exports the function to be run on every execution. | ||
</li> | ||
<li> | ||
If you have build steps, like installing dependencies, input the commands into the <b>Build settings</b> heading's <b>Command</b> field. | ||
You can combine multiple commands using <code>&&</code>, such as <code>npm install && npm build</code>. | ||
For compiled languages you don't need to worry about installing dependencies, as that's done automatically during compilation step. | ||
</li> | ||
<li> | ||
Finally, configure the execute permissions of the function. For security, only provide execute permissions to the necessary roles. | ||
</li> | ||
</ol> | ||
|
||
<h3>Deploy</h3> | ||
<ol class="margin-top margin-bottom-large text-size-normal"> | ||
<li> | ||
Using Git, checkout the branch you configured as production branch when creating the Appwrite Function. | ||
</li> | ||
<li> | ||
Create a new commit. | ||
</li> | ||
<li> | ||
Push your new commit. | ||
</li> | ||
<li> | ||
A new deployment will be automatically created, built and activated. | ||
</li> | ||
</ol> | ||
|
||
<h2><a href="#cli" id="cli">CLI</a></h2> | ||
<div class="notice margin-bottom-small"> | ||
<h2>CLI Setup</h2> | ||
<p>Before you can deploy with the Appwrite CLI, make sure you've <a href="docs/command-line">installed and initialized</a> the CLI.</p> | ||
</div> | ||
<p> | ||
To deploy with the Appwrite CLI, your function must be added to <code>appwrite.json</code> that tells the CLI where each function is stored. | ||
gewenyu99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
To ensure the folder structure is setup correctly and <code>appwrite.json</code> is configured correctly, use the appwrite init function method to create a starter function, then paste in your function code. | ||
</p> | ||
|
||
<p> | ||
Run the following command in the folder holding the <code>appwrite.json</code> file. | ||
</p> | ||
<div class="ide margin-bottom" data-lang="bash" data-lang-label="Bash"> | ||
<pre class="line-numbers"><code class="prism language-bash" data-prism>appwrite init function</code></pre> | ||
</div> | ||
|
||
<p> | ||
Give your function a name and choose your runtime. | ||
This will create a new starter function in the current directory and also add it to your <code>appwrite.json</code> file. | ||
</p> | ||
|
||
<p> | ||
Edit the automatically generated code and add dependencies to the dependency files of your language or framework. | ||
Then, deploy the function using the following command. | ||
</p> | ||
|
||
<div class="ide margin-bottom" data-lang="bash" data-lang-label="Bash"> | ||
<pre class="line-numbers"><code class="prism language-bash" data-prism>appwrite deploy function</code></pre> | ||
</div> | ||
|
||
gewenyu99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<div class="notice"> | ||
<h2>Overwrite Warning</h2> | ||
<p> | ||
If you made changes in the Appwrite Console that is different from your <code>appwrite.json</code>, | ||
using the CLI deploy command will overwrite your console changes, such as execution schedule or permissions. | ||
Update your <code>appwrite.json</code> manually before deploying to avoid overwriting changes. | ||
</p> | ||
</div> | ||
|
||
<h3>Manual Deployment</h3> | ||
<p>You can upload your functions to be deployed using the Appwrite Console. The example below shows a simple Node.js function, but the same idea applies to any other language.</p> | ||
<div class="ide margin-bottom"> | ||
<pre class="line-numbers"><code class="prism" data-prism>. | ||
├── package.json | ||
└── index.js | ||
</code></pre> | ||
</div> | ||
|
||
<p>First, navigate inside the folder that contains your dependency file. Package your code files into the <code>.tar.gz</code> format with this tar command:</p> | ||
|
||
<ul class="phases clear" data-ui-phases> | ||
<li> | ||
<h3>Unix</h3> | ||
|
||
<div class="ide margin-bottom" data-lang="bash" data-lang-label="Bash"> | ||
<pre class="line-numbers"><code class="prism language-bash" data-prism>tar --exclude code.tar.gz -czf code.tar.gz .</code></pre> | ||
</div> | ||
</li> | ||
<li> | ||
<h3>CMD</h3> | ||
|
||
<div class="ide margin-bottom" data-lang="bash" data-lang-label="CMD"> | ||
<pre class="line-numbers"><code class="prism language-bash" data-prism>tar --exclude code.tar.gz -czf code.tar.gz .</code></pre> | ||
</div> | ||
</li> | ||
<li> | ||
<h3>PowerShell</h3> | ||
|
||
<div class="ide margin-bottom" data-lang="bash" data-lang-label="PowerShell"> | ||
<pre class="line-numbers"><code class="prism language-bash" data-prism>tar --exclude code.tar.gz -czf code.tar.gz .</code></pre> | ||
</div> | ||
</li> | ||
</ul> | ||
|
||
<p>Next, navigate to your Appwrite Console and upload the function.</p> | ||
|
||
<ol class="margin-top margin-bottom-large text-size-normal"> | ||
<li class="margin-bottom-small">Navigate to the function you want to deploy.</li> | ||
<li class="margin-bottom-small">Click <i class="icon-plus"></i> <b>Create deployment</b>.</li> | ||
<li class="margin-bottom-small">Select the <b>Manual</b> tab.</li> | ||
<li class="margin-bottom-small">Input the entry point of your function under <b>Entrypoint</b>. For the example above, it would be <code>index.js</code>.</li> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's also mention that users can also specify build commands. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point |
||
<li class="margin-bottom-small">Upload <code> code.tar.gz</code>.</li> | ||
<li class="margin-bottom-small">Select <b>Activate deployment after build</b> to use your new deployment.</li> | ||
<li class="margin-bottom-small">Click <b>Create</b> to deploy your function.</li> | ||
</ol> | ||
|
||
<h2><a href="#domains" id="domains">Domains</a></h2> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm a bit concerned here. Should this be in deploy, or execute section? 🤔 Your call, just wanted to bring in the chaos 😈 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both |
||
<p> | ||
Each deployed function can have its own domain. | ||
By default, one is generated for each of your functions. | ||
You can find the generated domain for your function like this. | ||
</p> | ||
|
||
<ol class="margin-top margin-bottom-large text-size-normal"> | ||
<li class="margin-bottom-small">Navigate to the Appwrite Console's <b>Functions</b> page.</li> | ||
<li class="margin-bottom-small">Navigate to the <b>Domains</b> tab.</li> | ||
<li class="margin-bottom-small">In the table, you'll find a link formatted similar to <code>https://64d4d22db370ae41a32e.appwrite.global</code>. This is your generated domain.</li> | ||
</ol> | ||
|
||
<p> | ||
You can also add a custom domain, which allows you to build custom REST APIs using nothing but Appwrite Functions. | ||
To do this, you need to first buy and register a domain. | ||
After obtaining a domain, follow these steps to add the domain to Appwrite. | ||
</p> | ||
|
||
<ol class="margin-top margin-bottom-large text-size-normal"> | ||
<li class="margin-bottom-small">Navigate to the Appwrite Console's <b>Functions</b> page.</li> | ||
<li class="margin-bottom-small">Navigate to the <b>Domains</b> tab.</li> | ||
<li class="margin-bottom-small">Click on <b>Create domain</b>.</li> | ||
<li class="margin-bottom-small">Input your domain in the <b>Domain</b> input field and click <b>Next</b>.</li> | ||
<li class="margin-bottom-small">Copy the <b>CNAME</b> record provided to you, and add it to your domain registrar.</li> | ||
<li class="margin-bottom-small">Click <b>Go to console</b> and wait for the domain name to be verified and certificate to generate.</li> | ||
</ol> | ||
|
||
<p> | ||
DNS records can take up to 48 hours to propagate after they're added. | ||
Please retry verification over the next 48 hours. | ||
If the domain verification still fails and you have confirmed DNS records are added correctly, please contact support. | ||
</p> | ||
|
||
<h2><a href="#debugging" id="debugging">Debugging Build</a></h2> | ||
<p>After deploying a function, you can find the status of the deployment and build logs in the Appwrite Console.</p> | ||
<ol class="margin-top margin-bottom-large text-size-normal"> | ||
<li>In Appwrite Console, navigate to <b>Functions</b>.</li> | ||
<li>Click to open a function you wish to inspect.</li> | ||
<li>Under the <b>Deployments</b> tab, you'll find the status of the current active deployment and previous inactive deployments.</li> | ||
<li>You can access build logs for the active deployment by clicking the <b>Build logs</b> button. You can click on an inactive function's three dots button to find their build logs.</li> | ||
</ol> | ||
|
||
<h2><a href="#redeploy" id="redeploy">Redeploy Builds</a></h2> | ||
<p> | ||
After updating the configuration of your Appwrite Function, you need to redeploy your function for the changes to take effect. | ||
You can also redeploy builds to retry failed builds. | ||
</p> | ||
<ol class="margin-top margin-bottom-large text-size-normal"> | ||
<li>In Appwrite Console, navigate to <b>Functions</b>.</li> | ||
<li>Click to open a function you wish to inspect.</li> | ||
<li>Under the <b>Deployments</b> tab, you'll find the status of the current active deployment.</li> | ||
<li>You can redeploy by clicking the triple-dots beside an execution, and hitting the <b>Redeploy</b> button.</li> | ||
</ol> | ||
<p> | ||
The redeployment behavior varies depending on how the initial deployment is created. | ||
For Git deployments, redeploy uses the same commit hash but updated function settings. | ||
For manual and CLI deployments, redeploy uses previously updated code but updated function settings. | ||
</p> |
Uh oh!
There was an error while loading. Please reload this page.