From 55c1261c4722e9c108e2fae387329b9eafeeb408 Mon Sep 17 00:00:00 2001 From: commit111 Date: Mon, 25 Nov 2024 14:04:58 -0800 Subject: [PATCH 1/5] changes to readmes --- samples/hasura/README.md | 70 ++++++++++++++++++++++++++++++--------- samples/huginn/README.md | 71 ++++++++++++++++++++++++++++++++++------ 2 files changed, 115 insertions(+), 26 deletions(-) diff --git a/samples/hasura/README.md b/samples/hasura/README.md index e161cd2e..80e8ce94 100644 --- a/samples/hasura/README.md +++ b/samples/hasura/README.md @@ -2,34 +2,72 @@ [![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) -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. +This sample project demonstrates how to deploy Hasura with Defang and connect it to a Postgres database. + +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. ## Prerequisites 1. Download [Defang CLI](https://github.com/DefangLabs/defang) -2. Have a managed database service configured and have the connection string ready. -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 -4. (Optional - for local development) [Docker CLI](https://docs.docker.com/engine/install/) -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. +2. Have a managed database service configured and ready, such as [Neon PostgreSQL](https://neon.tech/) +3. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account +4. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/) +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 ## Development -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. + To run the application locally, you can use the following command: + +```bash +docker compose -f ./compose.yaml -f ./compose.dev.yaml up --build +``` +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`. + +> Note: If you want to make changes to your database, permissions, etc. see [Editing Hasura Settings](#editing-hasura-settings) for more information. + +### Editing Hasura Settings + +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. + +## Configuration + +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. + +### `HASURA_GRAPHQL_DATABASE_URL` +A connection string of the format `postgres://username:password@host:port/dbname`. +```bash +defang config set HASURA_GRAPHQL_DATABASE_URL +``` + +### `HASURA_GRAPHQL_ADMIN_SECRET` +A password you would like to log into Hasura with. +```bash +defang config set HASURA_GRAPHQL_ADMIN_SECRET +``` + +## Deployment + +> [!NOTE] +> Download [Defang CLI](https://github.com/DefangLabs/defang) -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`. -**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._ +### Defang Playground -### Editing the database/permissions etc. +Deploy your application to the Defang Playground by opening up your terminal and typing: +```bash +defang compose up +``` -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. +### BYOC (AWS) -## Deploying +If you want to deploy to your own cloud account, you can use Defang BYOC: -1. Open the terminal and type `defang login` -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`) -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. -4. Type `defang compose up` in the CLI. -5. Your app will be running within a few minutes. +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`. +2. Run in a terminal that has access to your AWS environment variables: + ```bash + defang --provider=aws compose up + ``` --- diff --git a/samples/huginn/README.md b/samples/huginn/README.md index 803c2396..fa1aa1bf 100644 --- a/samples/huginn/README.md +++ b/samples/huginn/README.md @@ -2,26 +2,77 @@ [![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-huginn-template%26template_owner%3DDefangSamples) +This sample shows how to deploy Huginn with Defang. + Huginn is a system for building agents that perform automated tasks for you online. Huginn's Agents can monitor the web, respond to events, and act on your behalf. They propagate events along a directed graph. It's like a customizable IFTTT or Zapier on your own server, ensuring data privacy. ## Prerequisites 1. Download [Defang CLI](https://github.com/DefangLabs/defang) -2. Have a managed database service configured and have the connection details ready. Neon postgres is a good free option. -3. (optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc), make sure you have properly [authenticated your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html). +2. Have a managed database service configured and ready, such as [Neon PostgreSQL](https://neon.tech/) +3. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account +4. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/) + +## Development + +To run the application locally, you can use the following command: + +```bash +`docker compose -f ./compose.yaml -f ./compose.dev.yaml up +``` +This will start the Postgres container and the Huginn container. Huginn will be available at `http://localhost:3000` with the username `admin` and password `password`. + +## Configuration + +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. + +### `DATABASE_NAME` +The name of the database. +```bash +defang config set DATABASE_NAME +``` + +### `DATABASE_USERNAME` +The username used with the database. +```bash +defang config set DATABASE_USERNAME +``` + +### `DATABASE_PASSWORD` +The password used with the database. +```bash +defang config set DATABASE_PASSWORD +``` + +### `DATABASE_HOST` +The host of the database. +```bash +defang config set DATABASE_HOST +``` + +## Deployment + +> [!NOTE] +> Download [Defang CLI](https://github.com/DefangLabs/defang) -## Local +### Defang Playground -For development, we use a Postgres container. The Postgres container is defined in the `compose.dev.yaml` file. The Huginn container is defined in the `compose.yaml` file, with some overrides in the `compose.dev.yaml` file so it can correctly connect to the local database container. +Deploy your application to the Defang Playground by opening up your terminal and typing: +```bash +defang compose up +``` -To start the local environment, run `docker compose -f ./compose.yaml -f ./compose.dev.yaml up`. This will start the Postgres container and the Huginn container. Huginn will be available at `http://localhost:3000` with the username `admin` and password `password`. +### BYOC (AWS) -## Deploying +If you want to deploy to your own cloud account, you can use Defang BYOC: -1. Open the terminal and type `defang login` -2. Add your database connection details using `defang config` by typing `defang config set ` where `` is the each of the following `DATABASE_NAME`, `DATABASE_USERNAME`, `DATABASE_PASSWORD`, `DATABASE_HOST`. For example `defang config set DATABASE_NAME` and pasting your database name. -3. Type `defang compose up` in the CLI. -4. Your app will be running within a few minutes. +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`. +2. Run in a terminal that has access to your AWS environment variables: + ```bash + defang --provider=aws compose up + ``` --- From 172ef38d113f985ee8b969ddf7d5fa185078a886 Mon Sep 17 00:00:00 2001 From: commit111 Date: Mon, 25 Nov 2024 14:41:08 -0800 Subject: [PATCH 2/5] huginn update --- samples/huginn/README.md | 2 +- samples/huginn/compose.yaml | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/samples/huginn/README.md b/samples/huginn/README.md index fa1aa1bf..17ee8340 100644 --- a/samples/huginn/README.md +++ b/samples/huginn/README.md @@ -18,7 +18,7 @@ Huginn is a system for building agents that perform automated tasks for you onli To run the application locally, you can use the following command: ```bash -`docker compose -f ./compose.yaml -f ./compose.dev.yaml up +docker compose -f ./compose.yaml -f ./compose.dev.yaml up ``` This will start the Postgres container and the Huginn container. Huginn will be available at `http://localhost:3000` with the username `admin` and password `password`. diff --git a/samples/huginn/compose.yaml b/samples/huginn/compose.yaml index f9287476..5985c712 100644 --- a/samples/huginn/compose.yaml +++ b/samples/huginn/compose.yaml @@ -18,7 +18,15 @@ services: retries: 10 environment: - DATABASE_ADAPTER=postgresql - - DATABASE_NAME - - DATABASE_USERNAME + - DATABASE_NAME=huginn + - DATABASE_USERNAME=huginn - DATABASE_PASSWORD - - DATABASE_HOST + - DATABASE_HOST=postgres + depends_on: + - postgres + postgres: + image: postgres:16 + environment: + - POSTGRES_USER=huginn + - POSTGRES_PASSWORD + - POSTGRES_DB=huginn \ No newline at end of file From ef94ba7296837372d9abccb4832e364f464e1fe7 Mon Sep 17 00:00:00 2001 From: commit111 Date: Mon, 25 Nov 2024 16:00:11 -0800 Subject: [PATCH 3/5] update change --- samples/hasura/README.md | 2 +- samples/hasura/compose.yaml | 8 ++++---- samples/huginn/compose.yaml | 10 +--------- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/samples/hasura/README.md b/samples/hasura/README.md index 80e8ce94..52d49415 100644 --- a/samples/hasura/README.md +++ b/samples/hasura/README.md @@ -23,7 +23,7 @@ docker compose -f ./compose.yaml -f ./compose.dev.yaml up --build ``` 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`. -> Note: If you want to make changes to your database, permissions, etc. see [Editing Hasura Settings](#editing-hasura-settings) for more information. +> Note: If you want to make changes to your database, permissions, etc. see [Editing Hasura Settings](#editing-hasura-settings). ### Editing Hasura Settings diff --git a/samples/hasura/compose.yaml b/samples/hasura/compose.yaml index e7e7329a..2517fab5 100644 --- a/samples/hasura/compose.yaml +++ b/samples/hasura/compose.yaml @@ -19,7 +19,7 @@ services: - HASURA_GRAPHQL_DEFAULT_NAMING_CONVENTION=graphql-default - HASURA_GRAPHQL_MIGRATIONS_DIR=/hasura/migrations - HASURA_GRAPHQL_METADATA_DIR=/hasura/metadata - #deploy: - # resources: - # reservations: - # memory: 256M + deploy: + resources: + reservations: + memory: 256M \ No newline at end of file diff --git a/samples/huginn/compose.yaml b/samples/huginn/compose.yaml index 5985c712..bc2966fd 100644 --- a/samples/huginn/compose.yaml +++ b/samples/huginn/compose.yaml @@ -10,7 +10,7 @@ services: resources: reservations: cpus: '1.0' - memory: '2G' + memory: 1G healthcheck: test: ["CMD", "curl", "-f", "http://localhost:3000/"] interval: 1m30s @@ -22,11 +22,3 @@ services: - DATABASE_USERNAME=huginn - DATABASE_PASSWORD - DATABASE_HOST=postgres - depends_on: - - postgres - postgres: - image: postgres:16 - environment: - - POSTGRES_USER=huginn - - POSTGRES_PASSWORD - - POSTGRES_DB=huginn \ No newline at end of file From 5c5420a45fe6e5515a9707f7137709acd4e914ee Mon Sep 17 00:00:00 2001 From: commit111 Date: Tue, 26 Nov 2024 09:28:40 -0800 Subject: [PATCH 4/5] edits to samples --- samples/hasura/compose.yaml | 14 ++++++++++++-- samples/huginn/compose.yaml | 8 +++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/samples/hasura/compose.yaml b/samples/hasura/compose.yaml index 2517fab5..fb8876e9 100644 --- a/samples/hasura/compose.yaml +++ b/samples/hasura/compose.yaml @@ -11,7 +11,7 @@ services: published: 8080 mode: ingress environment: - - HASURA_GRAPHQL_DATABASE_URL + - HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:${POSTGRES_PASSWORD}@db:5432/postgres - HASURA_GRAPHQL_ADMIN_SECRET - HASURA_GRAPHQL_ENABLE_CONSOLE=true - HASURA_GRAPHQL_UNAUTHORIZED_ROLE=public @@ -22,4 +22,14 @@ services: deploy: resources: reservations: - memory: 256M \ No newline at end of file + memory: 256M + db: + image: postgres:14 + restart: unless-stopped + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD + - POSTGRES_DB=postgres + ports: + - mode: host + target: 5432 \ No newline at end of file diff --git a/samples/huginn/compose.yaml b/samples/huginn/compose.yaml index bc2966fd..4d244bb0 100644 --- a/samples/huginn/compose.yaml +++ b/samples/huginn/compose.yaml @@ -1,5 +1,5 @@ services: - huginn: + huginn-app: image: ghcr.io/huginn/huginn restart: unless-stopped ports: @@ -22,3 +22,9 @@ services: - DATABASE_USERNAME=huginn - DATABASE_PASSWORD - DATABASE_HOST=postgres + postgres: + image: postgres:16 + environment: + - POSTGRES_USER=huginn + - POSTGRES_PASSWORD + - POSTGRES_DB=huginn From 15605bee1a8da5d6a846df17ff4d2297bb4d6181 Mon Sep 17 00:00:00 2001 From: commit111 Date: Tue, 26 Nov 2024 11:47:39 -0800 Subject: [PATCH 5/5] updated again --- samples/hasura/compose.dev.yaml | 2 +- samples/huginn/compose.yaml | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/samples/hasura/compose.dev.yaml b/samples/hasura/compose.dev.yaml index c5dba8a8..c64ca0d5 100644 --- a/samples/hasura/compose.dev.yaml +++ b/samples/hasura/compose.dev.yaml @@ -1,6 +1,6 @@ services: postgres: - image: postgres:16 + image: postgres:14 environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres diff --git a/samples/huginn/compose.yaml b/samples/huginn/compose.yaml index 4d244bb0..1b9f35bb 100644 --- a/samples/huginn/compose.yaml +++ b/samples/huginn/compose.yaml @@ -20,11 +20,17 @@ services: - DATABASE_ADAPTER=postgresql - DATABASE_NAME=huginn - DATABASE_USERNAME=huginn - - DATABASE_PASSWORD - - DATABASE_HOST=postgres - postgres: - image: postgres:16 + - DATABASE_PASSWORD=${POSTGRES_PASSWORD} + - DATABASE_HOST=postgresx + postgresx: + image: postgres:14 environment: - POSTGRES_USER=huginn - POSTGRES_PASSWORD - POSTGRES_DB=huginn + ports: + - mode: host + target: 5432 + published: 5432 + networks: + - public