Skip to content

Commit e09fa2a

Browse files
committed
hasura with config interpolation
1 parent e67caa9 commit e09fa2a

File tree

9 files changed

+85
-38
lines changed

9 files changed

+85
-38
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM mcr.microsoft.com/devcontainers/typescript-node:22-bookworm
2+
3+
# Install hasura cli
4+
RUN curl -L https://github.com/hasura/graphql-engine/raw/stable/cli/get.sh | bash
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"build": {
3+
"dockerfile": "Dockerfile",
4+
"context": ".."
5+
},
6+
"features": {
7+
"ghcr.io/defanglabs/devcontainer-feature/defang-cli:1.0.4": {},
8+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
9+
"ghcr.io/devcontainers/features/aws-cli:1": {}
10+
}
11+
}

samples/hasura/README.md

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,51 @@ This sample project demonstrates how to deploy Hasura with Defang and connect it
77
## Prerequisites
88

99
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
10-
2. Have a managed database service configured and have the connection string ready.
11-
3. (Optional) If you are using [Defang BYOC](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) authenticated with your AWS account
12-
4. (Optional - for local development) [Docker CLI](https://docs.docker.com/engine/install/)
13-
5. (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.
10+
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
11+
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.
1413

1514
## Development
1615

17-
For development, we use a Postgres container. The Postgres container is defined in the `compose.dev.yaml` file. The Hasura container is defined in the `compose.yaml` file, with some overrides in the `compose.dev.yaml` file so it can correctly connect to the development database container.
18-
19-
To start the development environment, run `docker compose -f ./compose.yaml -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`.
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`.
2017
**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._
2118

2219
### Editing the database/permissions etc.
2320

2421
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.
2522

26-
## Deploying
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.
24+
25+
## Configuration
26+
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.
28+
29+
### `HASURA_GRAPHQL_ADMIN_SECRET`
30+
This password will be used to allow you to access the hasura console.
31+
32+
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.
35+
36+
37+
## Deployment
38+
39+
> [!NOTE]
40+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
41+
42+
### Defang Playground
43+
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).**
47+
48+
### BYOC (AWS)
49+
50+
If you want to deploy to your own cloud account, you can use Defang BYOC:
51+
52+
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.
2754

28-
1. Open the terminal and type `defang login`
29-
2. Add your connection string as a defang config value by typing `defang config set HASURA_GRAPHQL_DATABASE_URL` and pasting your connection string (which should be in the format `postgres://username:password@host:port/dbname`)
30-
3. Setup a password for hasura by typing `defang config set HASURA_GRAPHQL_ADMIN_SECRET` and adding a password you would like to login with.
31-
4. Type `defang compose up` in the CLI.
32-
5. Your app will be running within a few minutes.
3355

3456
---
3557

samples/hasura/compose.dev.yaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
services:
2-
postgres:
3-
image: postgres:16
4-
environment:
5-
- POSTGRES_USER=postgres
6-
- POSTGRES_PASSWORD=postgres
7-
- POSTGRES_DB=postgres
8-
volumes:
9-
- postgres_data:/var/lib/postgresql/data
102
hasura:
11-
depends_on:
12-
- postgres
13-
restart: on-failure
3+
extends:
4+
file: compose.yaml
5+
service: hasura
146
environment:
15-
- HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres
7+
- HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:password@database:5432/postgres
168
- HASURA_GRAPHQL_ADMIN_SECRET=password
179
volumes:
1810
- ./hasura:/hasura
11+
database:
12+
extends:
13+
file: compose.yaml
14+
service: database
15+
environment:
16+
- POSTGRES_PASSWORD=password
17+
volumes:
18+
- database_data:/var/lib/postgresql/data
1919

2020
volumes:
21-
postgres_data:
21+
database_data:

samples/hasura/compose.yaml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,23 @@ services:
1111
published: 8080
1212
mode: ingress
1313
environment:
14-
- HASURA_GRAPHQL_DATABASE_URL
1514
- HASURA_GRAPHQL_ADMIN_SECRET
15+
- HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:${POSTGRES_PASSWORD}@database:5432/postgres
1616
- HASURA_GRAPHQL_ENABLE_CONSOLE=true
1717
- HASURA_GRAPHQL_UNAUTHORIZED_ROLE=public
1818
- HASURA_GRAPHQL_EXPERIMENTAL_FEATURES=naming_convention
1919
- HASURA_GRAPHQL_DEFAULT_NAMING_CONVENTION=graphql-default
2020
- HASURA_GRAPHQL_MIGRATIONS_DIR=/hasura/migrations
2121
- HASURA_GRAPHQL_METADATA_DIR=/hasura/metadata
22-
#deploy:
23-
# resources:
24-
# reservations:
25-
# memory: 256M
22+
- POSTGRES_PASSWORD
23+
24+
database:
25+
image: postgres:16
26+
x-defang-postgres: true
27+
ports:
28+
- target: 5432
29+
mode: host
30+
environment:
31+
- POSTGRES_USER=postgres
32+
- POSTGRES_DB=postgres
33+
- POSTGRES_PASSWORD

samples/rails/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ Deploy your application to the defang playground by opening up your terminal and
3838

3939
If you want to deploy to your own cloud account, you can use Defang BYOC:
4040

41-
1. [Authenticate your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), and that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`.
41+
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`.
42+
2. Run `defang --provider=aws up` in a terminal that has access to your AWS environment variables.
4243

4344
---
4445

samples/rocket/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ Deploy your application to the defang playground by opening up your terminal and
3131

3232
If you want to deploy to your own cloud account, you can use Defang BYOC:
3333

34-
1. [Authenticate your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), and that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`.
35-
2. Run `defang up` in a terminal that has access to your AWS environment variables.
34+
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`.
35+
2. Run `defang --provider=aws up` in a terminal that has access to your AWS environment variables.
3636

3737
---
3838

starter-sample/.devcontainer/devcontainer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
},
66
"features": {
77
"ghcr.io/defanglabs/devcontainer-feature/defang-cli:1.0.4": {},
8-
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
8+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
9+
"ghcr.io/devcontainers/features/aws-cli:1": {}
910
}
1011
}

starter-sample/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This is a sample that shows the rough structure of an actual Defang sample. This
77
## Prerequisites
88

99
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
10-
2. (Optional) If you are using [Defang BYOC](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) authenticated with your AWS account
10+
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
1111
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
1212

1313
## Development
@@ -40,8 +40,8 @@ Deploy your application to the defang playground by opening up your terminal and
4040

4141
If you want to deploy to your own cloud account, you can use Defang BYOC:
4242

43-
1. [Authenticate your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), and that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`.
44-
2. Run `defang up` in a terminal that has access to your AWS environment variables.
43+
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`.
44+
2. Run `defang --provider=aws up` in a terminal that has access to your AWS environment variables.
4545

4646
---
4747

0 commit comments

Comments
 (0)