Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add self-host instructions to Go tutorials #1636

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion docs/go/tutorials/graphql.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,43 @@ query {

And you should get back `https://encore.dev`.

## 7. Deploy to the cloud

## 7. Deploy

<Accordion>

### Self-hosting

Encore supports building Docker images directly from the CLI, which can then be self-hosted on your own infrastructure of choice.

If your app is using infrastructure resources, such as SQL databases, Pub/Sub, or metrics, you will need to supply a [runtime configuration](/docs/go/self-host/configure-infra) your Docker image.

🥐 Build a Docker image by running `encore build docker graphql:v1.0`.

This will compile your application using the host machine and then produce a Docker image containing the compiled application.

🥐 Upload the Docker image to the cloud provider of your choice and run it.

</Accordion>

<Accordion>

### Deploy to Encore Cloud

Encore Cloud provides automated infrastructure and DevOps. Deploy to a free development environment or to your own cloud account on AWS or GCP.

### Create account

Before deploying with Encore Cloud, you need to have a free Encore Cloud account and link your app to the platform. If you already have an account, you can move on to the next step.

If you don’t have an account, the simplest way to get set up is by running `encore app create` and selecting **Y** when prompted to create a new account. Once your account is set up, continue creating a new app, selecting the `empty app` template.

After creating the app, copy your project files into the new app directory, ensuring that you do not replace the `encore.app` file (this file holds a unique id which links your app to the platform).

### Commit changes

The final step before you deploy is to commit all changes to the project repo.


Push your changes and deploy your application to Encore's free development cloud by running:

Expand Down Expand Up @@ -282,6 +318,8 @@ _From here you can easily access all Cloud Dashboard features and for example ju

![Fireworks](/assets/docs/fireworks.jpg)

</Accordion>

## Conclusion

We've now built a GraphQL API gateway that forwards requests to the application's
Expand Down
62 changes: 59 additions & 3 deletions docs/go/tutorials/rest-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,61 @@ func TestShortenAndRetrieve(t *testing.T) {

If you use the local development dashboard ([localhost:9400](http://localhost:9400)), you can even see traces for tests.

## 5. Deploy to the cloud
## 5. Deploy

<Accordion>

### Self-hosting

Encore supports building Docker images directly from the CLI, which can then be self-hosted on your own infrastructure of choice.

If your app is using infrastructure resources, such as SQL databases, Pub/Sub, or metrics, you will need to configure your Docker image with the necessary configuration.
Our URL shortener makes use of a PostgreSQL database, so we'll need to supply a [runtime configuration](/docs/go/self-host/configure-infra) so that our app knows how to connect to the database in the cloud.

🥐 Create a new file `infra-config.json` in the root of your project with the following contents:

```json
{
"$schema": "https://encore.dev/schemas/infra.schema.json",
"sql_servers": [
{
"host": "my-db-host:5432",
"databases": {
"url": {
"username": "my-db-owner",
"password": {"$env": "DB_PASSWORD"}
}
}
}
]
}
```

The values in this configuration are just examples, you will need to replace them with the correct values for your database.

🥐 Build a Docker image by running `encore build docker url-shortener:v1.0`.

This will compile your application using the host machine and then produce a Docker image containing the compiled application.

🥐 Upload the Docker image to the cloud provider of your choice and run it.

</Accordion>

<Accordion>

### Encore Cloud (free)

Encore Cloud provides automated infrastructure and DevOps. Deploy to a free development environment or to your own cloud account on AWS or GCP.

### Create account

Before deploying with Encore Cloud, you need to have a free Encore Cloud account and link your app to the platform. If you already have an account, you can move on to the next step.

If you don’t have an account, the simplest way to get set up is by running `encore app create` and selecting **Y** when prompted to create a new account. Once your account is set up, continue creating a new app, selecting the `empty app` template.

After creating the app, copy your project files into the new app directory, ensuring that you do not replace the `encore.app` file (this file holds a unique id which links your app to the platform).

### Commit changes

The final step before you deploy is to commit all changes to the project repo.

Expand Down Expand Up @@ -341,10 +395,12 @@ _From here you can easily access all Cloud Dashboard features and for example ju

![Fireworks](/assets/docs/fireworks.jpg)

🥐 A great next step is to [integrate with GitHub](/docs/platform/integrations/github). Once you've linked with GitHub, Encore will automatically start building and running tests against your Pull Requests.

</Accordion>

## What's next

Now that you know how to build a backend with a database, you're ready to let your creativity flow and begin building your next great idea!

🥐 A great next step is to [integrate with GitHub](/docs/platform/integrations/github). Once you've linked with GitHub, Encore will automatically start building and running tests against your Pull Requests.

We're excited to hear what you're going to build with Encore, join the pioneering developer community on [Discord](/discord) and share your story.
82 changes: 80 additions & 2 deletions docs/go/tutorials/uptime.md
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,66 @@ func Status(ctx context.Context) (*StatusResponse, error) {

Now try visiting http://localhost:4000/frontend in your browser again. This time you should see a working frontend that lists all sites and their current status.

## 5. Deploy to Encore's development cloud
## 5. Deploy

To try out your uptime monitor for real, let's deploy it to Encore's free development cloud.
To try out your uptime monitor for real, let's deploy it to the cloud.

<Accordion>

### Self-hosting

Encore supports building Docker images directly from the CLI, which can then be self-hosted on your own infrastructure of choice.

If your app is using infrastructure resources, such as SQL databases, Pub/Sub, or metrics, you will need to supply a [runtime configuration](/docs/go/self-host/configure-infra) your Docker image.

🥐 Create a new file `infra-config.json` in the root of your project with the following contents:

```json
{
"$schema": "https://encore.dev/schemas/infra.schema.json",
"sql_servers": [
{
"host": "my-db-host:5432",
"databases": {
"monitor": {
"username": "my-db-owner",
"password": {"$env": "DB_PASSWORD"}
},
"site": {
"username": "my-db-owner",
"password": {"$env": "DB_PASSWORD"}
}
}
}
]
}
```

The values in this configuration are just examples, you will need to replace them with the correct values for your database.

🥐 Build a Docker image by running `encore build docker uptime:v1.0`.

This will compile your application using the host machine and then produce a Docker image containing the compiled application.

🥐 Upload the Docker image to the cloud provider of your choice and run it.

</Accordion>

<Accordion>

### Encore Cloud (free)

Encore Cloud provides automated infrastructure and DevOps. Deploy to a free development environment or to your own cloud account on AWS or GCP.

### Create account

Before deploying with Encore Cloud, you need to have a free Encore Cloud account and link your app to the platform. If you already have an account, you can move on to the next step.

If you don’t have an account, the simplest way to get set up is by running `encore app create` and selecting **Y** when prompted to create a new account. Once your account is set up, continue creating a new app, selecting the `empty app` template.

After creating the app, copy your project files into the new app directory, ensuring that you do not replace the `encore.app` file (this file holds a unique id which links your app to the platform).

### Commit changes

Encore comes with built-in CI/CD, and the deployment process is as simple as a `git push`.
(You can also integrate with GitHub to activate per Pull Request Preview Environments, learn more in the [CI/CD docs](/docs/platform/deploy/deploying).)
Expand All @@ -621,6 +678,7 @@ From the Cloud Dashboard you can also see metrics, trigger Cron Jobs, see traces

*You now have an Uptime Monitor running in the cloud, well done!*

</Accordion>

## 6. Publish Pub/Sub events when a site goes down

Expand Down Expand Up @@ -839,6 +897,24 @@ var _ = pubsub.NewSubscription(monitor.TransitionTopic, "slack-notification", pu

Now you're ready to deploy your finished Uptime Monitor, complete with a Slack integration.

<Accordion>

### Self-hosting

Because we have added more infrastructure to our app, we need to [update the configuration](/docs/go/self-host/configure-infra) in our `infra-config.json` to include the new Pub/Sub topic and subscription as well as how we should set the `SlackWebhookURL` secret.

🥐 Update your `ìnfra-config.json` to reflect the new infrastructure.

🥐 Build a Docker image by running `encore build docker uptime:v2.0`.

🥐 Upload the Docker image to the cloud provider and run it.

</Accordion>

<Accordion>

### Encore Cloud (free)

🥐 As before, deploying your app to the cloud is as simple as running:

```shell
Expand All @@ -859,6 +935,8 @@ _From here you can easily access all Cloud Dashboard features and for example ju

![Fireworks](/assets/docs/fireworks.jpg)

</Accordion>

## Conclusion

We've now built a fully functioning uptime monitoring system.
Expand Down
Loading