Skip to content

Commit 154e21f

Browse files
authored
Merge pull request #327 from DefangLabs/linda-nextjs-cv
Add Nextjs CV (from market.dev) sample
0 parents  commit 154e21f

File tree

40 files changed

+385
-0
lines changed

40 files changed

+385
-0
lines changed

.github/workflows/deploy.yaml

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

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Hasura & PostgreSQL
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. 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.
14+
15+
## Development
16+
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`.
20+
**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._
21+
22+
### Editing the database/permissions etc.
23+
24+
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.
25+
26+
## Deploying
27+
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.
33+
34+
---
35+
36+
Title: Hasura & PostgreSQL
37+
38+
Short Description: A sample project demonstrating how to deploy Hasura with Defang and connect it to a PostgreSQL database.
39+
40+
Tags: Hasura, GraphQL, PostgreSQL, Database
41+
42+
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+
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
10+
hasura:
11+
depends_on:
12+
- postgres
13+
restart: on-failure
14+
environment:
15+
- HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres
16+
- HASURA_GRAPHQL_ADMIN_SECRET=password
17+
volumes:
18+
- ./hasura:/hasura
19+
20+
volumes:
21+
postgres_data:

compose.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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_DATABASE_URL
15+
- HASURA_GRAPHQL_ADMIN_SECRET
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+
#deploy:
23+
# resources:
24+
# reservations:
25+
# memory: 256M

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: []

hasura/metadata/allow_list.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

hasura/metadata/api_limits.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

0 commit comments

Comments
 (0)