You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This sample project demonstrates how to deploy Hasura with Defang and connect it to a Postgres database. We also demonstrate how to run a Postgres container during development and how to switch over to a managed postgres service like RDS, Neon, or others in production. If you want to get a compatible database ready to go really quickly for free, [Neon](https://neon.tech/) is a quick and easy way to go. The sample populates the database with some sample data so you can quickly start playing with the Hasura console. It sets wide open permissions on the tables as well so you can start querying or mutating the data right away.
5
+
This sample project demonstrates how to deploy Hasura with Defang and connect it to a Postgres database.
6
+
7
+
The sample populates the database with some sample data so you can quickly start playing with the Hasura console. It sets wide open permissions on the tables as well so you can start querying or mutating the data right away.
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
11
13
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
12
-
4. (Optional) [Install the Hasura CLI](https://hasura.io/docs/latest/hasura-cli/install-hasura-cli/) to create migrations and update metadata for your Hasura GraphQL api.
14
+
Comment view5. (Optional) Install the [Hasura CLI](https://hasura.io/docs/latest/hasura-cli/install-hasura-cli/) to create migrations and update metadata for your Hasura GraphQL API
13
15
14
16
## Development
15
17
16
-
To start the development environment, run `docker -f ./compose.dev.yaml up`. This will start the Postgres container and the Hasura container. The Hasura console will be available at `http://localhost:8080` with the password `password`.
17
-
**Note:**_If you want to make changes to your database, permissions, etc. you should use the Hasura console and the Hasura CLI to make those changes. See the next section for more information._
18
+
To run the application locally, you can use the following command:
19
+
20
+
```bash
21
+
docker compose -f ./compose.yaml -f ./compose.dev.yaml up --build
22
+
```
23
+
This will start the Postgres container (from `compose.dev.yaml`) and the Hasura container (from `compose.yaml` with some overrides). The Hasura console will be available at `http://localhost:8080` with the password `password`.
18
24
19
-
### Editing the database/permissions etc.
25
+
> Note: If you want to make changes to your database, permissions, etc. see [Editing Hasura Settings](#editing-hasura-settings).
20
26
21
-
If you want to edit the database, permissions, or any other Hasura settings such that you can deploy them to production, you should [install the Hasura CLI](https://hasura.io/docs/latest/hasura-cli/install-hasura-cli/). Then, after starting the development environment, you can run `hasura console`_inside the `./hasura` directory_. This will open the Hasura console in your browser. Any changes you make in the console will be saved to the `migrations` and `metadata` directories. When you run `defang compose up` these changes will be applied to the production environment.
27
+
### Editing Hasura Settings
22
28
23
-
**NOTE**: If you are using the [Dev Container](https://containers.dev/) defined in [.devcontainer/devcontainer.json](.devcontainer/devcontainer.json), the Hasura CLI will already be installed.
29
+
To edit the database, permissions, or any other Hasura settings such that you can deploy them to production, you should install the [ Hasura CLI](https://hasura.io/docs/latest/hasura-cli/install-hasura-cli/). Then, after starting the development environment, you can run `hasura console`_inside the `./hasura` directory_. This will open the Hasura console in your browser. Any changes you make in the console will be saved to the `migrations` and `metadata` directories. When you run `defang compose up`, these changes will be applied to the production environment.
24
30
25
31
## Configuration
26
32
27
-
For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration). Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
33
+
For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration):
28
34
29
-
### `HASURA_GRAPHQL_ADMIN_SECRET`
30
-
This password will be used to allow you to access the hasura console.
35
+
> Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
31
36
37
+
### `POSTGRES_PASSWORD`
38
+
A password for your database.
39
+
```bash
40
+
defang config set POSTGRES_PASSWORD
41
+
```
32
42
33
-
### `POSTGRES_PASSWORD`
34
-
This password will be used to initialize the PostgreSQL database and to connect to it. You could use a command like `openssl rand -base64 16` to generate a random password.
43
+
### `SSL_MODE`
44
+
Either `disable` if you're using the Defang Playground or `require` if you're using BYOC.
45
+
```bash
46
+
defang config set SSL_MODE
47
+
```
35
48
49
+
### `HASURA_GRAPHQL_ADMIN_SECRET`
50
+
A password you would like to log into Hasura with.
51
+
```bash
52
+
defang config set HASURA_GRAPHQL_ADMIN_SECRET
53
+
```
36
54
37
55
## Deployment
38
56
@@ -41,17 +59,20 @@ This password will be used to initialize the PostgreSQL database and to connect
41
59
42
60
### Defang Playground
43
61
44
-
Deploy your application to the defang playground by opening up your terminal and typing `defang up`.
45
-
46
-
**Keep in mind that the playground does not support [managed Postgres](https://docs.defang.io/docs/concepts/managed-storage/managed-postgres).**
62
+
Deploy your application to the Defang Playground by opening up your terminal and typing:
63
+
```bash
64
+
defang compose up
65
+
```
47
66
48
67
### BYOC (AWS)
49
68
50
69
If you want to deploy to your own cloud account, you can use Defang BYOC:
51
70
52
71
1.[Authenticate your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), and check that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`.
53
-
2. Run `defang --provider=aws up` in a terminal that has access to your AWS environment variables.
54
-
72
+
2. Run in a terminal that has access to your AWS environment variables:
0 commit comments