From f52f968b7f4ead5976964275d19c7e0d900794b6 Mon Sep 17 00:00:00 2001 From: commit111 Date: Tue, 26 Nov 2024 12:47:33 -0800 Subject: [PATCH 1/3] huginn changes only --- samples/huginn/README.md | 71 +++++++++++++++++++++++++++++++------ samples/huginn/compose.yaml | 24 +++++++++---- 2 files changed, 79 insertions(+), 16 deletions(-) diff --git a/samples/huginn/README.md b/samples/huginn/README.md index 803c2396..17ee8340 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 + ``` --- diff --git a/samples/huginn/compose.yaml b/samples/huginn/compose.yaml index f9287476..1b9f35bb 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: @@ -10,7 +10,7 @@ services: resources: reservations: cpus: '1.0' - memory: '2G' + memory: 1G healthcheck: test: ["CMD", "curl", "-f", "http://localhost:3000/"] interval: 1m30s @@ -18,7 +18,19 @@ services: retries: 10 environment: - DATABASE_ADAPTER=postgresql - - DATABASE_NAME - - DATABASE_USERNAME - - DATABASE_PASSWORD - - DATABASE_HOST + - DATABASE_NAME=huginn + - DATABASE_USERNAME=huginn + - 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 From eadef7169587029dc05bf5ab0162b43db0e007bb Mon Sep 17 00:00:00 2001 From: commit111 Date: Wed, 27 Nov 2024 15:11:26 -0800 Subject: [PATCH 2/3] postgres 14 --- samples/huginn/compose.dev.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/huginn/compose.dev.yaml b/samples/huginn/compose.dev.yaml index b95005d0..bd51e284 100644 --- a/samples/huginn/compose.dev.yaml +++ b/samples/huginn/compose.dev.yaml @@ -9,7 +9,7 @@ services: depends_on: - postgres postgres: - image: postgres:16 + image: postgres:14 environment: POSTGRES_USER: huginn POSTGRES_PASSWORD: huginn From dc902ad7f4df4d129325e517b1542359a0125a60 Mon Sep 17 00:00:00 2001 From: Jordan Stephens Date: Mon, 16 Dec 2024 13:56:43 -0600 Subject: [PATCH 3/3] fixup compose --- samples/huginn/compose.dev.yaml | 15 +++++++++------ samples/huginn/compose.yaml | 16 ++++++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/samples/huginn/compose.dev.yaml b/samples/huginn/compose.dev.yaml index bd51e284..ec1d944e 100644 --- a/samples/huginn/compose.dev.yaml +++ b/samples/huginn/compose.dev.yaml @@ -1,15 +1,18 @@ services: huginn: + extends: + file: compose.yaml + service: huginn-app environment: - DATABASE_ADAPTER=postgresql - DATABASE_NAME=huginn - DATABASE_USERNAME=huginn - DATABASE_PASSWORD=huginn - - DATABASE_HOST=postgres - depends_on: - - postgres - postgres: - image: postgres:14 + - DATABASE_HOST=db + db: + extends: + file: compose.yaml + service: db environment: POSTGRES_USER: huginn POSTGRES_PASSWORD: huginn @@ -18,4 +21,4 @@ services: - postgres:/var/lib/postgresql/data volumes: - postgres: \ No newline at end of file + postgres: diff --git a/samples/huginn/compose.yaml b/samples/huginn/compose.yaml index 1b9f35bb..62321efe 100644 --- a/samples/huginn/compose.yaml +++ b/samples/huginn/compose.yaml @@ -1,5 +1,5 @@ services: - huginn-app: + huginn: image: ghcr.io/huginn/huginn restart: unless-stopped ports: @@ -20,17 +20,17 @@ services: - DATABASE_ADAPTER=postgresql - DATABASE_NAME=huginn - DATABASE_USERNAME=huginn - - DATABASE_PASSWORD=${POSTGRES_PASSWORD} - - DATABASE_HOST=postgresx - postgresx: - image: postgres:14 + - DATABASE_HOST=db + - DATABASE_PASSWORD="${POSTGRES_PASSWORD}" + depends_on: + - db + db: + image: postgres:16 environment: - POSTGRES_USER=huginn - - POSTGRES_PASSWORD - POSTGRES_DB=huginn + - POSTGRES_PASSWORD ports: - mode: host target: 5432 published: 5432 - networks: - - public