Skip to content

Commit 4e22eb5

Browse files
committed
Merge branch 'main' of github.com:DefangLabs/samples
2 parents 5554bac + 3a28668 commit 4e22eb5

File tree

222 files changed

+22228
-53
lines changed

Some content is hidden

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

222 files changed

+22228
-53
lines changed
Lines changed: 91 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,100 @@
11
name: Trigger Docs Samples Rebuild
2+
permissions:
3+
contents: read
4+
pull-requests: read
25

36
on:
4-
push:
5-
branches: main
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
branches:
10+
- "**"
611
paths:
7-
- 'samples/**'
12+
- "samples/**"
813

914
jobs:
15+
# python-lint:
16+
# runs-on: ubuntu-latest
17+
# steps:
18+
# - name: Checkout code
19+
# uses: actions/checkout@v4
20+
21+
# - name: Get list of changed files
22+
# id: changed
23+
# run: |
24+
# files=$(git diff --name-only origin/${{ github.base_ref }}...${{ github.head_ref }} | grep '\.py$' || true)
25+
# echo "files=$files" >> "$GITHUB_OUTPUT"
26+
27+
# - name: Run Ruff linter
28+
# uses: astral-sh/ruff-action@v1
29+
# with:
30+
# args: check
31+
# src: ${{ steps.changed.outputs.files }}
32+
33+
# - name: Run Ruff formatter check
34+
# uses: astral-sh/ruff-action@v1
35+
# with:
36+
# args: "format --check"
37+
# src: ${{ steps.changed.outputs.files }}
38+
39+
js-ts-lint:
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: Checkout code
43+
uses: actions/checkout@v4
44+
45+
- name: Set up Node.js
46+
uses: actions/setup-node@v4
47+
with:
48+
node-version: "20"
49+
50+
- name: Get list of changed JS/TS files
51+
id: changed_js
52+
run: |
53+
files=$(git diff --name-only origin/${{ github.base_ref }}...${{ github.head_ref }} | grep -E '\.(js|ts|jsx|tsx)$' || true)
54+
echo "files=$files" >> "$GITHUB_OUTPUT"
55+
56+
- name: Run ESLint (JS/TS only)
57+
run: |
58+
if [ -n "${{ steps.changed_js.outputs.files }}" ]; then
59+
npx eslint ${{ steps.changed_js.outputs.files }}
60+
else
61+
echo "No JS/TS files to lint."
62+
fi
63+
64+
- name: Run Prettier check (JS/TS only)
65+
run: |
66+
if [ -n "${{ steps.changed_js.outputs.files }}" ]; then
67+
npx prettier --check ${{ steps.changed_js.outputs.files }}
68+
else
69+
echo "No JS/TS files to format check."
70+
fi
71+
72+
# go-lint:
73+
# runs-on: ubuntu-latest
74+
# steps:
75+
# - name: Checkout code
76+
# uses: actions/checkout@v4
77+
78+
# - name: Set up Golang
79+
# uses: actions/setup-go@v5
80+
# with:
81+
# go-version: stable
82+
83+
# - name: Run golangci-lint
84+
# uses: golangci/golangci-lint-action@v8
85+
# with:
86+
# args: --enable gofmt --enable goimports
87+
# only-new-issues: true
88+
# version: latest
89+
1090
build-json:
1191
runs-on: ubuntu-latest
92+
# needs: [python-lint, js-ts-lint, go-lint]
93+
needs: [js-ts-lint]
1294
steps:
13-
- name: Trigger CLI Autodoc
14-
uses: peter-evans/repository-dispatch@v1
15-
with:
16-
token: ${{ secrets.DOCS_ACTION_TRIGGER_TOKEN }}
17-
repository: DefangLabs/defang-docs
18-
event-type: sample-update
95+
- name: Trigger CLI Autodoc
96+
uses: peter-evans/repository-dispatch@v1
97+
with:
98+
token: ${{ secrets.DOCS_ACTION_TRIGGER_TOKEN }}
99+
repository: DefangLabs/defang-docs
100+
event-type: sample-update

.github/workflows/deploy-changed-samples.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Deploy Changed Samples
33
on:
44
pull_request:
55
paths:
6-
- 'samples/**'
6+
- "samples/**"
77

88
permissions:
99
contents: read
@@ -82,6 +82,8 @@ jobs:
8282
TEST_MB_DB_PASS: ${{ secrets.TEST_MB_DB_PASS }}
8383
TEST_MB_DB_PORT: ${{ secrets.TEST_MB_DB_PORT }}
8484
TEST_MB_DB_USER: ${{ secrets.TEST_MB_DB_USER }}
85+
TEST_MISTRAL_API_KEY: ${{ secrets.TEST_MISTRAL_API_KEY }}
86+
TEST_MODEL: ${{ secrets.TEST_MODEL }}
8587
TEST_MONGO_INITDB_ROOT_USERNAME: ${{ secrets.TEST_MONGO_INITDB_ROOT_USERNAME }}
8688
TEST_MONGO_INITDB_ROOT_PASSWORD: ${{ secrets.TEST_MONGO_INITDB_ROOT_PASSWORD }}
8789
TEST_NC_DB: ${{ secrets.TEST_NC_DB }}
@@ -100,6 +102,7 @@ jobs:
100102
TEST_SLACK_CHANNEL_ID: ${{ secrets.TEST_SLACK_CHANNEL_ID }}
101103
TEST_SLACK_TOKEN: ${{ secrets.TEST_SLACK_TOKEN }}
102104
TEST_SHARED_SECRETS: ${{ secrets.TEST_SHARED_SECRETS}}
105+
TEST_TAVILY_API_KEY: ${{ secrets.TEST_TAVILY_API_KEY }}
103106
TEST_ALLOWED_HOSTS: ${{ secrets.TEST_ALLOWED_HOSTS }}
104107
run: |
105108
SAMPLES=$(sed 's|^samples/||' changed_samples.txt | paste -s -d ',' -)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
FROM mcr.microsoft.com/devcontainers/python:3.13-bookworm
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+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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]
22+
with:
23+
config-env-vars: MISTRAL_API_KEY
24+
env:
25+
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}

