ReaSpeech-Cloud / Dockerfile
j
added cadvisor and nginx reverse proxy
7b81ce2
raw
history blame
3.16 kB
FROM swaggerapi/swagger-ui:v4.18.2 AS swagger-ui
FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04
ARG SERVICE_USER=service
ARG SERVICE_UID=1000
ARG SERVICE_GID=1000
ENV PYTHON_VERSION=3.10
ENV POETRY_VENV=/app/.venv
# Install necessary tools, cAdvisor, and Nginx
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get -qq update \
&& apt-get -qq install --no-install-recommends \
python${PYTHON_VERSION} \
python${PYTHON_VERSION}-venv \
python3-pip \
lua5.3 \
lua5.4 \
lua-check \
fswatch \
make \
ffmpeg \
redis \
wget \
curl \
supervisor \
nginx \
net-tools \
&& rm -rf /var/lib/apt/lists/*
# Set up Python symlinks
RUN ln -s -f /usr/bin/python${PYTHON_VERSION} /usr/bin/python3 && \
ln -s -f /usr/bin/python${PYTHON_VERSION} /usr/bin/python && \
ln -s -f /usr/bin/pip3 /usr/bin/pip
# Install cAdvisor
RUN wget https://github.com/google/cadvisor/releases/download/v0.47.2/cadvisor-v0.47.2-linux-amd64 -O /usr/local/bin/cadvisor \
&& chmod +x /usr/local/bin/cadvisor
# Set up service user
RUN groupadd -g $SERVICE_GID $SERVICE_USER || true
RUN useradd -u $SERVICE_UID -g $SERVICE_GID -d /app -s /bin/bash $SERVICE_USER || true
# After installing cAdvisor
RUN chown service:service /usr/local/bin/cadvisor
# Set up directories and permissions
RUN mkdir -p /app /var/log/nginx /var/lib/nginx /run/nginx && \
chown -R $SERVICE_USER:$SERVICE_USER /app /var/log/nginx /var/lib/nginx /run/nginx /var/log/supervisor
# Copy application files
COPY --chown=$SERVICE_UID:$SERVICE_GID . /app
COPY --chown=$SERVICE_UID:$SERVICE_GID --from=swagger-ui /usr/share/nginx/html/swagger-ui.css /app/swagger-ui-assets/swagger-ui.css
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
# Copy Nginx configuration
COPY nginx.conf /etc/nginx/nginx.conf
# After installing Nginx
RUN chown -R service:service /var/log/nginx /var/lib/nginx /run
RUN chmod -R 755 /var/log/nginx /var/lib/nginx /run
# Ensure Nginx can read its configuration
RUN chmod 644 /etc/nginx/nginx.conf
# Copy supervisord configuration
COPY --chown=$SERVICE_UID:$SERVICE_GID supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# Switch to service user
USER $SERVICE_USER
WORKDIR /app
# Set up Python environment
RUN python3 -m venv $POETRY_VENV \
&& $POETRY_VENV/bin/pip install -U pip setuptools \
&& $POETRY_VENV/bin/pip install poetry==1.6.1
ENV PATH="${PATH}:${POETRY_VENV}/bin"
COPY --chown=$SERVICE_UID:$SERVICE_GID poetry.lock pyproject.toml ./
RUN poetry config virtualenvs.in-project true
RUN poetry install --no-root
RUN poetry install && rm -rf /app/.cache/pypoetry
RUN $POETRY_VENV/bin/pip install --no-cache-dir torch==1.13.1+cu117 -f https://download.pytorch.org/whl/torch
WORKDIR /app/reascripts/ReaSpeech
RUN make publish
WORKDIR /app
RUN rm -rf reascripts
# Expose single port for Nginx
EXPOSE 7860
# Use supervisord to manage multiple processes
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]