From eccfd870e4ca36e4c2db0cc12f0e448ceab37c75 Mon Sep 17 00:00:00 2001 From: Tudor Pipernea <69115828+tudorpip@users.noreply.github.com> Date: Tue, 30 Jul 2024 10:35:04 +0200 Subject: [PATCH 1/3] feat: add genezio preset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added genezio preset * Auto-generate genezio file * Enable custom names and default region for yaml file * Create genezio.yaml * Basic draft of genezio.md file * Update genezio.md * Update for the auto-generation of the yaml files * Update index.ts * Update genezio.md * Update genezio.md * Update genezio.md * Update genezio.md * Update genezio.md * Update genezio.md Co-authored-by: Andreia Ocănoaia * Update genezio.md * Update genezio.md * Update genezio.md * Reverted the accidental changes to _all.gen * Reverted the playground changes * Update genezio.md --------- Co-authored-by: Andreia Ocănoaia --- docs/2.deploy/20.providers/genezio.md | 44 ++++++++++++++++++++++ src/presets/_all.gen.ts | 2 + src/presets/_types.gen.ts | 4 +- src/presets/genezio/preset.ts | 20 ++++++++++ src/presets/genezio/utils.ts | 53 +++++++++++++++++++++++++++ 5 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 docs/2.deploy/20.providers/genezio.md create mode 100644 src/presets/genezio/preset.ts create mode 100644 src/presets/genezio/utils.ts diff --git a/docs/2.deploy/20.providers/genezio.md b/docs/2.deploy/20.providers/genezio.md new file mode 100644 index 0000000000..cafce9cd37 --- /dev/null +++ b/docs/2.deploy/20.providers/genezio.md @@ -0,0 +1,44 @@ +# Genezio + +> Deploy Nitro apps to Genezio. + +**Preset:** `genezio` + +:read-more{title="Genezio" to="https://genezio.com"} + +# Project Setup + +## 1. Install genezio CLI globally + +```bash +npm install genezio -g +``` + +## Build and deploy + +#### Build your Nitro project using the `Genezio` preset: + +```bash +nitro build --preset genezio +``` + +Building the project will automatically create a default `genezio.yaml` configuration file, if it doesn't already exist. + +By default, the name will be the one specified in the `package-lock.json` file, and the region will be set to `us-east-1`. + +To further customize the file to your needs, you can consult the +[official documentation](https://genezio.com/docs/project-structure/genezio-configuration-file/). + +## 2. Deploy your project + +Run the following command in your terminal: + +```bash +genezio deploy +``` + +For projects that set environment backends, you can check the following tutorial: [Genezio - Environment Variables](https://genezio.com/docs/project-structure/backend-environment-variables). + +## 3. Monitor your project +You can monitor and manage your application through the [Genezio App Dashboard](https://app.genez.io/dashboard). The dashboard URL, also provided after deployment, allows you to access comprehensive views of your project's status and logs. + diff --git a/src/presets/_all.gen.ts b/src/presets/_all.gen.ts index 381e168a9b..a4ae251bff 100644 --- a/src/presets/_all.gen.ts +++ b/src/presets/_all.gen.ts @@ -14,6 +14,7 @@ import _digitalocean from "./digitalocean/preset"; import _edgio from "./edgio/preset"; import _firebase from "./firebase/preset"; import _flightcontrol from "./flightcontrol/preset"; +import _genezio from "./genezio/preset"; import _heroku from "./heroku/preset"; import _iis from "./iis/preset"; import _koyeb from "./koyeb/preset"; @@ -41,6 +42,7 @@ export default [ ..._edgio, ..._firebase, ..._flightcontrol, + ..._genezio, ..._heroku, ..._iis, ..._koyeb, diff --git a/src/presets/_types.gen.ts b/src/presets/_types.gen.ts index 3ee32c8a66..c2b499e156 100644 --- a/src/presets/_types.gen.ts +++ b/src/presets/_types.gen.ts @@ -16,6 +16,6 @@ export interface PresetOptions { vercel: VercelOptions; } -export type PresetName = "alwaysdata" | "aws-amplify" | "aws-lambda" | "aws-lambda-streaming" | "azure" | "azure-functions" | "azure-swa" | "base-worker" | "bun" | "cleavr" | "cli" | "cloudflare" | "cloudflare-module" | "cloudflare-pages" | "cloudflare-pages-static" | "cloudflare-worker" | "deno" | "deno-deploy" | "deno-server" | "digital-ocean" | "edgio" | "firebase" | "flight-control" | "github-pages" | "gitlab-pages" | "heroku" | "iis" | "iis-handler" | "iis-node" | "koyeb" | "layer0" | "netlify" | "netlify-builder" | "netlify-edge" | "netlify-legacy" | "netlify-static" | "nitro-dev" | "nitro-prerender" | "node" | "node-cluster" | "node-listener" | "node-server" | "platform-sh" | "render-com" | "service-worker" | "static" | "stormkit" | "vercel" | "vercel-edge" | "vercel-static" | "winterjs" | "zeabur" | "zeabur-static"; +export type PresetName = "alwaysdata" | "aws-amplify" | "aws-lambda" | "aws-lambda-streaming" | "azure" | "azure-functions" | "azure-swa" | "base-worker" | "bun" | "cleavr" | "cli" | "cloudflare" | "cloudflare-module" | "cloudflare-pages" | "cloudflare-pages-static" | "cloudflare-worker" | "deno" | "deno-deploy" | "deno-server" | "digital-ocean" | "edgio" | "firebase" | "flight-control" | "genezio" | "github-pages" | "gitlab-pages" | "heroku" | "iis" | "iis-handler" | "iis-node" | "koyeb" | "layer0" | "netlify" | "netlify-builder" | "netlify-edge" | "netlify-legacy" | "netlify-static" | "nitro-dev" | "nitro-prerender" | "node" | "node-cluster" | "node-listener" | "node-server" | "platform-sh" | "render-com" | "service-worker" | "static" | "stormkit" | "vercel" | "vercel-edge" | "vercel-static" | "winterjs" | "zeabur" | "zeabur-static"; -export type PresetNameInput = "alwaysdata" | "aws-amplify" | "awsAmplify" | "aws_amplify" | "aws-lambda" | "awsLambda" | "aws_lambda" | "aws-lambda-streaming" | "awsLambdaStreaming" | "aws_lambda_streaming" | "azure" | "azure-functions" | "azureFunctions" | "azure_functions" | "azure-swa" | "azureSwa" | "azure_swa" | "base-worker" | "baseWorker" | "base_worker" | "bun" | "cleavr" | "cli" | "cloudflare" | "cloudflare-module" | "cloudflareModule" | "cloudflare_module" | "cloudflare-pages" | "cloudflarePages" | "cloudflare_pages" | "cloudflare-pages-static" | "cloudflarePagesStatic" | "cloudflare_pages_static" | "cloudflare-worker" | "cloudflareWorker" | "cloudflare_worker" | "deno" | "deno-deploy" | "denoDeploy" | "deno_deploy" | "deno-server" | "denoServer" | "deno_server" | "digital-ocean" | "digitalOcean" | "digital_ocean" | "edgio" | "firebase" | "flight-control" | "flightControl" | "flight_control" | "github-pages" | "githubPages" | "github_pages" | "gitlab-pages" | "gitlabPages" | "gitlab_pages" | "heroku" | "iis" | "iis-handler" | "iisHandler" | "iis_handler" | "iis-node" | "iisNode" | "iis_node" | "koyeb" | "layer0" | "netlify" | "netlify-builder" | "netlifyBuilder" | "netlify_builder" | "netlify-edge" | "netlifyEdge" | "netlify_edge" | "netlify-legacy" | "netlifyLegacy" | "netlify_legacy" | "netlify-static" | "netlifyStatic" | "netlify_static" | "nitro-dev" | "nitroDev" | "nitro_dev" | "nitro-prerender" | "nitroPrerender" | "nitro_prerender" | "node" | "node-cluster" | "nodeCluster" | "node_cluster" | "node-listener" | "nodeListener" | "node_listener" | "node-server" | "nodeServer" | "node_server" | "platform-sh" | "platformSh" | "platform_sh" | "render-com" | "renderCom" | "render_com" | "service-worker" | "serviceWorker" | "service_worker" | "static" | "stormkit" | "vercel" | "vercel-edge" | "vercelEdge" | "vercel_edge" | "vercel-static" | "vercelStatic" | "vercel_static" | "winterjs" | "zeabur" | "zeabur-static" | "zeaburStatic" | "zeabur_static" | (string & {}); +export type PresetNameInput = "alwaysdata" | "aws-amplify" | "awsAmplify" | "aws_amplify" | "aws-lambda" | "awsLambda" | "aws_lambda" | "aws-lambda-streaming" | "awsLambdaStreaming" | "aws_lambda_streaming" | "azure" | "azure-functions" | "azureFunctions" | "azure_functions" | "azure-swa" | "azureSwa" | "azure_swa" | "base-worker" | "baseWorker" | "base_worker" | "bun" | "cleavr" | "cli" | "cloudflare" | "cloudflare-module" | "cloudflareModule" | "cloudflare_module" | "cloudflare-pages" | "cloudflarePages" | "cloudflare_pages" | "cloudflare-pages-static" | "cloudflarePagesStatic" | "cloudflare_pages_static" | "cloudflare-worker" | "cloudflareWorker" | "cloudflare_worker" | "deno" | "deno-deploy" | "denoDeploy" | "deno_deploy" | "deno-server" | "denoServer" | "deno_server" | "digital-ocean" | "digitalOcean" | "digital_ocean" | "edgio" | "firebase" | "flight-control" | "flightControl" | "flight_control" | "genezio" | "github-pages" | "githubPages" | "github_pages" | "gitlab-pages" | "gitlabPages" | "gitlab_pages" | "heroku" | "iis" | "iis-handler" | "iisHandler" | "iis_handler" | "iis-node" | "iisNode" | "iis_node" | "koyeb" | "layer0" | "netlify" | "netlify-builder" | "netlifyBuilder" | "netlify_builder" | "netlify-edge" | "netlifyEdge" | "netlify_edge" | "netlify-legacy" | "netlifyLegacy" | "netlify_legacy" | "netlify-static" | "netlifyStatic" | "netlify_static" | "nitro-dev" | "nitroDev" | "nitro_dev" | "nitro-prerender" | "nitroPrerender" | "nitro_prerender" | "node" | "node-cluster" | "nodeCluster" | "node_cluster" | "node-listener" | "nodeListener" | "node_listener" | "node-server" | "nodeServer" | "node_server" | "platform-sh" | "platformSh" | "platform_sh" | "render-com" | "renderCom" | "render_com" | "service-worker" | "serviceWorker" | "service_worker" | "static" | "stormkit" | "vercel" | "vercel-edge" | "vercelEdge" | "vercel_edge" | "vercel-static" | "vercelStatic" | "vercel_static" | "winterjs" | "zeabur" | "zeabur-static" | "zeaburStatic" | "zeabur_static" | (string & {}); diff --git a/src/presets/genezio/preset.ts b/src/presets/genezio/preset.ts new file mode 100644 index 0000000000..8ee4508812 --- /dev/null +++ b/src/presets/genezio/preset.ts @@ -0,0 +1,20 @@ +import { defineNitroPreset } from "nitropack/kit"; +import type { Nitro } from "nitropack/types"; +import { generateFunctionFiles } from "./utils"; + +const genezio = defineNitroPreset( + { + extends: "aws_lambda", + hooks: { + async compiled(nitro: Nitro) { + await generateFunctionFiles(nitro); + }, + }, + }, + { + name: "genezio" as const, + stdName: "genezio", + url: import.meta.url, + } +); +export default [genezio] as const; diff --git a/src/presets/genezio/utils.ts b/src/presets/genezio/utils.ts new file mode 100644 index 0000000000..50cb465e1d --- /dev/null +++ b/src/presets/genezio/utils.ts @@ -0,0 +1,53 @@ +import { resolve, dirname } from "pathe"; +import fsp from "node:fs/promises"; +import type { Nitro } from "nitropack/types"; +export async function generateFunctionFiles(nitro: Nitro) { + const name = await getNameFromPackage(); + const initialPath = dirname(nitro.options.output.dir); + const genezioConfigPath = resolve(initialPath, "genezio.yaml"); + const genezioConfigContent = ` + # The name of the project. + name: ${name} + # The version of the Genezio YAML configuration to parse. + yamlVersion: 2 + backend: + # The root directory of the backend. + path: .output/ + # Information about the backend's programming language. + language: + # The name of the programming language. + name: js + # The package manager used by the backend. + packageManager: npm + # Information about the backend's functions. + functions: + # The name (label) of the function. + - name: nitroServer + # The path to the function's code. + path: server/ + # The name of the function handler + handler: handler + # The entry point for the function. + entry: index.mjs + `.trim(); + try { + await fsp.writeFile(genezioConfigPath, genezioConfigContent, { + flag: "wx", + }); + } catch { + return; + } +} +async function getNameFromPackage() { + const defaultName = "nitro-app"; + try { + const packageLockContent = await fsp.readFile("package-lock.json", "utf8"); + const packageLockJson = JSON.parse(packageLockContent); + if (packageLockJson.name) { + return packageLockJson.name; + } + return defaultName; + } catch { + return defaultName; + } +} From 24e7c1ac2f81cfa78901b6fd29df529c24ebfa7e Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 5 Sep 2024 12:55:53 +0000 Subject: [PATCH 2/3] chore: apply automated updates --- src/presets/genezio/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/presets/genezio/utils.ts b/src/presets/genezio/utils.ts index 50cb465e1d..f6a7398495 100644 --- a/src/presets/genezio/utils.ts +++ b/src/presets/genezio/utils.ts @@ -1,6 +1,6 @@ -import { resolve, dirname } from "pathe"; import fsp from "node:fs/promises"; import type { Nitro } from "nitropack/types"; +import { dirname, resolve } from "pathe"; export async function generateFunctionFiles(nitro: Nitro) { const name = await getNameFromPackage(); const initialPath = dirname(nitro.options.output.dir); From 380f377b32bcd8e78a306f0e9e28b82c719af033 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 5 Sep 2024 15:21:06 +0200 Subject: [PATCH 3/3] apply updates to iterate faster --- docs/2.deploy/20.providers/genezio.md | 65 ++++++++++++++++++--------- src/presets/genezio/preset.ts | 8 ---- src/presets/genezio/utils.ts | 53 ---------------------- 3 files changed, 45 insertions(+), 81 deletions(-) delete mode 100644 src/presets/genezio/utils.ts diff --git a/docs/2.deploy/20.providers/genezio.md b/docs/2.deploy/20.providers/genezio.md index cafce9cd37..8936d81d21 100644 --- a/docs/2.deploy/20.providers/genezio.md +++ b/docs/2.deploy/20.providers/genezio.md @@ -6,38 +6,63 @@ :read-more{title="Genezio" to="https://genezio.com"} -# Project Setup +> [!NOTE] +> This preset available via [nightly channel](https://nitro.unjs.io/guide/nightly) to try. + + +## 1. Project Setup + +Create `genezio.yaml` file: + +```yaml +# The name of the project. +name: nitro-app +# The version of the Genezio YAML configuration to parse. +yamlVersion: 2 +backend: + # The root directory of the backend. + path: .output/ + # Information about the backend's programming language. + language: + # The name of the programming language. + name: js + # The package manager used by the backend. + packageManager: npm + # Information about the backend's functions. + functions: + # The name (label) of the function. + - name: nitroServer + # The path to the function's code. + path: server/ + # The name of the function handler + handler: handler + # The entry point for the function. + entry: index.mjs +``` -## 1. Install genezio CLI globally +::read-more{to="https://genezio.com/docs/project-structure/genezio-configuration-file/"} +To further customize the file to your needs, you can consult the +[official documentation](https://genezio.com/docs/project-structure/genezio-configuration-file/). +:: -```bash -npm install genezio -g -``` -## Build and deploy +## 2. Deploy your project -#### Build your Nitro project using the `Genezio` preset: +Build with the genezio nitro preset: ```bash -nitro build --preset genezio +NITRO_PRESET=genezio npm run build ``` -Building the project will automatically create a default `genezio.yaml` configuration file, if it doesn't already exist. -By default, the name will be the one specified in the `package-lock.json` file, and the region will be set to `us-east-1`. +Deploy with [`genezio`](https://npmjs.com/package/genezio) cli: -To further customize the file to your needs, you can consult the -[official documentation](https://genezio.com/docs/project-structure/genezio-configuration-file/). - -## 2. Deploy your project +:pm-x{command="genezio deploy"} -Run the following command in your terminal: - -```bash -genezio deploy -``` +::read-more{title="Backend Environment Variables" to="https://genezio.com/docs/project-structure/backend-environment-variables"} +To set environment viarables, please check out [Genezio - Environment Variables](https://genezio.com/docs/project-structure/backend-environment-variables). +:: -For projects that set environment backends, you can check the following tutorial: [Genezio - Environment Variables](https://genezio.com/docs/project-structure/backend-environment-variables). ## 3. Monitor your project You can monitor and manage your application through the [Genezio App Dashboard](https://app.genez.io/dashboard). The dashboard URL, also provided after deployment, allows you to access comprehensive views of your project's status and logs. diff --git a/src/presets/genezio/preset.ts b/src/presets/genezio/preset.ts index 8ee4508812..316e39e5d9 100644 --- a/src/presets/genezio/preset.ts +++ b/src/presets/genezio/preset.ts @@ -1,19 +1,11 @@ import { defineNitroPreset } from "nitropack/kit"; -import type { Nitro } from "nitropack/types"; -import { generateFunctionFiles } from "./utils"; const genezio = defineNitroPreset( { extends: "aws_lambda", - hooks: { - async compiled(nitro: Nitro) { - await generateFunctionFiles(nitro); - }, - }, }, { name: "genezio" as const, - stdName: "genezio", url: import.meta.url, } ); diff --git a/src/presets/genezio/utils.ts b/src/presets/genezio/utils.ts deleted file mode 100644 index f6a7398495..0000000000 --- a/src/presets/genezio/utils.ts +++ /dev/null @@ -1,53 +0,0 @@ -import fsp from "node:fs/promises"; -import type { Nitro } from "nitropack/types"; -import { dirname, resolve } from "pathe"; -export async function generateFunctionFiles(nitro: Nitro) { - const name = await getNameFromPackage(); - const initialPath = dirname(nitro.options.output.dir); - const genezioConfigPath = resolve(initialPath, "genezio.yaml"); - const genezioConfigContent = ` - # The name of the project. - name: ${name} - # The version of the Genezio YAML configuration to parse. - yamlVersion: 2 - backend: - # The root directory of the backend. - path: .output/ - # Information about the backend's programming language. - language: - # The name of the programming language. - name: js - # The package manager used by the backend. - packageManager: npm - # Information about the backend's functions. - functions: - # The name (label) of the function. - - name: nitroServer - # The path to the function's code. - path: server/ - # The name of the function handler - handler: handler - # The entry point for the function. - entry: index.mjs - `.trim(); - try { - await fsp.writeFile(genezioConfigPath, genezioConfigContent, { - flag: "wx", - }); - } catch { - return; - } -} -async function getNameFromPackage() { - const defaultName = "nitro-app"; - try { - const packageLockContent = await fsp.readFile("package-lock.json", "utf8"); - const packageLockJson = JSON.parse(packageLockContent); - if (packageLockJson.name) { - return packageLockJson.name; - } - return defaultName; - } catch { - return defaultName; - } -}