samples/agentic-autogen/.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Environment variables
2+
.env
3+
.env.local
4+
.env.production
5+
6+
# Python
7+
__pycache__/
8+
/myenv
9+
10+
# Node.js
11+
node_modules/
12+
npm-debug.log*
13+
.pnpm-debug.log*
14+
15+
# Frontend build
16+
frontend/dist/
17+
frontend/build/
18+
19+
# IDE
20+
.vscode/
21+
.idea/
22+
*~
23+
24+
# OS
25+
.DS_Store
26+
._*
27+
Thumbs.db
28+
29+
# Optional npm cache directory
30+
.npm

samples/agentic-autogen/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Agentic Autogen
2+
3+
[![1-click-deploy](https://raw.githubusercontent.com/DefangLabs/defang-assets/main/Logos/Buttons/SVG/deploy-with-defang.svg)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-agentic-autogen-template%26template_owner%3DDefangSamples)
4+
5+
This sample shows an agentic Autogen application using Mistral and FastAPI, deployed with Defang. For demonstration purposes, it will require a [Mistral AI](https://mistral.ai/) API key (see [Configuration](#configuration) for more details). However, you are free to modify it to use a different LLM, say the [Defang OpenAI Access Gateway](https://github.com/DefangLabs/openai-access-gateway/) service, as an alternative. Note that the Vite React frontend is served through the FastAPI backend so that they can be treated as one service in production.
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+
13+
## Development
14+
15+
To run the application locally, you can use the following command:
16+
17+
```bash
18+
docker compose up --build
19+
```
20+
21+
## Configuration
22+
23+
For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration):
24+
25+
> 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.
26+
27+
### `MISTRAL_API_KEY`
28+
An API key to access the [Mistral AI API](https://mistral.ai/).
29+
```bash
30+
defang config set MISTRAL_API_KEY
31+
```
32+
33+
## Deployment
34+
35+
> [!NOTE]
36+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
37+
38+
### Defang Playground
39+
40+
Deploy your application to the Defang Playground by opening up your terminal and typing:
41+
```bash
42+
defang compose up
43+
```
44+
45+
### BYOC
46+
47+
If you want to deploy to your own cloud account, you can [use Defang BYOC](https://docs.defang.io/docs/tutorials/deploy-to-your-cloud).
48+
49+
---
50+
51+
Title: Agentic Autogen
52+
53+
Short Description: An Autogen agent application using Mistral and FastAPI, deployed with Defang.
54+
55+
Tags: Agent, Autogen, Mistral, FastAPI, Vite, React, Python, JavaScript, AI
56+
57+
Languages: Python, JavaScript
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
services:
3+
autogen:
4+
build:
5+
context: ./src
6+
dockerfile: Dockerfile
7+
ports:
8+
- "3000:3000"
9+
environment:
10+
- MISTRAL_API_KEY=${MISTRAL_API_KEY}
11+
restart: unless-stopped
12+
healthcheck:
13+
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
14+
interval: 30s
15+
timeout: 10s
16+
retries: 3
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Default .dockerignore file for Defang
2+
**/__pycache__
3+
**/.direnv
4+
**/.DS_Store
5+
**/.envrc
6+
**/.git
7+
**/.github
8+
**/.idea
9+
**/.next
10+
**/.vscode
11+
**/compose.*.yaml
12+
**/compose.*.yml
13+
**/compose.yaml
14+
**/compose.yml
15+
**/docker-compose.*.yaml
16+
**/docker-compose.*.yml
17+
**/docker-compose.yaml
18+
**/docker-compose.yml
19+
**/node_modules
20+
**/Thumbs.db
21+
# Dockerfile
22+
# *.Dockerfile
23+
# Ignore our own binary, but only in the root to avoid ignoring subfolders
24+
defang
25+
defang.exe
26+
# Ignore our project-level state
27+
.defang
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# ------------ FRONTEND BUILD STAGE ------------ #
2+
FROM node:22-alpine AS frontend-build
3+
4+
WORKDIR /frontend
5+
6+
# Copy only package files first (cache optimization)
7+
COPY frontend/package*.json ./
8+
RUN npm ci
9+
10+
# Copy rest of the frontend source
11+
COPY frontend/ ./
12+
RUN npm run build
13+
14+
15+
# ------------ BACKEND STAGE ------------ #
16+
FROM python:3.13-slim AS backend
17+
18+
WORKDIR /app
19+
20+
# Install build dependencies for Python packages
21+
RUN apt-get update && apt-get install -y \
22+
gcc \
23+
curl \
24+
&& rm -rf /var/lib/apt/lists/*
25+
26+
# Install dependencies
27+
COPY backend/requirements.txt ./
28+
RUN pip install --no-cache-dir -r requirements.txt
29+
30+
# Copy backend code
31+
COPY backend/ ./
32+
33+
# Copy built frontend into backend's static folder
34+
COPY --from=frontend-build /frontend/dist ./static
35+
36+
# Optionally expose the same port for both backend and frontend
37+
EXPOSE 3000
38+
39+
# Start the backend server (which serves both API + frontend files)
40+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "3000"]

0 commit comments

Comments
 (0)