Skip to content

Commit 165805b

Browse files
author
agi
committed
Easy server setup with docker.
1 parent 002d3ef commit 165805b

File tree

5 files changed

+336
-1
lines changed

5 files changed

+336
-1
lines changed

.dockerignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Git
2+
.git
3+
.gitignore
4+
5+
# Documentation
6+
README.md
7+
LICENSE
8+
9+
# Docker files
10+
Dockerfile
11+
.dockerignore
12+
13+
# IDE files
14+
.vscode
15+
.idea
16+
17+
# OS files
18+
.DS_Store
19+
Thumbs.db
20+
21+
# Temporary files
22+
*.tmp
23+
*.log
24+
25+
# Test files
26+
*_test.go
27+
test/
28+
tests/
29+
30+
# Assets that are already copied during build
31+
assets/demos/

DOCKER_README.md

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# Docker Setup for Useless-Agent
2+
3+
This document explains how to build and run the useless-agent application using Docker.
4+
5+
## Prerequisites
6+
7+
- Docker installed on your system
8+
- Docker Compose (optional, but recommended)
9+
- An API key for your preferred LLM provider (DeepSeek or Z.AI)
10+
11+
## Building the Docker Image
12+
13+
### Option 1: Using Docker Compose (Recommended)
14+
15+
1. Update the `docker-compose.yml` file with your API key:
16+
```yaml
17+
environment:
18+
- API_KEY=your_actual_api_key_here
19+
```
20+
21+
2. Build and run the container:
22+
```bash
23+
docker compose up --build
24+
```
25+
26+
### Option 2: Using Docker directly
27+
28+
1. Build the image:
29+
```bash
30+
docker build -t useless-agent .
31+
```
32+
33+
2. Run the container:
34+
```bash
35+
docker run -d \
36+
--name useless-agent-server \
37+
-p 8080:8080 \
38+
-e PROVIDER=deepseek \
39+
-e BASE_URL=https://api.deepseek.com/v1 \
40+
-e API_KEY=your_actual_api_key_here \
41+
-e MODEL=deepseek-chat \
42+
-e IP=0.0.0.0 \
43+
-e PORT=8080 \
44+
-e DISPLAY=:1 \
45+
useless-agent
46+
```
47+
48+
## Configuration
49+
50+
The container can be configured using the following environment variables:
51+
52+
### LLM Provider Configuration
53+
54+
- `PROVIDER`: The LLM provider to use (`deepseek` or `zai`)
55+
- `BASE_URL`: The API base URL for your provider
56+
- `API_KEY`: Your API key for the provider
57+
- `MODEL`: The model to use (e.g., `deepseek-chat`, `glm-4.5-air`)
58+
59+
### Server Configuration
60+
61+
- `IP`: The IP address to bind to (default: `0.0.0.0`)
62+
- `PORT`: The port to listen on (default: `8080`)
63+
- `DISPLAY`: The X11 display (default: `:1`)
64+
65+
## Accessing the Application
66+
67+
### Finding the Container IP
68+
69+
To get the IP address of the running container:
70+
71+
```bash
72+
# Method 1: Using docker inspect
73+
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' useless-agent-server
74+
75+
# Method 2: Using docker exec
76+
docker exec useless-agent-server hostname -I
77+
78+
# Method 3: If running on Docker Desktop (Mac/Windows), use localhost
79+
# The container is accessible via localhost:8080
80+
```
81+
82+
### Connecting to the Application
83+
84+
1. Once the container is running, open `main.html` in your web browser
85+
2. Enter the IP address obtained from the commands above
86+
- If running Docker on Linux: Use the container IP from the commands above
87+
- If running Docker Desktop on Mac/Windows: Use `localhost` or `127.0.0.1`
88+
3. Click "Connect" to establish a connection
89+
4. Start giving tasks to the agent through the LLM Chat interface
90+
91+
## Example Usage
92+
93+
### Using DeepSeek
94+
95+
```bash
96+
docker run -d \
97+
--name useless-agent-server \
98+
-p 8080:8080 \
99+
-e PROVIDER=deepseek \
100+
-e BASE_URL=https://api.deepseek.com/v1 \
101+
-e API_KEY=your_deepseek_api_key \
102+
-e MODEL=deepseek-chat \
103+
useless-agent
104+
```
105+
106+
### Using Z.AI
107+
108+
```bash
109+
docker run -d \
110+
--name useless-agent-server \
111+
-p 8080:8080 \
112+
-e PROVIDER=zai \
113+
-e BASE_URL=https://api.z.ai/api/paas/v4 \
114+
-e API_KEY=your_zai_api_key \
115+
-e MODEL=glm-4.5-air \
116+
useless-agent
117+
```
118+
119+
## Troubleshooting
120+
121+
### Viewing Logs
122+
123+
To view the logs of the running container:
124+
125+
```bash
126+
docker logs useless-agent-server
127+
```
128+
129+
Or with Docker Compose:
130+
131+
```bash
132+
docker compose logs -f
133+
```
134+
135+
### Stopping the Container
136+
137+
To stop the container:
138+
139+
```bash
140+
docker stop useless-agent-server
141+
```
142+
143+
Or with Docker Compose:
144+
145+
```bash
146+
docker compose down
147+
```
148+
149+
### Rebuilding the Image
150+
151+
If you make changes to the source code, you'll need to rebuild the image:
152+
153+
```bash
154+
docker compose build --no-cache
155+
```
156+
157+
Or with Docker:
158+
159+
```bash
160+
docker build --no-cache -t useless-agent .
161+
```
162+
163+
## Notes
164+
165+
- The container includes Xvfb (X Virtual Framebuffer) and XFCE4 desktop environment
166+
- Tesseract OCR is installed for text recognition capabilities
167+
- The application runs on port 8080 inside the container
168+
- The Go binary is compiled during the build process and installed to `/app/useless-agent`
169+
- The container uses a simple startup script to manage Xvfb and XFCE processes
170+
- No special privileges are required to run this container

