Skip to content

Commit f92b2f1

Browse files
committed
Merge branch 'main' of github.com:DefangLabs/samples
2 parents 4e22eb5 + d237cb0 commit f92b2f1

File tree

43 files changed

+8355
-60
lines changed

Some content is hidden

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

43 files changed

+8355
-60
lines changed

.github/workflows/check-sample.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
./scripts/check-modified-samples.sh > modified.txt
3131
echo "@@ MODIFIED @@"
3232
cat modified.txt
33+
echo "@@ CHECKLIST @@"
34+
cat checklist.txt
3335
3436
# TODO: Uncomment the following lines to validate the Compose files
3537
# once we figure out how to prevent it from erroring on warnings.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Defang Software Labs
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

samples/agentic-strands/app/agent.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ def chat():
158158
print(f"Error in /chat endpoint: {str(e)}")
159159
return jsonify({"error": str(e), "response": str(e)}), 500
160160

161+
@app.get("/health")
162+
def health_check():
163+
"""Health check endpoint"""
164+
return "ok"
165+
166+
161167
# Start Flask server when this script is run directly
162168
if __name__ == '__main__':
163169

samples/agentic-strands/compose.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,25 @@ services:
1313
LLM_URL: http://llm/api/v1/
1414
LLM_MODEL: default
1515
OPENAI_API_KEY: FAKE_TOKEN
16+
healthcheck:
17+
test:
18+
[
19+
"CMD",
20+
"python3",
21+
"-c",
22+
"import urllib.request; exit(0) if urllib.request.urlopen('http://localhost:5001/health').status == 200 else exit(1)",
23+
]
24+
interval: 30s
25+
timeout: 5s
26+
retries: 3
27+
start_period: 10s
1628
depends_on:
1729
- llm
1830

1931
llm:
2032
environment:
2133
- OPENAI_API_KEY=FAKE_TOKEN
22-
image: defangio/openai-access-gateway:06339c7
34+
image: defangio/openai-access-gateway
2335
ports:
2436
- target: 80
2537
published: 80

samples/django-celery/app/command.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#!/bin/bash
22

3-
# Apply database migrations
4-
python manage.py migrate
5-
63
# Create superuser if not exists
74
python manage.py createsuperauto
85

samples/django-celery/compose.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ services:
1010
- POSTGRES_URL=postgres://postgres:${POSTGRES_PASSWORD}@database:5432/postgres
1111
depends_on:
1212
- database
13+
- migrate
1314
- broker
1415
ports:
1516
- mode: ingress
@@ -22,6 +23,19 @@ services:
2223
retries: 3
2324
start_period: 20s
2425

26+
migrate:
27+
restart: no
28+
build:
29+
context: ./app
30+
dockerfile: Dockerfile
31+
environment:
32+
- SECRET_KEY
33+
- REDIS_URL=redis://broker:6379/0
34+
- POSTGRES_URL=postgres://postgres:${POSTGRES_PASSWORD}@database:5432/postgres
35+
depends_on:
36+
- database
37+
command: python manage.py migrate
38+
2539
worker:
2640
restart: unless-stopped
2741
build:
@@ -37,6 +51,7 @@ services:
3751
depends_on:
3852
- database
3953
- broker
54+
- migrate
4055
command: celery -A django_celery worker --loglevel=info
4156

4257
database:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(docker compose:*)"
5+
],
6+
"deny": []
7+
}
8+
}

samples/django-channels-redis-postgres/app/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Use a smaller base image
2-
FROM python:3.10-slim-buster
2+
FROM python:3.10-slim-bullseye
33

44
# Set environment variables
55
ENV PYTHONDONTWRITEBYTECODE=1
@@ -12,7 +12,8 @@ RUN apt-get update \
1212
&& apt-get install -y \
1313
gcc \
1414
python3-dev \
15-
libpq-dev
15+
libpq-dev \
16+
netcat-openbsd
1617

1718
# Install dependencies
1819
COPY requirements.txt /app/
@@ -32,4 +33,4 @@ RUN adduser --disabled-password --gecos '' django
3233
USER django
3334

3435
# Start server
35-
CMD ["sh", "-c", "python manage.py migrate && daphne -b 0.0.0.0 -p 8000 django_defang.asgi:application"]
36+
CMD ["sh", "-c", "daphne -b 0.0.0.0 -p 8000 django_defang.asgi:application"]

samples/django-channels-redis-postgres/compose.dev.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@ services:
1313
depends_on:
1414
- redis-service
1515
- postgres-service
16-
command: sh -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
16+
- migrate
17+
command: sh -c "python manage.py runserver 0.0.0.0:8000"
1718

19+
migrate:
20+
extends:
21+
file: compose.yaml
22+
service: migrate
23+
environment:
24+
- POSTGRES_URL=postgres://djangouser:djangopassword@postgres-service:5432/djangodatabase
25+
1826
redis-service:
1927
extends:
2028
file: compose.yaml

samples/django-channels-redis-postgres/compose.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ services:
2222
depends_on:
2323
- redis-service
2424
- postgres-service
25+
- migrate
2526

2627
redis-service:
2728
image: redis:6.2
@@ -31,6 +32,18 @@ services:
3132
- mode: host
3233
target: 6379
3334

35+
migrate:
36+
restart: "no"
37+
build:
38+
context: ./app
39+
dockerfile: Dockerfile
40+
command: python manage.py migrate
41+
depends_on:
42+
- postgres-service
43+
environment:
44+
- POSTGRES_URL=postgres://djangouser:${POSTGRES_PASSWORD}@postgres-service:5432/djangodatabase?
45+
- SECRET_KEY
46+
3447
postgres-service:
3548
image: postgres:16.4
3649
# uncomment the following line in BYOC

0 commit comments

Comments
 (0)