Skip to content

Commit 4d26c9c

Browse files
committed
merge
2 parents 7ea8798 + 40d20a8 commit 4d26c9c

File tree

9 files changed

+176
-68
lines changed

9 files changed

+176
-68
lines changed

.github/workflows/check-sample.yml

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -42,50 +42,12 @@ jobs:
4242
uses: actions/github-script@v5
4343
with:
4444
script: |
45-
const fs = require('fs');
46-
const pr_number = context.issue.number;
47-
const marker = '## Samples Checklist';
48-
49-
// Read the checklist from the file
50-
let checklist = fs.readFileSync('checklist.txt', 'utf8').trim();
51-
let error = false;
52-
53-
if(!checklist) {
54-
checklist = "✅ All good!"
55-
}
56-
else {
57-
error = true;
58-
}
59-
60-
// Get the current PR
61-
const { data: pullRequest } = await github.rest.pulls.get({
62-
owner: context.repo.owner,
63-
repo: context.repo.repo,
64-
pull_number: pr_number
65-
});
66-
67-
let newBody;
68-
const body = pullRequest.body || "";
69-
const markerIndex = body.indexOf(marker);
70-
71-
if (markerIndex !== -1) {
72-
// Replace the content below the marker
73-
newBody = body.substring(0, markerIndex + marker.length) + "\n" + checklist;
74-
} else {
75-
// Append the checklist if the marker doesn't exist
76-
newBody = body + "\n" + marker + "\n" + checklist;
77-
}
78-
79-
// Update the PR description
80-
await github.rest.pulls.update({
81-
owner: context.repo.owner,
82-
repo: context.repo.repo,
83-
pull_number: pr_number,
84-
body: newBody
85-
});
86-
87-
if(error) {
88-
throw new Error("Incomplete samples checklist. Please fix the issues and try again.");
45+
const script = require('./scripts/add-checklist-to-pr.js');
46+
try {
47+
await script({github, context});
48+
core.info(`Checklist successfully added to PR description`);
49+
} catch (error) {
50+
core.setFailed(`Script execution failed: ${error.message}`);
8951
}
9052
9153
- name: Create / Update Template Repo

.github/workflows/publish-sample-template.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- main
77

88
jobs:
9-
check_samples:
9+
publish_samples:
1010
runs-on: ubuntu-latest
1111
permissions:
1212
contents: write

samples/django-postgres/compose.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ services:
22
db:
33
restart: unless-stopped
44
image: postgres:16
5+
x-defang-postgres: true
56
environment:
67
- POSTGRES_DB=django
78
- POSTGRES_USER=django
89
- POSTGRES_PASSWORD
910
ports:
1011
- mode: host
1112
target: 5432
13+
published: 5432
1214

1315
django:
16+
# uncomment to add your own domain
17+
# domainname: example.com
1418
restart: unless-stopped
1519
build: ./app
1620
ports:

samples/huginn/README.md

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,77 @@
22

33
[![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)
44

5+
This sample shows how to deploy Huginn with Defang.
6+
57
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.
68

79
## Prerequisites
810

911
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
10-
2. Have a managed database service configured and have the connection details ready. Neon postgres is a good free option.
11-
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).
12+
2. Have a managed database service configured and ready, such as [Neon PostgreSQL](https://neon.tech/)
13+
3. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
14+
4. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
15+
16+
## Development
17+
18+
To run the application locally, you can use the following command:
19+
20+
```bash
21+
docker compose -f ./compose.yaml -f ./compose.dev.yaml up
22+
```
23+
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`.
24+
25+
## Configuration
26+
27+
For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration):
28+
29+
> 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.
30+
31+
### `DATABASE_NAME`
32+
The name of the database.
33+
```bash
34+
defang config set DATABASE_NAME
35+
```
36+
37+
### `DATABASE_USERNAME`
38+
The username used with the database.
39+
```bash
40+
defang config set DATABASE_USERNAME
41+
```
42+
43+
### `DATABASE_PASSWORD`
44+
The password used with the database.
45+
```bash
46+
defang config set DATABASE_PASSWORD
47+
```
48+
49+
### `DATABASE_HOST`
50+
The host of the database.
51+
```bash
52+
defang config set DATABASE_HOST
53+
```
54+
55+
## Deployment
56+
57+
> [!NOTE]
58+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
1259
13-
## Local
60+
### Defang Playground
1461

15-
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.
62+
Deploy your application to the Defang Playground by opening up your terminal and typing:
63+
```bash
64+
defang compose up
65+
```
1666

17-
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`.
67+
### BYOC (AWS)
1868

19-
## Deploying
69+
If you want to deploy to your own cloud account, you can use Defang BYOC:
2070

21-
1. Open the terminal and type `defang login`
22-
2. Add your database connection details using `defang config` by typing `defang config set <CONFIG_VAL>` where `<CONFIG_VAL>` 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.
23-
3. Type `defang compose up` in the CLI.
24-
4. Your app will be running within a few minutes.
71+
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`.
72+
2. Run in a terminal that has access to your AWS environment variables:
73+
```bash
74+
defang --provider=aws compose up
75+
```
2576

2677
---
2778

samples/huginn/compose.dev.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
services:
22
huginn:
3+
extends:
4+
file: compose.yaml
5+
service: huginn-app
36
environment:
47
- DATABASE_ADAPTER=postgresql
58
- DATABASE_NAME=huginn
69
- DATABASE_USERNAME=huginn
710
- DATABASE_PASSWORD=huginn
8-
- DATABASE_HOST=postgres
9-
depends_on:
10-
- postgres
11-
postgres:
12-
image: postgres:16
11+
- DATABASE_HOST=db
12+
db:
13+
extends:
14+
file: compose.yaml
15+
service: db
1316
environment:
1417
POSTGRES_USER: huginn
1518
POSTGRES_PASSWORD: huginn
@@ -18,4 +21,4 @@ services:
1821
- postgres:/var/lib/postgresql/data
1922

2023
volumes:
21-
postgres:
24+
postgres:

samples/huginn/compose.yaml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,27 @@ services:
1010
resources:
1111
reservations:
1212
cpus: '1.0'
13-
memory: '2G'
13+
memory: 1G
1414
healthcheck:
1515
test: ["CMD", "curl", "-f", "http://localhost:3000/"]
1616
interval: 1m30s
1717
timeout: 30s
1818
retries: 10
1919
environment:
2020
- DATABASE_ADAPTER=postgresql
21-
- DATABASE_NAME
22-
- DATABASE_USERNAME
23-
- DATABASE_PASSWORD
24-
- DATABASE_HOST
21+
- DATABASE_NAME=huginn
22+
- DATABASE_USERNAME=huginn
23+
- DATABASE_HOST=db
24+
- DATABASE_PASSWORD="${POSTGRES_PASSWORD}"
25+
depends_on:
26+
- db
27+
db:
28+
image: postgres:16
29+
environment:
30+
- POSTGRES_USER=huginn
31+
- POSTGRES_DB=huginn
32+
- POSTGRES_PASSWORD
33+
ports:
34+
- mode: host
35+
target: 5432
36+
published: 5432

samples/react/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ It includes Vite and ESLint, which are common build tools for React development.
1616
To run the application locally, you can use the following command (make sure you've got `npm` and [Node.js](https://nodejs.org/en) installed):
1717

1818
```bash
19+
npm install
1920
npm run dev
2021
```
2122

scripts/add-checklist-to-pr.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const fs = require('fs');
2+
3+
module.exports = async ({ github, context }) => {
4+
const pr_number = context.issue.number;
5+
const marker = '## Samples Checklist';
6+
7+
let checklist;
8+
let error = false;
9+
10+
try {
11+
// Read the checklist from the file
12+
checklist = fs.readFileSync('checklist.txt', 'utf8');
13+
checklist = checklist.trim();
14+
if(!checklist) {
15+
checklist = "✅ All good!"
16+
}
17+
else {
18+
error = true;
19+
}
20+
} catch (readFileError) {
21+
throw new Error("Could not read samples checklist from file. Please fix the issues and try again.")
22+
}
23+
24+
let pullRequest;
25+
26+
try {
27+
// Get the current PR
28+
const { data: prData } = await github.rest.pulls.get({
29+
owner: context.repo.owner,
30+
repo: context.repo.repo,
31+
pull_number: pr_number
32+
});
33+
pullRequest = prData;
34+
} catch (getPrError) {
35+
throw new Error ("Could not get current PR from source. Please fix the issues and try again.")
36+
}
37+
38+
try {
39+
let newBody;
40+
const body = pullRequest.body || "";
41+
const markerIndex = body.indexOf(marker);
42+
43+
if (markerIndex !== -1) {
44+
// Replace the content below the marker
45+
newBody = body.substring(0, markerIndex + marker.length) + "\n" + checklist;
46+
} else {
47+
// Append the checklist if the marker doesn't exist
48+
newBody = body + "\n" + marker + "\n" + checklist;
49+
}
50+
51+
console.log('@@ pulls opts: ', {
52+
owner: context.repo.owner,
53+
repo: context.repo.repo,
54+
pull_number: pr_number,
55+
body: newBody
56+
});
57+
58+
// Update the PR description
59+
await github.rest.pulls.update({
60+
owner: context.repo.owner,
61+
repo: context.repo.repo,
62+
pull_number: pr_number,
63+
body: newBody
64+
});
65+
} catch (updatePrError) {
66+
console.error('@@ updatePrError: ', updatePrError);
67+
throw new Error("Could not update PR description based on samples checklist. Please fix the issues and try again.")
68+
}
69+
70+
if (error) {
71+
throw new Error("Incomplete samples checklist. Please fix the issues and try again.");
72+
}
73+
74+
}

scripts/check-sample-files.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ for dir in ./samples/*/; do
1818
# if there is a compose.yaml file, check if it is valid
1919
(
2020
cd $dir
21-
if ! defang compose config > /dev/null 2>/dev/null; then
22-
echo " - [ ] ${dir}compose.yaml contains errors"
21+
output=$(defang compose config 2>&1)
22+
if [[ $? -ne 0 ]]; then
23+
echo " - [ ] ${dir}compose.yaml is not valid according to \`defang compose config\`: $output"
2324
fi
2425
)
2526
fi

0 commit comments

Comments
 (0)