Skip to content

Commit 0690663

Browse files
authored
Merge pull request #116 from korjavin/main
Dockerfiles for backend/frontend + github actions + docker-compose
2 parents 7555086 + ef27d65 commit 0690663

File tree

6 files changed

+205
-7
lines changed

6 files changed

+205
-7
lines changed

.github/workflows/docker-build.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Build and Push Docker Images
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
packages: write
11+
12+
jobs:
13+
build-and-push:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Set up Docker Buildx
19+
uses: docker/setup-buildx-action@v3
20+
21+
- name: Log in to GitHub Container Registry
22+
uses: docker/login-action@v3
23+
with:
24+
registry: ghcr.io
25+
username: ${{ github.actor }}
26+
password: ${{ secrets.GITHUB_TOKEN }}
27+
28+
- name: Build and push Backend image
29+
uses: docker/build-push-action@v5
30+
with:
31+
context: ./backend
32+
file: ./backend/Dockerfile
33+
push: true
34+
tags: ghcr.io/${{ github.repository }}/suna-backend:latest
35+
cache-from: type=gha
36+
cache-to: type=gha,mode=max
37+
38+
- name: Build and push Frontend image
39+
uses: docker/build-push-action@v5
40+
with:
41+
context: ./frontend
42+
file: ./frontend/Dockerfile
43+
push: true
44+
tags: ghcr.io/${{ github.repository }}/suna-frontend:latest
45+
cache-from: type=gha
46+
cache-to: type=gha,mode=max

README.md

+41-4
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ You'll need the following components:
9494

9595
### Prerequisites
9696

