File size: 2,292 Bytes
125f18f
 
a830538
125f18f
 
 
 
fd0ee34
 
 
 
 
 
 
 
 
 
125f18f
a830538
db88c10
 
 
a830538
db88c10
 
 
 
 
a830538
8efa104
 
 
db88c10
 
a830538
db88c10
 
a830538
db88c10
 
a830538
db88c10
 
 
a830538
 
db88c10
a830538
 
 
db88c10
 
b419751
db88c10
 
b419751
 
8efa104
b419751
 
db88c10
 
 
 
 
 
b419751
 
 
db88c10
b419751
db88c10
b419751
 
db88c10
 
b419751
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Start with Ubuntu 24.04 (Noble)
FROM ubuntu:noble

# Avoid prompts from apt
ENV DEBIAN_FRONTEND=noninteractive

# Install essential packages and tools
RUN apt-get update && apt-get install -y curl wget git nginx

# Free advertising :)
LABEL maintainer="sam@defact.org" \
      description="Free multimodal inference api running in node via docker and HF serverless inference" \
      usage="https://huggingface.co/spaces/DeFactOfficial/MMAPI"

# Switch to root for system installations
USER root


# Set home to the user's home directory
ENV HOME=/home/root \
	  PATH=/home/root/.local/bin:$PATH  \
      STATIC_SITE_ROOT=$HOME/code/public

# Install Node.js 20 (using n instead of nodesource for better HF compatibility)
RUN curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n \
    && bash n 20 \
    && rm n \
    && npm install -g npm@latest

# pm2 is awesome... lets you run node.js scripts as services with zero configuration
RUN npm install pm2 -g

# Create working directory that matches HF Spaces expectations
WORKDIR $HOME/code

# Clone your repository (replace with your actual repo URL)
#RUN git clone https://your-repo-url.git .
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
ADD . $HOME/code
COPY --chown=root . $HOME/code

# INSTALL NPM PACKAGES
# INSTALL FFMPEG TOOLING
# FIRE UP API
# Loading Dependencies
RUN npm install
RUN $HOME/code/ffmpeg_install.sh
# Expose application's default port
EXPOSE 7860

# Configure nginx
RUN rm -f /etc/nginx/sites-enabled/default
COPY $HOME/code/conf/nginx.conf /etc/nginx/sites-available/reverse-proxy.conf
RUN ln -s /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/

# Stop all old instances of the api service
RUN pm2 delete all

# Start nginx in foreground
RUN nginx -g 'daemon off;'

# Start all services in background with logging
#cd /code/service1 && ./run.sh > /var/log/service1.log 2>&1 &
#cd /code/service2 && ./run.sh > /var/log/service2.log 2>&1 &
#cd /code/service3 && ./run.sh > /var/log/service3.log 2>&1 &

# Start the API
ENTRYPOINT ["pm2", "start", "./api.js"]

# Wait for services to start
RUN sleep 5

# Display the status of the service, make sure it started
RUN pm2 list

# Tail the logs in background
#tail -f /var/log/*.log &