Skip to content

Commit 441e07b

Browse files
Oxyjunhyperlint-ai[bot]thomasgauvin
authored
[Hyperdrive] Adding example for connecting Hyperdrive to Fly.io (cloudflare#20744)
* Adding example for connecting Hyperdrive to Fly.io * Update src/content/docs/hyperdrive/examples/fly.mdx Co-authored-by: hyperlint-ai[bot] <154288675+hyperlint-ai[bot]@users.noreply.github.com> * Update src/content/docs/hyperdrive/examples/fly.mdx * Update src/content/docs/hyperdrive/examples/fly.mdx * Update src/content/docs/hyperdrive/examples/fly.mdx --------- Co-authored-by: hyperlint-ai[bot] <154288675+hyperlint-ai[bot]@users.noreply.github.com> Co-authored-by: Thomas Gauvin <[email protected]>
1 parent 61d9e24 commit 441e07b

File tree

2 files changed

+67
-7
lines changed

2 files changed

+67
-7
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
type: example
3+
summary: Connect Hyperdrive to a Fly database instance.
4+
pcx_content_type: example
5+
title: Connect to Fly
6+
sidebar:
7+
order: 1
8+
description: Connect Hyperdrive to a Fly database instance.
9+
---
10+
11+
import { Render, Steps } from "~/components";
12+
13+
This example shows you how to connect Hyperdrive to a Fly PostgreSQL database instance.
14+
15+
## 1. Allow Hyperdrive access
16+
17+
You can connect Hyperdrive to any existing Fly database by:
18+
19+
1. Allocating a public IP address to your Fly database instance
20+
2. Configuring an external service
21+
3. Deploying the configuration
22+
4. Obtain the connection string, which is used to connect the database to Hyperdrive.
23+
24+
<Steps>
25+
1. Run the following command to [allocate a public IP address](https://fly.io/docs/postgres/connecting/connecting-external/#allocate-an-ip-address).
26+
27+
```txt
28+
fly ips allocate-v6 --app <pg-app-name>
29+
```
30+
31+
:::note
32+
Cloudflare recommends using IPv6, but some Internet service providers may not support IPv6. In this case, [you can allocate an IPv4 address](https://fly.io/docs/postgres/connecting/connecting-with-flyctl/).
33+
:::
34+
35+
2. [Configure an external service](https://fly.io/docs/postgres/connecting/connecting-external/#configure-an-external-service) by modifying the contents of your `fly.toml` file. Run the following command to download the `fly.toml` file.
36+
37+
```txt
38+
fly config save --app <pg-app-name>
39+
```
40+
41+
Then, replace the `services` and `services.ports` section of the file with the following `toml` snippet:
42+
43+
```toml
44+
[[services]]
45+
internal_port = 5432 # Postgres instance
46+
protocol = "tcp"
47+
48+
[[services.ports]]
49+
handlers = ["pg_tls"]
50+
port = 5432
51+
```
52+
53+
3. [Deploy the new configuration](https://fly.io/docs/postgres/connecting/connecting-external/#deploy-with-the-new-configuration).
54+
4. [Obtain the connection string](https://fly.io/docs/postgres/connecting/connecting-external/#adapting-the-connection-string), which is in the form of:
55+
56+
```txt
57+
postgres://{username}:{password}@{public-hostname}:{port}/{database}?options
58+
```
59+
</Steps>
60+
61+
## 2. Create a database configuration
62+
63+
<Render file="create-hyperdrive-config" />

src/content/docs/hyperdrive/index.mdx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,27 +161,24 @@ Deploy dynamic front-end applications in record time.
161161
href="/workers/platform/storage-options/"
162162
icon="document"
163163
>
164-
Learn more about the storage and database options you can build on with
165-
Workers.
164+
Learn more about the storage and database options you can build on with Workers.
166165
</LinkTitleCard>
167166

168167
<LinkTitleCard
169168
title="Developer Discord"
170169
href="https://discord.cloudflare.com"
171170
icon="discord"
172171
>
173-
Connect with the Workers community on Discord to ask questions, show what you
174-
are building, and discuss the platform with other developers.
172+
Connect with the Workers community on Discord to ask questions, show what you are building, and discuss the platform with other developers.
175173
</LinkTitleCard>
176174

177175
<LinkTitleCard
178176
title="@CloudflareDev"
179177
href="https://x.com/cloudflaredev"
180178
icon="x.com"
181179
>
182-
Follow @CloudflareDev on Twitter to learn about product announcements, and
183-
what is new in Cloudflare Developer Platform.
180+
Follow @CloudflareDev on Twitter to learn about product announcements, and what is new in Cloudflare Developer Platform.
184181
</LinkTitleCard>
185182

186183
</CardGrid>
187-
````
184+

0 commit comments

Comments
 (0)