Skip to content

Commit eb75158

Browse files
committed
Merge branch 'main' into hasura-with-config-interpolation
0 parents  commit eb75158

File tree

42 files changed

+429
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+429
-0
lines changed

.devcontainer/Dockerfile

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

.devcontainer/devcontainer.json

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+
}

.github/workflows/deploy.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
id-token: write
14+
15+
steps:
16+
- name: Checkout Repo
17+
uses: actions/checkout@v4
18+
19+
- name: Deploy
20+
uses: DefangLabs/[email protected]

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Hasura & Postgres
2+
3+
[![1-click-deploy](https://defang.io/deploy-with-defang.png)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-hasura-template%26template_owner%3DDefangSamples)
4+
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.
6+
7+
## Prerequisites
8+
9+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
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.
13+
14+
## Development
15+
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+
19+
### Editing the database/permissions etc.
20+
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.
22+
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.
54+
55+
56+
---
57+
58+
Title: Hasura & PostgreSQL
59+
60+
Short Description: A sample project demonstrating how to deploy Hasura with Defang and connect it to a PostgreSQL database.
61+
62+
Tags: Hasura, GraphQL, PostgreSQL, Database
63+
64+
Languages: SQL, GraphQL

compose.dev.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
services:
2+
hasura:
3+
extends:
4+
file: compose.yaml
5+
service: hasura
6+
environment:
7+
- HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:password@database:5432/postgres
8+
- HASURA_GRAPHQL_ADMIN_SECRET=password
9+
volumes:
10+
- ./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
19+
20+
volumes:
21+
database_data:

compose.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
services:
2+
hasura:
3+
restart: unless-stopped
4+
build:
5+
dockerfile: Dockerfile
6+
context: ./hasura
7+
# If you want to add your own domain name in Defang BYOC, uncomment the following line and replace the domain name with your own
8+
# domainname: hasura.mycoolapp.com
9+
ports:
10+
- target: 8080
11+
published: 8080
12+
mode: ingress
13+
environment:
14+
- HASURA_GRAPHQL_ADMIN_SECRET
15+
- HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:${POSTGRES_PASSWORD}@database:5432/postgres
16+
- HASURA_GRAPHQL_ENABLE_CONSOLE=true
17+
- HASURA_GRAPHQL_UNAUTHORIZED_ROLE=public
18+
- HASURA_GRAPHQL_EXPERIMENTAL_FEATURES=naming_convention
19+
- HASURA_GRAPHQL_DEFAULT_NAMING_CONVENTION=graphql-default
20+
- HASURA_GRAPHQL_MIGRATIONS_DIR=/hasura/migrations
21+
- HASURA_GRAPHQL_METADATA_DIR=/hasura/metadata
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

hasura/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM hasura/graphql-engine:v2.39.0.cli-migrations-v3.ubuntu
2+
3+
COPY . /hasura

hasura/config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 3
2+
endpoint: http://localhost:8080
3+
metadata_directory: metadata
4+
admin_secret: password
5+
actions:
6+
kind: synchronous
7+
handler_webhook_baseurl: http://localhost:3000

hasura/metadata/actions.graphql

Whitespace-only changes.

hasura/metadata/actions.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
actions: []
2+
custom_types:
3+
enums: []
4+
input_objects: []
5+
objects: []
6+
scalars: []

0 commit comments

Comments
 (0)