xarical's picture
Move node_modules installation in Dockerfile and add npx playwright install (fixes 8544a132013d00741e8d63c99d48e6da42236f88)
d491960
# Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
# you will also find guides on how best to write your Dockerfile
FROM python:3
# Add new user 'user' (non-root)
RUN useradd -m -u 1000 user
# Set working dir to app
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
RUN mkdir $HOME/app
WORKDIR $HOME/app
# Switch to root
USER root
# Install nginx, Node.js, and packages.txt
COPY --chown=root packages.txt packages.txt
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get -y update && apt-get -y install nginx && apt-get install -y nodejs && \
xargs apt-get -y install < packages.txt && \
npm install -g npm
# Install package-lock.json
COPY --chown=user package.json package-lock.json ./
RUN npm install
RUN npx playwright install
RUN chown -R user:user "$HOME/app/node_modules"
# Give app permissions to 'user' (non-root)
RUN chown user:user .
# Give nginx permissions to 'user' (non-root)
# See https://www.rockyourcode.com/run-docker-nginx-as-non-root-user/
RUN mkdir -p /var/cache/nginx \
/var/log/nginx \
/var/lib/nginx
RUN touch /var/run/nginx.pid
RUN chown -R user:user /var/cache/nginx \
/var/log/nginx \
/var/lib/nginx \
/var/run/nginx.pid
# Switch to 'user' (non-root)
USER user
# Install requirements.txt
COPY --chown=user requirements.txt requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements.txt
# Copy nginx configuration
COPY --chown=user nginx.conf /etc/nginx/sites-available/default
# Copy app
COPY --chown=user . .
# Run
CMD ["bash", "run.sh"]