From 51785f08537ce8a92b979f45aa2d5d06c3582c6d Mon Sep 17 00:00:00 2001 From: Dovi Cowan Date: Fri, 26 Jul 2024 01:05:57 +0100 Subject: [PATCH] deploy appwrite function --- .forgejo/workflows/demo.yaml | 8 +- .gitignore | 1 + appwrite.json | 24 ++++++ functions/demo-web/.gitignore | 130 ++++++++++++++++++++++++++++++++ functions/demo-web/README.md | 46 +++++++++++ functions/demo-web/package.json | 16 ++++ functions/demo-web/src/main.js | 19 +++++ package.json | 5 ++ 8 files changed, 247 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 appwrite.json create mode 100644 functions/demo-web/.gitignore create mode 100644 functions/demo-web/README.md create mode 100644 functions/demo-web/package.json create mode 100644 functions/demo-web/src/main.js create mode 100644 package.json diff --git a/.forgejo/workflows/demo.yaml b/.forgejo/workflows/demo.yaml index 0270eb4..83976a0 100644 --- a/.forgejo/workflows/demo.yaml +++ b/.forgejo/workflows/demo.yaml @@ -4,5 +4,9 @@ jobs: steps: - uses: actions/checkout@v4 - run: | - echo $PWD - ls -la \ No newline at end of file + npm install + npx appwrite client \ + --endpoint ${{ vars.APPWRITE_ENDPOINT }} \ + --projectId ${{ vars.APPWRITE_PROJECT_ID }} \ + --key ${{ secrets.APPWRITE_API_KEY }} + npx appwrite deploy function --all \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..40b878d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/appwrite.json b/appwrite.json new file mode 100644 index 0000000..913b481 --- /dev/null +++ b/appwrite.json @@ -0,0 +1,24 @@ +{ + "projectId": "66a2d6c20021107d3343", + "projectName": "Forgejo Actions Test", + "functions": [ + { + "$id": "66a2d6e74666ca0797f7", + "name": "demo-web", + "runtime": "node-20.0", + "execute": [ "any" ], + "events": [], + "schedule": "", + "timeout": 15, + "enabled": true, + "logging": true, + "entrypoint": "src/main.js", + "commands": "npm install", + "ignore": [ + "node_modules", + ".npm" + ], + "path": "functions/demo-web" + } + ] +} \ No newline at end of file diff --git a/functions/demo-web/.gitignore b/functions/demo-web/.gitignore new file mode 100644 index 0000000..6a7d6d8 --- /dev/null +++ b/functions/demo-web/.gitignore @@ -0,0 +1,130 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp +.cache + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* \ No newline at end of file diff --git a/functions/demo-web/README.md b/functions/demo-web/README.md new file mode 100644 index 0000000..ed64686 --- /dev/null +++ b/functions/demo-web/README.md @@ -0,0 +1,46 @@ +# demo-web + +## 🧰 Usage + +### GET / + +- Returns a "Hello, World!" message. + +**Response** + +Sample `200` Response: + +```text +Hello, World! +``` + +### POST, PUT, PATCH, DELETE / + +- Returns a "Learn More" JSON response. + +**Response** + +Sample `200` Response: + +```json +{ + "motto": "Build like a team of hundreds_", + "learn": "https://appwrite.io/docs", + "connect": "https://appwrite.io/discord", + "getInspired": "https://builtwith.appwrite.io" +} +``` + +## ⚙️ Configuration + +| Setting | Value | +|-------------------|---------------| +| Runtime | Node (20.0) | +| Entrypoint | `src/main.js` | +| Build Commands | `npm install` | +| Permissions | `any` | +| Timeout (Seconds) | 15 | + +## 🔒 Environment Variables + +No environment variables required. diff --git a/functions/demo-web/package.json b/functions/demo-web/package.json new file mode 100644 index 0000000..0f8d361 --- /dev/null +++ b/functions/demo-web/package.json @@ -0,0 +1,16 @@ +{ + "name": "starter-template", + "version": "1.0.0", + "description": "", + "main": "src/main.js", + "type": "module", + "scripts": { + "format": "prettier --write ." + }, + "dependencies": { + "node-appwrite": "^13.0.0" + }, + "devDependencies": { + "prettier": "^3.2.5" + } +} diff --git a/functions/demo-web/src/main.js b/functions/demo-web/src/main.js new file mode 100644 index 0000000..a6669f5 --- /dev/null +++ b/functions/demo-web/src/main.js @@ -0,0 +1,19 @@ +// This is your Appwrite function +// It's executed each time we get a request +export default async ({ req, res, log, error }) => { + + // The `req` object contains the request data + if (req.method === 'GET') { + switch (req.path) { + case "/": + return res.send('Hello, World!'); + break; + + default: + return res.send("Invalid route", 404) + break; + } + } + + return res.send("Invalid request", 405) +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..702a73d --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "appwrite-cli": "^5.0.5" + } +}