Mafia2008 commited on
Commit
e1dfcd1
·
verified ·
1 Parent(s): 2771104

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +15 -13
Dockerfile CHANGED
@@ -1,3 +1,4 @@
 
1
  FROM ubuntu:22.04
2
 
3
  ENV DEBIAN_FRONTEND=noninteractive
@@ -33,7 +34,8 @@ RUN pip3 install fastapi uvicorn pydantic
33
  RUN mkdir -p /opt/api /workspace /var/log/supervisor
34
 
35
  # ---- 1. Create the Python API (FastAPI) ----
36
- RUN /bin/bash -c "cat << 'EOF' > /opt/api/api.py
 
37
  from fastapi import FastAPI, HTTPException
38
  from pydantic import BaseModel
39
  import os, subprocess, shutil
@@ -93,10 +95,10 @@ def delete_item(req: DeleteRequest):
93
  return {'status': 'success'}
94
  except Exception as e:
95
  raise HTTPException(status_code=400, detail=str(e))
96
- EOF"
97
 
98
  # ---- 2. Create Nginx Configuration ----
99
- RUN /bin/bash -c "cat << 'EOF' > /etc/nginx/nginx.conf
100
  events {}
101
  http {
102
  server {
@@ -104,25 +106,25 @@ http {
104
 
105
  # Route API requests to Python server
106
  location /api/ {
107
- proxy_pass http://127.0.0.1:8000/api/;
108
- proxy_set_header Host \$host;
109
- proxy_set_header X-Real-IP \$remote_addr;
110
  }
111
 
112
  # Route all other requests to code-server
113
  location / {
114
  proxy_pass http://127.0.0.1:8080/;
115
- proxy_set_header Host \$host;
116
- proxy_set_header Upgrade \$http_upgrade;
117
  proxy_set_header Connection upgrade;
118
  proxy_set_header Accept-Encoding gzip;
119
  }
120
  }
121
  }
122
- EOF"
123
 
124
  # ---- 3. Create Supervisor Configuration ----
125
- RUN /bin/bash -c "cat << 'EOF' > /etc/supervisor/conf.d/supervisord.conf
126
  [supervisord]
127
  nodaemon=true
128
 
@@ -137,14 +139,14 @@ directory=/opt/api
137
  autorestart=true
138
 
139
  [program:nginx]
140
- command=nginx -g 'daemon off;'
141
  autorestart=true
142
- EOF"
143
 
144
  # ---- Workspace Setup ----
145
  WORKDIR /workspace
146
 
147
  EXPOSE 7860
148
 
149
- # Start Supervisor (which starts code-server, api, and nginx)
150
  CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
 
1
+ # syntax=docker/dockerfile:1
2
  FROM ubuntu:22.04
3
 
4
  ENV DEBIAN_FRONTEND=noninteractive
 
34
  RUN mkdir -p /opt/api /workspace /var/log/supervisor
35
 
36
  # ---- 1. Create the Python API (FastAPI) ----
37
+ # Using COPY <<"EOF" cleanly writes the file without escaping issues
38
+ COPY <<"EOF" /opt/api/api.py
39
  from fastapi import FastAPI, HTTPException
40
  from pydantic import BaseModel
41
  import os, subprocess, shutil
 
95
  return {'status': 'success'}
96
  except Exception as e:
97
  raise HTTPException(status_code=400, detail=str(e))
98
+ EOF
99
 
100
  # ---- 2. Create Nginx Configuration ----
101
+ COPY <<"EOF" /etc/nginx/nginx.conf
102
  events {}
103
  http {
104
  server {
 
106
 
107
  # Route API requests to Python server
108
  location /api/ {
109
+ proxy_pass http://127.0.0.1:8000;
110
+ proxy_set_header Host $host;
111
+ proxy_set_header X-Real-IP $remote_addr;
112
  }
113
 
114
  # Route all other requests to code-server
115
  location / {
116
  proxy_pass http://127.0.0.1:8080/;
117
+ proxy_set_header Host $host;
118
+ proxy_set_header Upgrade $http_upgrade;
119
  proxy_set_header Connection upgrade;
120
  proxy_set_header Accept-Encoding gzip;
121
  }
122
  }
123
  }
124
+ EOF
125
 
126
  # ---- 3. Create Supervisor Configuration ----
127
+ COPY <<"EOF" /etc/supervisor/conf.d/supervisord.conf
128
  [supervisord]
129
  nodaemon=true
130
 
 
139
  autorestart=true
140
 
141
  [program:nginx]
142
+ command=nginx -g "daemon off;"
143
  autorestart=true
144
+ EOF
145
 
146
  # ---- Workspace Setup ----
147
  WORKDIR /workspace
148
 
149
  EXPOSE 7860
150
 
151
+ # Start Supervisor (which automatically handles code-server, api, and nginx)
152
  CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]