Dockerfile

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
FROM ubuntu:22.04
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
ENV DISPLAY=:1
5+
6+
RUN apt-get update && apt-get install -y \
7+
curl \
8+
wget \
9+
gnupg \
10+
software-properties-common \
11+
ca-certificates \
12+
build-essential \
13+
git \
14+
&& rm -rf /var/lib/apt/lists/*
15+
16+
# Install Go 1.25.2 (matching the go.mod requirement)
17+
RUN wget -O go.tar.gz https://go.dev/dl/go1.25.2.linux-amd64.tar.gz \
18+
&& tar -C /usr/local -xzf go.tar.gz \
19+
&& rm go.tar.gz
20+
21+
# Set Go environment variables
22+
ENV PATH=$PATH:/usr/local/go/bin
23+
ENV GOPATH=/go
24+
ENV PATH=$PATH:$GOPATH/bin
25+
26+
# Add PPA for tesseract-ocr5 and install X11, XFCE, and other dependencies
27+
RUN apt-get update && apt-get install -y \
28+
software-properties-common \
29+
&& add-apt-repository -y ppa:alex-p/tesseract-ocr5 \
30+
&& apt-get update \
31+
&& apt-get install -y \
32+
xvfb \
33+
x11-utils \
34+
x11-xserver-utils \
35+
xfce4 \
36+
xfce4-terminal \
37+
tesseract-ocr \
38+
tesseract-ocr-eng \
39+
libtesseract5 \
40+
libleptonica-dev \
41+
libtesseract-dev \
42+
libx11-dev \
43+
libxrandr-dev \
44+
libxtst-dev \
45+
libxi-dev \
46+
&& rm -rf /var/lib/apt/lists/*
47+
48+
# Remove xfce4-screensaver
49+
RUN apt-get remove -y xfce4-screensaver && apt-get autoremove -y
50+
51+
# Create application directory
52+
WORKDIR /app
53+
54+
# Copy the Go module files
55+
COPY go.mod go.sum ./
56+
57+
# Copy the entire source code
58+
COPY . .
59+
60+
# Build the Go application
61+
RUN go mod download
62+
RUN go build -o useless-agent .
63+
64+
# Create a startup script
65+
RUN echo '#!/bin/bash\n\
66+
# Start Xvfb in background\n\
67+
Xvfb :1 -screen 0 1920x1080x24 &\n\
68+
XVFB_PID=$!\n\
69+
\n\
70+
# Wait for Xvfb to start\n\
71+
sleep 3\n\
72+
\n\
73+
# Start XFCE in background\n\
74+
DISPLAY=:1 startxfce4 &\n\
75+
XFCE_PID=$!\n\
76+
\n\
77+
# Wait for XFCE to start\n\
78+
sleep 5\n\
79+
\n\
80+
# Function to cleanup background processes\n\
81+
cleanup() {\n\
82+
echo "Cleaning up..."\n\
83+
kill $XVFB_PID 2>/dev/null\n\
84+
kill $XFCE_PID 2>/dev/null\n\
85+
exit 0\n\
86+
}\n\
87+
\n\
88+
# Set trap to cleanup on exit\n\
89+
trap cleanup SIGTERM SIGINT\n\
90+
\n\
91+
# Start the useless-agent application\n\
92+
./useless-agent --provider=${PROVIDER:-deepseek} --base-url="${BASE_URL:-https://api.deepseek.com/v1}" --key="${API_KEY}" --model="${MODEL:-deepseek-chat}" --display=:1 --ip=${IP:-0.0.0.0} --port=${PORT:-8080}' > /app/start.sh && \
93+
chmod +x /app/start.sh
94+
95+
# Expose the application port
96+
EXPOSE 8080
97+
98+
# Set the entrypoint
99+
ENTRYPOINT ["/app/start.sh"]

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,36 @@ https://github.com/user-attachments/assets/370bdd7e-0955-4b1e-8e81-8ee3eb913e90
9595

9696

9797
### How to build:
98+
99+
**The easiest way:**
100+
```bash
101+
docker compose up --build
102+
```
103+
104+
For more information, see [DOCKER_README.md](DOCKER_README.md).
105+
106+
> [!WARNING]
107+
> Docker is not a sufficient level of isolation and it is risky.
108+
109+
**or manually:**
98110
* `git clone`
99111
* `cd useless-agent`
100112
* `go build`
101113

102114
### How to prepare headless vm:
103115
Scripts - "assets/scripts"
104116
```bash
105-
sudo apt update && sudo apt install -y \
117+
sudo apt update && sudo add-apt-repository ppa:alex-p/tesseract-ocr5 && sudo apt install -y \
106118
xfce4 xvfb tesseract-ocr-eng tesseract-ocr libtesseract5 libleptonica-dev libtesseract-dev
107119
sudo apt remove -y xfce4-screensaver
108120
sudo systemctl enable --now xvfb.service xfce4.service
109121
```
110122

123+
### How to establish a secure tunnel between client and remote server:
124+
```bash
125+
ssh -p 22 -fN -o IPQoS=ef USERNAME@REMOTE-HOST-PUBLIC-IP -L 127.0.0.1:8080:127.0.0.1:8080
126+
```
127+
111128
### How to use:
112129
`copy executable to the target machine`
113130

docker-compose.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
services:
2+
useless-agent:
3+
build: .
4+
container_name: useless-agent-server
5+
ports:
6+
- "8080:8080"
7+
environment:
8+
# LLM Provider Configuration
9+
- PROVIDER=deepseek # or zai
10+
- BASE_URL=https://api.deepseek.com/v1 # or https://api.z.ai/api/paas/v4
11+
- API_KEY=YOUR_API_KEY_HERE # Replace with your actual API key
12+
- MODEL=deepseek-chat # or glm-4.5-air, etc.
13+
14+
# Server Configuration
15+
- IP=0.0.0.0 # Listen on all interfaces
16+
- PORT=8080
17+
- DISPLAY=:1 # X11 display
18+
restart: unless-stopped

0 commit comments

Comments
 (0)