97-
1. **Supabase**:
97+
1. **Supabase**:
9898
- Create a new [Supabase project](https://supabase.com/dashboard/projects)
9999
- Save your project's API URL, anon key, and service role key for later use
100100
- Install the [Supabase CLI](https://supabase.com/docs/guides/cli/getting-started)
@@ -105,9 +105,12 @@ You'll need the following components:
105105
- [Mac](https://formulae.brew.sh/formula/redis): `brew install redis`
106106
- [Linux](https://redis.io/docs/getting-started/installation/install-redis-on-linux/): Follow distribution-specific instructions
107107
- [Windows](https://redis.io/docs/getting-started/installation/install-redis-on-windows/): Use WSL2 or Docker
108-
- Save your Redis connection details for later use
108+
- Docker Compose (included in our setup):
109+
- If you're using our Docker Compose setup, Redis is included and configured automatically
110+
- No additional installation is needed
111+
- Save your Redis connection details for later use (not needed if using Docker Compose)
109112

110-
3. **Daytona**:
113+
3. **Daytona**:
111114
- Create an account on [Daytona](https://app.daytona.io/)
112115
- Generate an API key from your account settings
113116
- Go to [Images](https://app.daytona.io/dashboard/images)
@@ -123,6 +126,7 @@ You'll need the following components:
123126
- For enhanced search capabilities, obtain an [Tavily API key](https://tavily.com/)
124127
- For web scraping capabilities, obtain a [Firecrawl API key](https://firecrawl.dev/)
125128

129+
126130
6. **RapidAPI API Key** (Optional):
127131
- To enable API services like LinkedIn, and others, you'll need a RapidAPI key
128132
- Each service requires individual activation in your RapidAPI account:
@@ -201,8 +205,13 @@ cp .env.example .env.local # Create from example if available, or use the follo
201205
```
202206
NEXT_PUBLIC_SUPABASE_URL=your_supabase_url
203207
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
204-
NEXT_PUBLIC_BACKEND_URL="http://localhost:8000/api"
208+
NEXT_PUBLIC_BACKEND_URL="http://localhost:8000/api" # Use this for local development
205209
NEXT_PUBLIC_URL="http://localhost:3000"
210+
```
211+
212+
Note: If you're using Docker Compose, use the container name instead of localhost:
213+
```
214+
NEXT_PUBLIC_BACKEND_URL="http://backend:8000/api" # Use this when running with Docker Compose
206215
```
207216

208217
5. **Install dependencies**:
@@ -230,6 +239,34 @@ cd backend
230239
python api.py
231240
```
232241

242+
5-6. **Docker Compose Alternative**:
243+
244+
Before running with Docker Compose, make sure your environment files are properly configured:
245+
- In `backend/.env`, set all the required environment variables as described above
246+
- For Redis configuration, use `REDIS_HOST=redis` instead of localhost
247+
- The Docker Compose setup will automatically set these Redis environment variables:
248+
```
249+
REDIS_HOST=redis
250+
REDIS_PORT=6379
251+
REDIS_PASSWORD=
252+
REDIS_SSL=False
253+
```
254+
- In `frontend/.env.local`, make sure to set `NEXT_PUBLIC_BACKEND_URL="http://backend:8000/api"` to use the container name
255+
256+
Then run:
257+
```bash
258+
export GITHUB_REPOSITORY="your-github-username/repo-name"
259+
docker compose -f docker-compose.ghcr.yaml up
260+
```
261+
262+
If you're building the images locally instead of using pre-built ones:
263+
```bash
264+
docker compose up
265+
```
266+
267+
The Docker Compose setup includes a Redis service that will be used by the backend automatically.
268+
269+
233270
7. **Access Suna**:
234271
- Open your browser and navigate to `http://localhost:3000`
235272
- Sign up for an account using the Supabase authentication

backend/Dockerfile

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
FROM python:3.11-slim
22

33
WORKDIR /app
4+
RUN pip install --no-cache-dir gunicorn
45

56
COPY requirements.txt .
67
RUN pip install --no-cache-dir -r requirements.txt
7-
RUN pip install --no-cache-dir gunicorn
8+
89

910
# Copy the .env file first
10-
COPY .env .
11+
# COPY .env . # ATTENTION. We shouldn't copy secrets to the image
12+
1113

1214
# Copy the backend code
1315
COPY . .
1416

1517
# Set environment variable
1618
ENV PYTHONPATH=/app
1719

20+
1821
ENV ENV_MODE="production"
1922

2023
# Expose the port the app runs on
2124
EXPOSE 8000
2225

2326
# 24 workers
24-
CMD ["gunicorn", "api:app", "--workers", "24", "--worker-class", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8000", "--timeout", "600", "--graceful-timeout", "300", "--keep-alive", "250", "--max-requests", "0", "--max-requests-jitter", "0", "--forwarded-allow-ips", "*", "--worker-connections", "5000", "--worker-tmp-dir", "/dev/shm", "--preload"]
27+
CMD ["gunicorn", "api:app", "--workers", "24", "--worker-class", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8000", "--timeout", "600", "--graceful-timeout", "300", "--keep-alive", "250", "--max-requests", "0", "--max-requests-jitter", "0", "--forwarded-allow-ips", "*", "--worker-connections", "5000", "--worker-tmp-dir", "/dev/shm", "--preload"]

docker-compose.ghcr.yaml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
version: '3.8'
2+
3+
services:
4+
redis:
5+
image: redis:7-alpine
6+
ports:
7+
- "6379:6379"
8+
volumes:
9+
- redis-data:/data
10+
command: redis-server --save 60 1 --loglevel warning
11+
healthcheck:
12+
test: ["CMD", "redis-cli", "ping"]
13+
interval: 10s
14+
timeout: 5s
15+
retries: 3
16+
17+
backend:
18+
image: ghcr.io/${GITHUB_REPOSITORY}/suna-backend:latest
19+
ports:
20+
- "8000:8000"
21+
volumes:
22+
- ./backend/.env:/app/.env:ro
23+
environment:
24+
- ENV_MODE=local
25+
- REDIS_HOST=redis
26+
- REDIS_PORT=6379
27+
- REDIS_PASSWORD=
28+
- REDIS_SSL=False
29+
depends_on:
30+
redis:
31+
condition: service_healthy
32+
33+
frontend:
34+
image: ghcr.io/${GITHUB_REPOSITORY}/suna-frontend:latest
35+
ports:
36+
- "3000:3000"
37+
volumes:
38+
- ./frontend/.env.local:/app/.env.local:ro
39+
environment:
40+
- NODE_ENV=production
41+
command: ["npm", "run", "dev"]
42+
depends_on:
43+
- backend
44+
45+
volumes:
46+
redis-data:

docker-compose.yaml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
version: '3.8'
2+
3+
services:
4+
redis:
5+
image: redis:7-alpine
6+
ports:
7+
- "6379:6379"
8+
volumes:
9+
- redis-data:/data
10+
command: redis-server --save 60 1 --loglevel warning
11+
healthcheck:
12+
test: ["CMD", "redis-cli", "ping"]
13+
interval: 10s
14+
timeout: 5s
15+
retries: 3
16+
17+
backend:
18+
build:
19+
context: ./backend
20+
dockerfile: Dockerfile
21+
ports:
22+
- "8000:8000"
23+
volumes:
24+
- ./backend/.env:/app/.env:ro
25+
environment:
26+
- ENV_MODE=local
27+
- REDIS_HOST=redis
28+
- REDIS_PORT=6379
29+
- REDIS_PASSWORD=
30+
- REDIS_SSL=False
31+
depends_on:
32+
redis:
33+
condition: service_healthy
34+
35+
frontend:
36+
build:
37+
context: ./frontend
38+
dockerfile: Dockerfile
39+
ports:
40+
- "3000:3000"
41+
volumes:
42+
- ./frontend/.env.local:/app/.env.local:ro
43+
environment:
44+
- NODE_ENV=production
45+
command: ["npm", "run", "start"]
46+
depends_on:
47+
- backend
48+
49+
volumes:
50+
redis-data:

frontend/Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM node:20-slim
2+
3+
WORKDIR /app
4+
5+
# Copy package files first for better layer caching
6+
COPY package*.json ./
7+
RUN npm install
8+
9+
# Copy the frontend code
10+
COPY . .
11+
12+
13+
EXPOSE 3000
14+
15+
# Default command is dev, but can be overridden in docker-compose
16+
CMD ["npm", "run", "dev"]

0 commit comments

Comments
 (0)