-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[yaml-v2] Update Backend Deployment feature (#39)
- Loading branch information
Showing
3 changed files
with
160 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,171 @@ | ||
--- | ||
sidebar_position: 1 | ||
--- | ||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
import Admonition from '@theme/Admonition'; | ||
|
||
# Backend Deployment | ||
|
||
Genezio offers a seamless and efficient solution for deploying backend logic. The platform leverages a function-as-a-service infrastructure, allowing users to deploy their backend classes easily with a simple command: `genezio deploy`.  | ||
|
||
<!-- {% hint style="success" %} --> | ||
|
||
:::tip | ||
You can deploy classes written in TypeScript, JavaScript, and Dart (experimental). | ||
You can deploy classes written in TypeScript, JavaScript, Go (experimental) and Dart (experimental). | ||
::: | ||
|
||
<!-- ::: --> | ||
|
||
## Code Structure | ||
|
||
To deploy with genezio, your code has to be structured in classes. Mark your classes for deployment with the `GenezioDeploy` decorator. This decorator also enables you to set the default type of the methods implemented in the specific class to `jsonrpc`, `http` or `cron`. | ||
|
||
<!-- :::info --> | ||
|
||
:::info | ||
Our recommendation is to use the official genezio templates and examples to be provided with fully written configuration files without having to write one from scratch. | ||
:::warning | ||
We do not recommend you to manually create your projects. You should instead use the `genezio create` command to create a new project. This command will generate a project with the correct structure and configuration files. | ||
|
||
Check out this tutorial to learn how to [create-your-first-project](../getting-started "mention") with genezio. | ||
::: | ||
|
||
<!-- ::: --> | ||
## Code Structure | ||
|
||
A snippet of a class that can be deployed with genezio is below: | ||
To deploy with genezio, your code has to be structured in classes. Each public method of the class will be deployed as a separate function. | ||
|
||
<!-- {% code title="index.ts" %} --> | ||
The following snippet of code shows a simple `HelloWorldService` class: | ||
|
||
```typescript title="index.ts" showLineNumbers | ||
import { GenezioDeploy } from "@genezio/types"; | ||
<Tabs groupId="languages"> | ||
<TabItem value="ts" label="TypeScript"> | ||
```ts title="service.ts" showLineNumbers | ||
import { GenezioDeploy } from "@genezio/types"; | ||
|
||
@GenezioDeploy() | ||
export class HelloWorldService { | ||
hello(name: string, sender: string): string { | ||
console.log( | ||
`Hello world request received with name ${name} from ${sender}!` | ||
); | ||
return `Hello, ${name}, from ${sender}!`; | ||
} | ||
} | ||
``` | ||
@GenezioDeploy() | ||
export class HelloWorldService { | ||
hello(name: string, sender: string): string { | ||
console.log(`Hello world request received with name ${name} from ${sender}!`); | ||
|
||
<!-- {% endcode %} --> | ||
return `Hello, ${name}, from ${sender}!`; | ||
} | ||
} | ||
``` | ||
|
||
## Configuration file | ||
</TabItem> | ||
<TabItem value="js" label="JavaScript"> | ||
```js title="service.js" showLineNumbers | ||
import { GenezioDeploy } from "@genezio/types"; | ||
|
||
To deploy your code, your project needs a minimum configuration file that sets various configurations for the project such as name, region to deploy to, and so on. A minimum `genezio.yaml` to deploy a project should look like this: | ||
@GenezioDeploy() | ||
export class HelloWorldService { | ||
hello(name, sender) { | ||
console.log(`Hello world request received with name ${name} from ${sender}!`); | ||
|
||
<!-- {% code title="genezio.yaml" %} --> | ||
return `Hello, ${name}, from ${sender}!`; | ||
} | ||
} | ||
``` | ||
|
||
```yaml title="genezio.yaml" showLineNumbers | ||
name: my-project-backend | ||
region: us-east-1 | ||
language: ts | ||
cloudProvider: genezio | ||
packageManager: npm | ||
``` | ||
</TabItem> | ||
<TabItem value="go" label="Go"> | ||
```go title="service.go" showLineNumbers | ||
type HelloWorldService struct {} | ||
|
||
<!-- {% endcode %} --> | ||
// Required. Will run when the HelloWorldService "class" is constructed. | ||
func New() HelloWorldService { | ||
return HelloWorldService{} | ||
} | ||
|
||
For more details on the `genezio.yaml` file, check the [genezio-configuration-file](../project-structure/genezio-configuration-file "mention") section. | ||
func (s HelloWorldService) Hello(name string, sender string) string { | ||
fmt.Println("Hello world request received with name", name, "from", sender, "!") | ||
|
||
<!-- :::info --> | ||
return "Hello, " + name + ", from " + sender + "!" | ||
} | ||
``` | ||
|
||
:::info | ||
For Dart backend code, a classes list should also be set in the `genezio.yaml`. Check the classes section from [#configuration-file](../project-structure/genezio-configuration-file "mention") | ||
for more information. | ||
::: | ||
<Admonition type="tip"> | ||
The `New` function is required in Go because, unlike TypeScript and JavaScript, Go does not embrace OOP, therefore there is no way to specify a `struct` constructor. | ||
</Admonition> | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
<!-- ::: --> | ||
## Configuration file | ||
|
||
The `genezio.yaml` configuration file is the file that genezio uses to understand how to deploy your project. It contains information about the project, such as the name, region, and the backend details. | ||
|
||
<Tabs groupId="languages"> | ||
<TabItem value="ts" label="TypeScript"> | ||
```yaml title="genezio.yaml" showLineNumbers | ||
name: my-backend | ||
region: us-east-1 | ||
yamlVersion: 2 | ||
backend: | ||
path: . | ||
language: | ||
name: ts | ||
runtime: nodejs20.x | ||
classes: | ||
- path: service.ts | ||
``` | ||
|
||
<Admonition type="tip"> | ||
The `classes` field can be omitted if the classes are decorated with `@GenezioDeploy()`. Learn more about decorators in the [Decorators](../project-structure/genezio-decorators "mention") section. | ||
|
||
If a class is neither decorated or specified in the `genezio.yaml` file, it will not be deployed. | ||
</Admonition> | ||
|
||
</TabItem> | ||
<TabItem value="js" label="JavaScript"> | ||
```yaml title="genezio.yaml" showLineNumbers | ||
name: my-backend | ||
region: us-east-1 | ||
yamlVersion: 2 | ||
backend: | ||
path: . | ||
language: | ||
name: js | ||
runtime: nodejs20.x | ||
classes: | ||
- path: service.js | ||
``` | ||
|
||
<Admonition type="tip"> | ||
The `classes` field can be omitted if the classes are decorated with `@GenezioDeploy()`. | ||
|
||
If a class is neither decorated or specified in the `genezio.yaml` file, it will not be deployed. | ||
</Admonition> | ||
|
||
</TabItem> | ||
<TabItem value="go" label="Go"> | ||
```yaml title="genezio.yaml" showLineNumbers | ||
name: my-backend | ||
region: us-east-1 | ||
yamlVersion: 2 | ||
backend: | ||
path: . | ||
language: | ||
name: go | ||
classes: | ||
- path: service.go | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
For more details on the `genezio.yaml` configuration file features, check the [Genezio Configuration File](../project-structure/genezio-configuration-file "mention") section. | ||
|
||
## Deploy your project | ||
|
||
The command to deploy has to be executed at the same path where `genezio.yaml`is saved: | ||
After you have written your classes and configured the `genezio.yaml` file, you can deploy your project by running the following command: | ||
|
||
``` | ||
```sh title="Terminal" | ||
genezio deploy | ||
``` | ||
|
||
Executing `genezio deploy` will deploy the `HelloWorldService`class implemented in the snippet above. | ||
|
||
## Testing | ||
|
||
webhooks | ||
You can make requests to the remote server either by using the[ testing functionality from the genezio dashboard](testing), or by using a client application - such as a React app. | ||
After deploying, you can make requests to the remote server by: | ||
|
||
To call the methods implemented in the `HelloWorldService`, you can make use of the genezio generated SDK for your project. Check [generated-sdk](generated-sdk "mention") section to find out how to install it in your project. | ||
- using the [testing functionality](testing) from the genezio dashboard | ||
- building a client application that uses the generated type safe SDK - such as a React app or a CLI | ||
- Check the [Generated Sdk](generated-sdk "mention") section to find out how to use the Genezio SDK in your project. | ||
|
||
## Next Steps <a href="#next-steps" id="next-steps"></a> | ||
## Next Steps | ||
|
||
Now let's see how to schedule the execution of a function as a cron job, or implement HTTP Webhooks: | ||
|
||
- [Cron Jobs](cron-methods) | ||
- [HTTP Webhooks](http-methods-webhooks) | ||
- [Cron Jobs](cron-methods) | ||
- [HTTP Webhooks](http-methods-webhooks) | ||
|
||
Now you are ready for some more advanced use cases: | ||
|
||
- [Web3 Application](https://genezio.com/blog/create-your-first-web3-app/) | ||
- [ChatGPT App](https://genezio.com/blog/create-your-first-app-using-chatgpt/) | ||
- [Shopping Cart Implementation](https://genezio.com/blog/implement-a-shopping-cart-using-typescript-redis-and-react/) | ||
- [Web3 Application](https://genezio.com/blog/create-your-first-web3-app/) | ||
- [ChatGPT App](https://genezio.com/blog/create-your-first-app-using-chatgpt/) | ||
- [Shopping Cart Implementation](https://genezio.com/blog/implement-a-shopping-cart-using-typescript-redis-and-react/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters