Skip to content

Commit 6c0e303

Browse files
author
Yemin Shi
committed
feat: add docker support
1 parent 31de546 commit 6c0e303

File tree

5 files changed

+122
-0
lines changed

5 files changed

+122
-0
lines changed

docker/Dockerfile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM tiangolo/uwsgi-nginx:python3.10
2+
3+
ENV LISTEN_PORT 7860
4+
ENV USE_HTML_ROOT /app/autoagents/frontend/app
5+
6+
EXPOSE 7860
7+
8+
RUN chown -R 1000 /app /etc/nginx /usr/local/lib/python3.10/site-packages /usr/local/bin /var/log /var/run /etc/supervisor/conf.d /run /tmp /etc/uwsgi /var/cache /entrypoint.sh
9+
10+
# Set up a new user named "user" with user ID 1000
11+
RUN useradd -m -u 1000 user
12+
13+
# Switch to the "user" user
14+
USER user
15+
16+
# Set home to the user's home directory
17+
ENV HOME=/home/user \
18+
PATH=/home/user/.local/bin:$PATH
19+
20+
# Install Python dependencies and install autoagents
21+
RUN git clone https://github.com/LinkSoul-AI/AutoAgents autoagents && \
22+
cd autoagents && \
23+
pip install -r requirements.txt --user && \
24+
python setup.py install && \
25+
pip cache purge && \
26+
cp docker/prestart.sh /app/prestart.sh && \
27+
cp docker/entrypoint.sh /entrypoint.sh && \
28+
chmod +x /entrypoint.sh && \
29+
sed -i 's/nodaemon=true/nodaemon=true\nuser=user/g' /etc/supervisor/conf.d/supervisord.conf && \
30+
sed -i 's/nginx/user/g' /etc/uwsgi/uwsgi.ini && \
31+
sed -i 's/nginx;/user;/g' /etc/nginx/nginx.conf

docker/build.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
IMAGE="linksoul.ai/autoagents"
4+
VERSION=1.0
5+
6+
docker build --no-cache -f docker/Dockerfile -t "${IMAGE}:${VERSION}" .

docker/entrypoint.sh

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env sh
2+
set -e
3+
4+
# Get the maximum upload file size for Nginx, default to 0: unlimited
5+
USE_NGINX_MAX_UPLOAD=${NGINX_MAX_UPLOAD:-0}
6+
7+
# Get the number of workers for Nginx, default to 1
8+
USE_NGINX_WORKER_PROCESSES=${NGINX_WORKER_PROCESSES:-1}
9+
10+
# Set the max number of connections per worker for Nginx, if requested
11+
# Cannot exceed worker_rlimit_nofile, see NGINX_WORKER_OPEN_FILES below
12+
NGINX_WORKER_CONNECTIONS=${NGINX_WORKER_CONNECTIONS:-1024}
13+
14+
# Get the listen port for Nginx, default to 80
15+
USE_LISTEN_PORT=${LISTEN_PORT:-80}
16+
17+
# Get html root path
18+
USE_HTML_ROOT=${USE_HTML_ROOT:-/html}
19+
20+
if [ -f /app/nginx.conf ]; then
21+
cp /app/nginx.conf /etc/nginx/nginx.conf
22+
else
23+
content='user nginx;\n'
24+
# Set the number of worker processes in Nginx
25+
content=$content"worker_processes ${USE_NGINX_WORKER_PROCESSES};\n"
26+
content=$content'error_log /var/log/nginx/error.log warn;\n'
27+
content=$content'pid /var/run/nginx.pid;\n'
28+
content=$content'events {\n'
29+
content=$content" worker_connections ${NGINX_WORKER_CONNECTIONS};\n"
30+
content=$content'}\n'
31+
content=$content'http {\n'
32+
content=$content' include /etc/nginx/mime.types;\n'
33+
content=$content' default_type application/octet-stream;\n'
34+
content=$content' log_format main '"'\$remote_addr - \$remote_user [\$time_local] \"\$request\" '\n"
35+
content=$content' '"'\$status \$body_bytes_sent \"\$http_referer\" '\n"
36+
content=$content' '"'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';\n"
37+
content=$content' access_log /var/log/nginx/access.log main;\n'
38+
content=$content' sendfile on;\n'
39+
content=$content' keepalive_timeout 65;\n'
40+
content=$content' include /etc/nginx/conf.d/*.conf;\n'
41+
content=$content'}\n'
42+
content=$content'daemon off;\n'
43+
# Set the max number of open file descriptors for Nginx workers, if requested
44+
if [ -n "${NGINX_WORKER_OPEN_FILES}" ] ; then
45+
content=$content"worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};\n"
46+
fi
47+
# Save generated /etc/nginx/nginx.conf
48+
printf "$content" > /etc/nginx/nginx.conf
49+
50+
content_server='server {\n'
51+
content_server=$content_server" listen ${USE_LISTEN_PORT} default_server;\n"
52+
content_server=$content_server" listen [::]:${USE_LISTEN_PORT} default_server;\n"
53+
content_server=$content_server" server_name _;\n"
54+
content_server=$content_server" root ${USE_HTML_ROOT};\n"
55+
content_server=$content_server" index index.html index.htm index.nginx-debian.html;\n"
56+
content_server=$content_server' location ^~ /api {\n'
57+
content_server=$content_server' proxy_pass http://127.0.0.1:9000;\n'
58+
content_server=$content_server' proxy_set_header Upgrade $http_upgrade;\n'
59+
content_server=$content_server' proxy_set_header Connection "Upgrade";\n'
60+
content_server=$content_server' proxy_http_version 1.1;\n'
61+
content_server=$content_server' }\n'
62+
content_server=$content_server'}\n'
63+
# Save generated server /etc/nginx/conf.d/nginx.conf
64+
printf "$content_server" > /etc/nginx/conf.d/nginx.conf
65+
66+
# Generate Nginx config for maximum upload file size
67+
printf "client_max_body_size $USE_NGINX_MAX_UPLOAD;\n" > /etc/nginx/conf.d/upload.conf
68+
69+
# Remove default Nginx config from Alpine
70+
printf "" > /etc/nginx/conf.d/default.conf
71+
fi
72+
73+
# For Alpine:
74+
# Explicitly add installed Python packages and uWSGI Python packages to PYTHONPATH
75+
# Otherwise uWSGI can't import Flask
76+
if [ -n "$ALPINEPYTHON" ] ; then
77+
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/$ALPINEPYTHON/site-packages:/usr/lib/$ALPINEPYTHON/site-packages
78+
fi
79+
exec "$@"

docker/prestart.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
cd /app/autoagents
4+
python main.py --mode service &
5+
sleep 2

docker/start_docker.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker run -it --rm -p 7860:7860 linksoul.ai/autoagents:1.0

0 commit comments

Comments
 (0)