Spaces:
Sleeping
Sleeping
j commited on
Commit ·
7b81ce2
1
Parent(s): f04e784
added cadvisor and nginx reverse proxy
Browse files- Dockerfile +59 -15
- README.md +1 -1
- nginx.conf +102 -0
- supervisord.conf +41 -0
Dockerfile
CHANGED
|
@@ -1,51 +1,95 @@
|
|
| 1 |
FROM swaggerapi/swagger-ui:v4.18.2 AS swagger-ui
|
| 2 |
-
FROM
|
| 3 |
|
| 4 |
ARG SERVICE_USER=service
|
| 5 |
ARG SERVICE_UID=1000
|
| 6 |
ARG SERVICE_GID=1000
|
| 7 |
-
|
| 8 |
ENV POETRY_VENV=/app/.venv
|
| 9 |
|
|
|
|
| 10 |
RUN export DEBIAN_FRONTEND=noninteractive \
|
| 11 |
&& apt-get -qq update \
|
| 12 |
&& apt-get -qq install --no-install-recommends \
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
&& rm -rf /var/lib/apt/lists/*
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
RUN groupadd -g $SERVICE_GID $SERVICE_USER || true
|
| 24 |
-
RUN useradd -u $SERVICE_UID -g $SERVICE_GID -d /app -s /
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
|
|
|
| 26 |
COPY --chown=$SERVICE_UID:$SERVICE_GID . /app
|
| 27 |
COPY --chown=$SERVICE_UID:$SERVICE_GID --from=swagger-ui /usr/share/nginx/html/swagger-ui.css /app/swagger-ui-assets/swagger-ui.css
|
| 28 |
COPY --chown=$SERVICE_UID:$SERVICE_GID --from=swagger-ui /usr/share/nginx/html/swagger-ui-bundle.js /app/swagger-ui-assets/swagger-ui-bundle.js
|
| 29 |
-
RUN chown $SERVICE_UID:$SERVICE_GID /app
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
WORKDIR /app
|
| 34 |
|
|
|
|
| 35 |
RUN python3 -m venv $POETRY_VENV \
|
| 36 |
&& $POETRY_VENV/bin/pip install -U pip setuptools \
|
| 37 |
&& $POETRY_VENV/bin/pip install poetry==1.6.1
|
| 38 |
|
| 39 |
ENV PATH="${PATH}:${POETRY_VENV}/bin"
|
| 40 |
|
|
|
|
| 41 |
RUN poetry config virtualenvs.in-project true
|
|
|
|
| 42 |
RUN poetry install && rm -rf /app/.cache/pypoetry
|
|
|
|
| 43 |
|
| 44 |
WORKDIR /app/reascripts/ReaSpeech
|
| 45 |
RUN make publish
|
| 46 |
WORKDIR /app
|
| 47 |
RUN rm -rf reascripts
|
| 48 |
|
| 49 |
-
|
|
|
|
| 50 |
|
| 51 |
-
|
|
|
|
|
|
| 1 |
FROM swaggerapi/swagger-ui:v4.18.2 AS swagger-ui
|
| 2 |
+
FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04
|
| 3 |
|
| 4 |
ARG SERVICE_USER=service
|
| 5 |
ARG SERVICE_UID=1000
|
| 6 |
ARG SERVICE_GID=1000
|
| 7 |
+
ENV PYTHON_VERSION=3.10
|
| 8 |
ENV POETRY_VENV=/app/.venv
|
| 9 |
|
| 10 |
+
# Install necessary tools, cAdvisor, and Nginx
|
| 11 |
RUN export DEBIAN_FRONTEND=noninteractive \
|
| 12 |
&& apt-get -qq update \
|
| 13 |
&& apt-get -qq install --no-install-recommends \
|
| 14 |
+
python${PYTHON_VERSION} \
|
| 15 |
+
python${PYTHON_VERSION}-venv \
|
| 16 |
+
python3-pip \
|
| 17 |
+
lua5.3 \
|
| 18 |
+
lua5.4 \
|
| 19 |
+
lua-check \
|
| 20 |
+
fswatch \
|
| 21 |
+
make \
|
| 22 |
+
ffmpeg \
|
| 23 |
+
redis \
|
| 24 |
+
wget \
|
| 25 |
+
curl \
|
| 26 |
+
supervisor \
|
| 27 |
+
nginx \
|
| 28 |
+
net-tools \
|
| 29 |
&& rm -rf /var/lib/apt/lists/*
|
| 30 |
|
| 31 |
+
# Set up Python symlinks
|
| 32 |
+
RUN ln -s -f /usr/bin/python${PYTHON_VERSION} /usr/bin/python3 && \
|
| 33 |
+
ln -s -f /usr/bin/python${PYTHON_VERSION} /usr/bin/python && \
|
| 34 |
+
ln -s -f /usr/bin/pip3 /usr/bin/pip
|
| 35 |
+
|
| 36 |
+
# Install cAdvisor
|
| 37 |
+
RUN wget https://github.com/google/cadvisor/releases/download/v0.47.2/cadvisor-v0.47.2-linux-amd64 -O /usr/local/bin/cadvisor \
|
| 38 |
+
&& chmod +x /usr/local/bin/cadvisor
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
# Set up service user
|
| 42 |
RUN groupadd -g $SERVICE_GID $SERVICE_USER || true
|
| 43 |
+
RUN useradd -u $SERVICE_UID -g $SERVICE_GID -d /app -s /bin/bash $SERVICE_USER || true
|
| 44 |
+
|
| 45 |
+
# After installing cAdvisor
|
| 46 |
+
RUN chown service:service /usr/local/bin/cadvisor
|
| 47 |
+
|
| 48 |
+
# Set up directories and permissions
|
| 49 |
+
RUN mkdir -p /app /var/log/nginx /var/lib/nginx /run/nginx && \
|
| 50 |
+
chown -R $SERVICE_USER:$SERVICE_USER /app /var/log/nginx /var/lib/nginx /run/nginx /var/log/supervisor
|
| 51 |
|
| 52 |
+
# Copy application files
|
| 53 |
COPY --chown=$SERVICE_UID:$SERVICE_GID . /app
|
| 54 |
COPY --chown=$SERVICE_UID:$SERVICE_GID --from=swagger-ui /usr/share/nginx/html/swagger-ui.css /app/swagger-ui-assets/swagger-ui.css
|
| 55 |
COPY --chown=$SERVICE_UID:$SERVICE_GID --from=swagger-ui /usr/share/nginx/html/swagger-ui-bundle.js /app/swagger-ui-assets/swagger-ui-bundle.js
|
|
|
|
| 56 |
|
| 57 |
+
# Copy Nginx configuration
|
| 58 |
+
COPY nginx.conf /etc/nginx/nginx.conf
|
| 59 |
+
# After installing Nginx
|
| 60 |
+
RUN chown -R service:service /var/log/nginx /var/lib/nginx /run
|
| 61 |
+
RUN chmod -R 755 /var/log/nginx /var/lib/nginx /run
|
| 62 |
+
|
| 63 |
+
# Ensure Nginx can read its configuration
|
| 64 |
+
RUN chmod 644 /etc/nginx/nginx.conf
|
| 65 |
|
| 66 |
+
# Copy supervisord configuration
|
| 67 |
+
COPY --chown=$SERVICE_UID:$SERVICE_GID supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
| 68 |
+
|
| 69 |
+
# Switch to service user
|
| 70 |
+
USER $SERVICE_USER
|
| 71 |
WORKDIR /app
|
| 72 |
|
| 73 |
+
# Set up Python environment
|
| 74 |
RUN python3 -m venv $POETRY_VENV \
|
| 75 |
&& $POETRY_VENV/bin/pip install -U pip setuptools \
|
| 76 |
&& $POETRY_VENV/bin/pip install poetry==1.6.1
|
| 77 |
|
| 78 |
ENV PATH="${PATH}:${POETRY_VENV}/bin"
|
| 79 |
|
| 80 |
+
COPY --chown=$SERVICE_UID:$SERVICE_GID poetry.lock pyproject.toml ./
|
| 81 |
RUN poetry config virtualenvs.in-project true
|
| 82 |
+
RUN poetry install --no-root
|
| 83 |
RUN poetry install && rm -rf /app/.cache/pypoetry
|
| 84 |
+
RUN $POETRY_VENV/bin/pip install --no-cache-dir torch==1.13.1+cu117 -f https://download.pytorch.org/whl/torch
|
| 85 |
|
| 86 |
WORKDIR /app/reascripts/ReaSpeech
|
| 87 |
RUN make publish
|
| 88 |
WORKDIR /app
|
| 89 |
RUN rm -rf reascripts
|
| 90 |
|
| 91 |
+
# Expose single port for Nginx
|
| 92 |
+
EXPOSE 7860
|
| 93 |
|
| 94 |
+
# Use supervisord to manage multiple processes
|
| 95 |
+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
|
README.md
CHANGED
|
@@ -5,5 +5,5 @@ colorFrom: gray
|
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
-
app_port:
|
| 9 |
---
|
|
|
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
+
app_port: 7860
|
| 9 |
---
|
nginx.conf
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
user service service;
|
| 2 |
+
worker_processes auto;
|
| 3 |
+
pid /tmp/nginx.pid;
|
| 4 |
+
|
| 5 |
+
events {
|
| 6 |
+
worker_connections 768;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
http {
|
| 10 |
+
sendfile on;
|
| 11 |
+
tcp_nopush on;
|
| 12 |
+
tcp_nodelay on;
|
| 13 |
+
keepalive_timeout 65;
|
| 14 |
+
types_hash_max_size 2048;
|
| 15 |
+
include /etc/nginx/mime.types;
|
| 16 |
+
default_type application/octet-stream;
|
| 17 |
+
access_log /tmp/nginx_access.log;
|
| 18 |
+
error_log /tmp/nginx_error.log;
|
| 19 |
+
gzip on;
|
| 20 |
+
|
| 21 |
+
server {
|
| 22 |
+
listen 7860;
|
| 23 |
+
server_name localhost;
|
| 24 |
+
|
| 25 |
+
# Force inclusion of port in redirects
|
| 26 |
+
port_in_redirect on;
|
| 27 |
+
absolute_redirect off;
|
| 28 |
+
|
| 29 |
+
# Preserve original scheme (http or https)
|
| 30 |
+
set $origin_scheme $scheme;
|
| 31 |
+
if ($http_x_forwarded_proto = "https") {
|
| 32 |
+
set $origin_scheme "https";
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
# cAdvisor
|
| 36 |
+
location /cadvisor/ {
|
| 37 |
+
proxy_pass http://localhost:8080/;
|
| 38 |
+
proxy_set_header Host $host;
|
| 39 |
+
proxy_set_header X-Real-IP $remote_addr;
|
| 40 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 41 |
+
proxy_set_header X-Forwarded-Proto $origin_scheme;
|
| 42 |
+
proxy_read_timeout 90;
|
| 43 |
+
proxy_http_version 1.1;
|
| 44 |
+
proxy_redirect off;
|
| 45 |
+
|
| 46 |
+
# Rewrite the URL to remove /cadvisor/ before passing to cAdvisor
|
| 47 |
+
rewrite ^/cadvisor/(.*) /$1 break;
|
| 48 |
+
|
| 49 |
+
# Handle cAdvisor's redirect and resource paths
|
| 50 |
+
sub_filter_once off;
|
| 51 |
+
sub_filter 'href="../' 'href="/cadvisor/';
|
| 52 |
+
sub_filter 'src="../' 'src="/cadvisor/';
|
| 53 |
+
sub_filter 'url("../' 'url("/cadvisor/';
|
| 54 |
+
sub_filter 'action="../' 'action="/cadvisor/';
|
| 55 |
+
sub_filter '<a href="/' '<a href="/cadvisor/';
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
# Handle the /containers/ redirect from cAdvisor
|
| 59 |
+
location /containers/ {
|
| 60 |
+
return 301 $origin_scheme://$host:$server_port/cadvisor/containers/;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
# Redirect /cadvisor to /cadvisor/
|
| 64 |
+
location = /cadvisor {
|
| 65 |
+
return 301 $origin_scheme://$host:$server_port/cadvisor/;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
# Root location
|
| 69 |
+
location = / {
|
| 70 |
+
return 302 $origin_scheme://$http_host/reaspeech/;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
# Main application
|
| 74 |
+
location /reaspeech {
|
| 75 |
+
proxy_pass http://localhost:9000;
|
| 76 |
+
proxy_set_header Host $http_host;
|
| 77 |
+
proxy_set_header X-Real-IP $remote_addr;
|
| 78 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 79 |
+
proxy_set_header X-Forwarded-Proto $origin_scheme;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
location /asr {
|
| 83 |
+
proxy_pass http://localhost:9000;
|
| 84 |
+
proxy_set_header Host $http_host;
|
| 85 |
+
proxy_set_header X-Real-IP $remote_addr;
|
| 86 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 87 |
+
proxy_set_header X-Forwarded-Proto $origin_scheme;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
location /jobs {
|
| 91 |
+
proxy_pass http://localhost:9000;
|
| 92 |
+
proxy_set_header Host $http_host;
|
| 93 |
+
proxy_set_header X-Real-IP $remote_addr;
|
| 94 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 95 |
+
proxy_set_header X-Forwarded-Proto $origin_scheme;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
location /static/ {
|
| 99 |
+
alias /app/app/static/;
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
}
|
supervisord.conf
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[unix_http_server]
|
| 2 |
+
file=/tmp/supervisor.sock
|
| 3 |
+
chmod=0700
|
| 4 |
+
chown=service:service
|
| 5 |
+
|
| 6 |
+
[supervisord]
|
| 7 |
+
logfile=/tmp/supervisord.log
|
| 8 |
+
logfile_maxbytes=50MB
|
| 9 |
+
logfile_backups=10
|
| 10 |
+
loglevel=info
|
| 11 |
+
pidfile=/tmp/supervisord.pid
|
| 12 |
+
nodaemon=true
|
| 13 |
+
user=service
|
| 14 |
+
|
| 15 |
+
[rpcinterface:supervisor]
|
| 16 |
+
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
|
| 17 |
+
|
| 18 |
+
[supervisorctl]
|
| 19 |
+
serverurl=unix:///tmp/supervisor.sock
|
| 20 |
+
|
| 21 |
+
[program:app]
|
| 22 |
+
command=/app/.venv/bin/python /app/app/run.py
|
| 23 |
+
user=service
|
| 24 |
+
autostart=true
|
| 25 |
+
autorestart=true
|
| 26 |
+
|
| 27 |
+
[program:cadvisor]
|
| 28 |
+
command=/usr/local/bin/cadvisor --port=8080 --allow_dynamic_housekeeping=false --listen_ip=0.0.0.0
|
| 29 |
+
user=service
|
| 30 |
+
autostart=true
|
| 31 |
+
autorestart=true
|
| 32 |
+
stdout_logfile=/tmp/cadvisor.log
|
| 33 |
+
stderr_logfile=/tmp/cadvisor_err.log
|
| 34 |
+
redirect_stderr=true
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
[program:nginx]
|
| 38 |
+
command=nginx -g 'daemon off;'
|
| 39 |
+
user=service
|
| 40 |
+
autostart=true
|
| 41 |
+
autorestart=true
|