AstraOS commited on
Commit
a59ab77
·
verified ·
1 Parent(s): 7684b00

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +24 -38
Dockerfile CHANGED
@@ -1,51 +1,37 @@
1
- # Stage 1: Build Python dependencies
2
- FROM python:3.11-slim-bullseye AS builder
3
- LABEL maintainer="YourName"
4
-
5
- # Create and switch to a non-root user
6
- RUN useradd -m -u 1000 user
7
- USER user
8
- ENV PATH="/home/user/.local/bin:$PATH"
9
-
10
- # Set working directory
11
- WORKDIR /app
12
-
13
- # Copy and install Python dependencies
14
- COPY --chown=user ./requirements.txt requirements.txt
15
- RUN pip install --no-cache-dir --upgrade -r requirements.txt || echo "No requirements.txt found, skipping."
16
-
17
- # Copy application files
18
- COPY --chown=user . /app
19
-
20
- # Stage 2: Install the latest Node.js & npm via nvm
21
  FROM python:3.11-slim-bullseye AS final
22
 
23
- # Install required dependencies
 
 
 
24
  RUN apt-get update && apt-get install -y curl bash git && rm -rf /var/lib/apt/lists/*
25
 
 
 
 
 
26
  # Install NVM and Node.js
27
- RUN curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash && \
28
- export NVM_DIR="/root/.nvm" && \
29
- [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" && \
 
 
30
  nvm install node && \
31
  nvm use node
32
 
33
- # Ensure Node.js is accessible in $PATH
34
- ENV NVM_DIR="/root/.nvm"
35
- ENV PATH="/root/.nvm/versions/node/$(ls /root/.nvm/versions/node)/bin:$PATH"
36
-
37
- # Copy application files
38
- COPY --from=builder /app /app
39
- WORKDIR /app
40
 
41
- # Ensure Uvicorn is installed
42
- RUN pip install --no-cache-dir uvicorn
43
 
44
- # Debugging: Verify installation
45
- RUN node -v && npm -v && python --version && pip --version && ls -l /app
 
46
 
47
- # Expose necessary ports
48
  EXPOSE 3000 7860
49
 
50
- # Run both services
51
- CMD ["/bin/bash", "-c", "node server.js & uvicorn app:app --host 0.0.0.0 --port 7860"]
 
1
+ # Base image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  FROM python:3.11-slim-bullseye AS final
3
 
4
+ # Use bash as default shell
5
+ SHELL ["/bin/bash", "-o", "pipefail", "-c"]
6
+
7
+ # Install dependencies
8
  RUN apt-get update && apt-get install -y curl bash git && rm -rf /var/lib/apt/lists/*
9
 
10
+ # Set environment variables for NVM
11
+ ENV NVM_DIR="/home/user/.nvm"
12
+ ENV PATH="${NVM_DIR}/versions/node/$(ls ${NVM_DIR}/versions/node)/bin:$PATH"
13
+
14
  # Install NVM and Node.js
15
+ RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash && \
16
+ echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrc && \
17
+ echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"' >> ~/.bashrc && \
18
+ echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"' >> ~/.bashrc && \
19
+ source ~/.bashrc && \
20
  nvm install node && \
21
  nvm use node
22
 
23
+ # Ensure Node.js is accessible globally
24
+ RUN bash -c "source ~/.bashrc && node -v && npm -v"
 
 
 
 
 
25
 
26
+ # Verify installation
27
+ RUN node -v && npm -v && python --version && pip --version
28
 
29
+ # Set working directory
30
+ WORKDIR /app
31
+ COPY . /app
32
 
33
+ # Expose ports
34
  EXPOSE 3000 7860
35
 
36
+ # Run both Node.js & Python servers
37
+ CMD ["/bin/bash", "-c", "source ~/.bashrc && node server.js & uvicorn app:app --host 0.0.0.0 --port 7860"]