Skip to content

Commit e817efe

Browse files
committed
sample working locally with docker model runner and basic crewai setup
1 parent 5554bac commit e817efe

Some content is hidden

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

51 files changed

+6737
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Note: universal image is not compatible with the devcontainer tools.
2+
# we use the typescript-node image instead here but should switch out per
3+
# project requirements. You can choose a devcontainer that's appropriate
4+
# for your sample from the list below #REMOVE_ME_AFTER_EDITING
5+
6+
# FROM mcr.microsoft.com/devcontainers/go:1.22-bookworm
7+
# FROM mcr.microsoft.com/devcontainers/python:3.12-bookworm
8+
# FROM mcr.microsoft.com/devcontainers/php:8.3-bookworm
9+
# FROM mcr.microsoft.com/devcontainers/ruby:3.2-bookworm
10+
# FROM mcr.microsoft.com/devcontainers/java:11-bookworm
11+
# FROM mcr.microsoft.com/devcontainers/rust:1-bookworm
12+
FROM mcr.microsoft.com/devcontainers/typescript-node:22-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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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/defang-github-action@v1.1.3
22+
#REMOVE_ME_AFTER_EDITING - Replace the following line with the list of environment variables you want to pass to the action
23+
# or remove the lines if you don't need to pass any environment variables/secrets to the action
24+
with:
25+
config-env-vars: ENV1 ENV2
26+
env:
27+
ENV1: ${{ secrets.ENV1 }}
28+
ENV2: ${{ secrets.ENV2 }}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Python
2+
__pycache__/
3+
*.pyc
4+
*.pyo
5+
*.pyd
6+
.Python
7+
env/
8+
venv/
9+
ENV/
10+
build/
11+
develop-eggs/
12+
dist/
13+
downloads/
14+
eggs/
15+
.eggs/
16+
lib/
17+
lib64/
18+
parts/
19+
sdist/
20+
var/
21+
*.egg-info/
22+
.installed.cfg
23+
*.egg
24+
25+
# Django
26+
*.log
27+
staticfiles/
28+
media/
29+
db.sqlite3
30+
31+
# Node
32+
node_modules/
33+
.next/
34+
.env
35+
36+
# Docker
37+
pgdata/
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
trigger: always_on
3+
---
4+
5+
Whenever you run commands for this project, run them in the relevant docker containers.
6+
7+
i.e. if you need to install a new package, use `docker compose run --rm` to install. Feel free to use volume mounts to persist the results, change the entrypoint, etc. Anything you need to. But the commands and deps need to work in the containerized environment, which is why I'm going to require you to work this way.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Dockerfile for Django API/Worker
2+
FROM python:3.11-slim
3+
4+
ENV PYTHONDONTWRITEBYTECODE 1
5+
ENV PYTHONUNBUFFERED 1
6+
WORKDIR /app
7+
8+
COPY requirements.txt ./
9+
RUN pip install --upgrade pip && pip install -r requirements.txt
10+
11+
COPY . .
12+
13+
RUN chmod +x run.sh
14+
15+
CMD ["./run.sh"]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .celery import app as celery_app
2+
3+
__all__ = ("celery_app",)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
ASGI config for config project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from channels.routing import ProtocolTypeRouter, URLRouter
13+
from django.core.asgi import get_asgi_application
14+
from channels.auth import AuthMiddlewareStack
15+
import os
16+
17+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
18+
19+
import core.routing
20+
21+
application = ProtocolTypeRouter({
22+
"http": get_asgi_application(),
23+
"websocket": AuthMiddlewareStack(
24+
URLRouter(
25+
core.routing.websocket_urlpatterns
26+
)
27+
),
28+
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
from celery import Celery
3+
4+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
5+
6+
app = Celery("config")
7+
app.config_from_object("django.conf:settings", namespace="CELERY")
8+
app.autodiscover_tasks()
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
"""
2+
Django settings for config project.
3+
4+
Generated by 'django-admin startproject' using Django 5.1.2.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.1/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/5.1/ref/settings/
11+
"""
12+
13+
from pathlib import Path
14+
15+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
16+
BASE_DIR = Path(__file__).resolve().parent.parent
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = 'django-insecure-nt!j#(2z3-x!rqmawyjw(q3y$9#rx1dfxk!w7(cmwf6kg%cb25'
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
import os
29+
30+
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS", "*").split(",")
31+
32+
33+
# Application definition
34+
35+
INSTALLED_APPS = [
36+
'daphne',
37+
'django.contrib.admin',
38+
'django.contrib.auth',
39+
'django.contrib.contenttypes',
40+
'django.contrib.sessions',
41+
'django.contrib.messages',
42+
'django.contrib.staticfiles',
43+
'channels',
44+
'core',
45+
]
46+
47+
MIDDLEWARE = [
48+
'django.middleware.security.SecurityMiddleware',
49+
'whitenoise.middleware.WhiteNoiseMiddleware',
50+
'django.contrib.sessions.middleware.SessionMiddleware',
51+
'django.middleware.common.CommonMiddleware',
52+
'django.middleware.csrf.CsrfViewMiddleware',
53+
'django.contrib.auth.middleware.AuthenticationMiddleware',
54+
'django.contrib.messages.middleware.MessageMiddleware',
55+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
56+
]
57+
58+
ROOT_URLCONF = 'config.urls'
59+
60+
TEMPLATES = [
61+
{
62+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
63+
'DIRS': [],
64+
'APP_DIRS': True,
65+
'OPTIONS': {
66+
'context_processors': [
67+
'django.template.context_processors.debug',
68+
'django.template.context_processors.request',
69+
'django.contrib.auth.context_processors.auth',
70+
'django.contrib.messages.context_processors.messages',
71+
],
72+
},
73+
},
74+
]
75+
76+
ASGI_APPLICATION = 'config.asgi.application'
77+
WSGI_APPLICATION = 'config.wsgi.application'
78+
79+
80+
# Database
81+
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
82+
83+
DATABASES = {
84+
'default': {
85+
'ENGINE': 'django.db.backends.postgresql',
86+
'NAME': os.environ.get('POSTGRES_DB', 'app_db'),
87+
'USER': os.environ.get('POSTGRES_USER', 'user'),
88+
'PASSWORD': os.environ.get('POSTGRES_PASSWORD', 'password'),
89+
'HOST': os.environ.get('POSTGRES_HOST', 'postgres'),
90+
'PORT': os.environ.get('POSTGRES_PORT', '5432'),
91+
}
92+
}
93+
94+
95+
# Password validation
96+
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
97+
98+
AUTH_PASSWORD_VALIDATORS = [
99+
{
100+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
101+
},
102+
{
103+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
104+
},
105+
{
106+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
107+
},
108+
{
109+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
110+
},
111+
]
112+
113+
114+
# Internationalization
115+
# https://docs.djangoproject.com/en/5.1/topics/i18n/
116+
117+
LANGUAGE_CODE = 'en-us'
118+
119+
TIME_ZONE = 'UTC'
120+
121+
USE_I18N = True
122+
123+
USE_TZ = True
124+
125+
126+
# Static files (CSS, JavaScript, Images)
127+
# https://docs.djangoproject.com/en/5.1/howto/static-files/
128+
129+
STATIC_URL = '/static/'
130+
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
131+
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
132+
133+
# Default primary key field type
134+
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
135+
136+
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
137+
138+
# Channels/Redis
139+
CHANNEL_LAYERS = {
140+
"default": {
141+
"BACKEND": "channels_redis.core.RedisChannelLayer",
142+
"CONFIG": {
143+
"hosts": [(os.environ.get("REDIS_HOST", "redis"), 6379)],
144+
},
145+
},
146+
}
147+
148+
# Celery
149+
CELERY_BROKER_URL = os.environ.get("CELERY_BROKER_URL", "redis://redis:6379/0")
150+
CELERY_RESULT_BACKEND = os.environ.get("CELERY_RESULT_BACKEND", "redis://redis:6379/0")
151+
152+
# CrewAI (no special settings needed for hello world)

0 commit comments

Comments
 (0)