shoudlere commited on
Commit
9f78881
Β·
verified Β·
1 Parent(s): 35022df

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +21 -100
Dockerfile CHANGED
@@ -1,106 +1,27 @@
1
- # Multi-stage build for AnyCoder Docker Space
2
 
3
- # Stage 1: Build frontend
4
- FROM node:18-slim AS frontend-builder
5
 
6
- WORKDIR /build
7
 
8
- # Copy frontend package files
9
- COPY frontend/package*.json ./
10
- RUN npm ci
11
 
12
- # Copy all frontend source files and configs
13
- COPY frontend/src ./src
14
- COPY frontend/public ./public
15
- COPY frontend/next.config.js ./
16
- COPY frontend/tsconfig.json ./
17
- COPY frontend/tailwind.config.js ./
18
- COPY frontend/postcss.config.js ./
19
- # Note: next-env.d.ts is auto-generated by Next.js, not needed for build
20
 
21
- # Build frontend
22
- RUN npm run build
23
-
24
- # Stage 2: Production image
25
- FROM python:3.11-slim
26
-
27
- # Install system dependencies as root (git for pip, nodejs for frontend)
28
- RUN apt-get update && \
29
- apt-get install -y --no-install-recommends \
30
- git \
31
- nodejs \
32
- npm \
33
- && rm -rf /var/lib/apt/lists/*
34
-
35
- # Set up a new user named "user" with user ID 1000
36
- RUN useradd -m -u 1000 user
37
-
38
- # Switch to the "user" user
39
- USER user
40
-
41
- # Set home to the user's home directory
42
- ENV HOME=/home/user \
43
- PATH=/home/user/.local/bin:$PATH \
44
- PYTHONUNBUFFERED=1
45
-
46
- # Set the working directory to the user's home directory
47
- WORKDIR $HOME/app
48
-
49
- # Copy Python requirements and install dependencies
50
- COPY --chown=user:user requirements.txt .
51
- RUN pip install --no-cache-dir --upgrade pip && \
52
- pip install --no-cache-dir -r requirements.txt
53
-
54
- # Copy application code
55
- COPY --chown=user:user anycoder_app/ ./anycoder_app/
56
- COPY --chown=user:user backend_api.py .
57
- COPY --chown=user:user backend_models.py .
58
- COPY --chown=user:user backend_docs_manager.py .
59
- COPY --chown=user:user backend_prompts.py .
60
- COPY --chown=user:user backend_parsers.py .
61
- COPY --chown=user:user backend_deploy.py .
62
- COPY --chown=user:user project_importer.py .
63
- COPY --chown=user:user app.py .
64
-
65
- # Copy built frontend from builder stage
66
- COPY --chown=user:user --from=frontend-builder /build/.next ./frontend/.next
67
- COPY --chown=user:user --from=frontend-builder /build/public ./frontend/public
68
- COPY --chown=user:user --from=frontend-builder /build/package*.json ./frontend/
69
- COPY --chown=user:user --from=frontend-builder /build/next.config.js ./frontend/
70
- COPY --chown=user:user --from=frontend-builder /build/node_modules ./frontend/node_modules
71
-
72
- # Set environment variables for the application
73
- # BACKEND_HOST is used by Next.js server for proxying
74
- # Do NOT set NEXT_PUBLIC_API_URL - let frontend use relative URLs
75
- ENV BACKEND_HOST=http://localhost:8000 \
76
- PORT=7860
77
-
78
- # Create startup script that runs both services
79
- # Backend on 8000, Frontend on 7860 (exposed port)
80
- RUN echo '#!/bin/bash\n\
81
- set -e\n\
82
- \n\
83
- echo "πŸš€ Starting AnyCoder Docker Space..."\n\
84
- \n\
85
- # Start backend on port 8000 in background\n\
86
- echo "πŸ“‘ Starting FastAPI backend on port 8000..."\n\
87
- cd $HOME/app\n\
88
- uvicorn backend_api:app --host 0.0.0.0 --port 8000 &\n\
89
- BACKEND_PID=$!\n\
90
- \n\
91
- # Wait for backend to be ready\n\
92
- echo "⏳ Waiting for backend to start..."\n\
93
- sleep 5\n\
94
- \n\
95
- # Start frontend on port 7860 (HF Spaces exposed port)\n\
96
- echo "🎨 Starting Next.js frontend on port 7860..."\n\
97
- cd $HOME/app/frontend\n\
98
- PORT=7860 BACKEND_HOST=http://localhost:8000 npm start\n\
99
- ' > $HOME/app/start.sh && chmod +x $HOME/app/start.sh
100
-
101
- # Expose port 7860 (HF Spaces default)
102
- EXPOSE 7860
103
-
104
- # Run the startup script
105
- CMD ["./start.sh"]
106
 
 
 
1
+ FROM node:trixie
2
 
3
+ WORKDIR /app
 
4
 
5
+ COPY * /app/
6
 
7
+ ENV PORT=7860
 
 
8
 
9
+ SHELL ["/bin/bash", "-c"]
 
 
 
 
 
 
 
10
 
11
+ RUN echo -e "\nTypes: deb\nURIs: http://deb.debian.org/debian\nSuites: trixie trixie-updates trixie-backports\nComponents: main contrib non-free non-free-firmware\nSigned-By: /usr/share/keyrings/debian-archive-keyring.pgp" >> /etc/apt/sources.list.d/debian.sources &&\
12
+ apt-get update &&\
13
+ apt-get install -y git unzip curl wget gzip procps coreutils bash upx-ucl gnupg2 ca-certificates lsb-release debian-archive-keyring &&\
14
+ curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null &&\
15
+ echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/debian `lsb_release -cs` nginx" | tee /etc/apt/sources.list.d/nginx.list &&\
16
+ echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | tee /etc/apt/preferences.d/99nginx &&\
17
+ apt-get update &&\
18
+ apt-get install -y nginx &&\
19
+ npm install -g pm2 &&\
20
+ npm install -g bash-obfuscate &&\
21
+ chmod -R 777 /app &&\
22
+ chmod -R 777 /var &&\
23
+ chmod -R 777 /run
24
+
25
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
+ ENTRYPOINT ["bash", "-c", "echo -e \"$RUN_BASE\" > /app/run.sh && chmod +x /app/run.sh && bash /app/run.sh"]