File size: 1,594 Bytes
40665b6
04fb59a
 
ec1f352
04fb59a
ec1f352
 
 
 
 
 
 
 
 
 
 
 
 
 
eb371f4
 
ec1f352
 
eb371f4
 
662cf6b
eb371f4
 
 
 
 
 
 
662cf6b
eb371f4
 
 
 
 
 
04fb59a
 
662cf6b
 
 
04fb59a
 
ec1f352
eb371f4
40665b6
74ee41d
04fb59a
40665b6
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
# Stage 1: Build Python dependencies
FROM python:3.11-slim-bullseye AS builder
LABEL maintainer="YourName"

# Create and switch to a non-root user
RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"

# Set working directory
WORKDIR /app

# Copy and install Python dependencies
COPY --chown=user ./requirements.txt requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements.txt || echo "No requirements.txt found, skipping."

# Copy application files
COPY --chown=user . /app

# Stage 2: Install the latest Node.js & npm via nvm
FROM python:3.11-slim-bullseye AS final
WORKDIR /app

# Install required dependencies
RUN apt-get update && apt-get install -y curl bash git && rm -rf /var/lib/apt/lists/*

# Install nvm and the latest Node.js
RUN curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash && \
    export NVM_DIR="$HOME/.nvm" && \
    [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" && \
    nvm install node && \
    nvm use node && \
    node -v && npm -v

# Ensure Node.js is available in PATH
ENV NVM_DIR="/root/.nvm"
ENV PATH="/root/.nvm/versions/node/$(ls /root/.nvm/versions/node)/bin:$PATH"

# Copy application files
COPY --from=builder /app /app
WORKDIR /app

# Ensure Uvicorn is installed
RUN pip install --no-cache-dir uvicorn

# Expose necessary ports
EXPOSE 3000 7860

# Verify Node.js and Python environments before running
RUN node -v && npm -v && python --version && pip --version && ls -l /app

# Run both services
CMD ["/bin/bash", "-c", "node server.js & uvicorn app:app --host 0.0.0.0 --port 7860"]