Skip to content

Commit e1b4ba5

Browse files
authored
Merge pull request #274 from DefangLabs/linda-hasura
Hasura changes
2 parents 08ebf95 + 81dbf48 commit e1b4ba5

3 files changed

Lines changed: 70 additions & 20 deletions

File tree

samples/hasura/README.md

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,55 @@
22

33
[![1-click-deploy](https://raw.githubusercontent.com/DefangLabs/defang-assets/main/Logos/Buttons/SVG/deploy-with-defang.svg)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-hasura-template%26template_owner%3DDefangSamples)
44

5-
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.
68

79
## Prerequisites
810

911
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
1012
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
1113
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
1315

1416
## Development
1517

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`.
1824

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).
2026
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
2228

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.
2430

2531
## Configuration
2632

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):
2834

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.
3136
37+
### `POSTGRES_PASSWORD`
38+
A password for your database.
39+
```bash
40+
defang config set POSTGRES_PASSWORD
41+
```
3242

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+
```
3548

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+
```
3654

3755
## Deployment
3856

@@ -41,17 +59,20 @@ This password will be used to initialize the PostgreSQL database and to connect
4159
4260
### Defang Playground
4361

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+
```
4766

4867
### BYOC (AWS)
4968

5069
If you want to deploy to your own cloud account, you can use Defang BYOC:
5170

5271
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:
73+
```bash
74+
defang --provider=aws compose up
75+
```
5576

5677
---
5778

samples/hasura/compose.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ services:
99
- target: 8080
1010
published: 8080
1111
mode: ingress
12+
depends_on:
13+
database:
14+
condition: service_started
1215
environment:
1316
- HASURA_GRAPHQL_ADMIN_SECRET
14-
- HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:${POSTGRES_PASSWORD}@database:5432/postgres
17+
- HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:${POSTGRES_PASSWORD}@database:5432/postgres?sslmode=${SSL_MODE}
1518
- HASURA_GRAPHQL_ENABLE_CONSOLE=true
1619
- HASURA_GRAPHQL_UNAUTHORIZED_ROLE=public
1720
- HASURA_GRAPHQL_EXPERIMENTAL_FEATURES=naming_convention
1821
- HASURA_GRAPHQL_DEFAULT_NAMING_CONVENTION=graphql-default
1922
- HASURA_GRAPHQL_MIGRATIONS_DIR=/hasura/migrations
2023
- HASURA_GRAPHQL_METADATA_DIR=/hasura/metadata
24+
- SSL_MODE
2125
- POSTGRES_PASSWORD
2226
deploy:
2327
resources:
@@ -31,8 +35,6 @@ services:
3135
- target: 5432
3236
mode: host
3337
environment:
34-
- POSTGRES_USER=postgres
35-
- POSTGRES_DB=postgres
3638
- POSTGRES_PASSWORD
3739
deploy:
3840
resources:
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Default .dockerignore file for Defang
2+
**/__pycache__
3+
**/.direnv
4+
**/.DS_Store
5+
**/.envrc
6+
**/.git
7+
**/.github
8+
**/.idea
9+
**/.next
10+
**/.vscode
11+
**/compose.*.yaml
12+
**/compose.*.yml
13+
**/compose.yaml
14+
**/compose.yml
15+
**/docker-compose.*.yaml
16+
**/docker-compose.*.yml
17+
**/docker-compose.yaml
18+
**/docker-compose.yml
19+
**/node_modules
20+
**/Thumbs.db
21+
Dockerfile
22+
*.Dockerfile
23+
# Ignore our own binary, but only in the root to avoid ignoring subfolders
24+
defang
25+
defang.exe
26+
# Ignore our project-level state
27+
.defang

0 commit comments

Comments
 (0)