Spaces:
Build error
Build error
TomTom101
commited on
Commit
•
b77940d
1
Parent(s):
6c555cd
First test
Browse files- Dockerfile +58 -0
- docker/nginx.prod.conf +19 -0
- docker/supervisord.conf +13 -0
Dockerfile
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Node frontend build
|
2 |
+
FROM node:18 as builder
|
3 |
+
|
4 |
+
WORKDIR /usr/src/app
|
5 |
+
RUN --mount=type=secret,id=SECRET_EXAMPLE,mode=0444,required=true \
|
6 |
+
git clone https://TomTom101:$(cat /run/secrets/SECRET_EXAMPLE)@github.com/TomTom101/use-case-voting .
|
7 |
+
|
8 |
+
|
9 |
+
WORKDIR /usr/src/app/frontend
|
10 |
+
RUN npm install
|
11 |
+
RUN npm run build
|
12 |
+
|
13 |
+
# Main build
|
14 |
+
FROM python:3.11-slim-bookworm
|
15 |
+
|
16 |
+
RUN useradd -m -u 1000 user
|
17 |
+
|
18 |
+
ENV POETRY_VERSION=1.6 \
|
19 |
+
POETRY_VIRTUALENVS_CREATE=false
|
20 |
+
ENV HOME=/home/user \
|
21 |
+
PATH=/home/user/.local/bin:$PATH
|
22 |
+
|
23 |
+
WORKDIR $HOME/app
|
24 |
+
|
25 |
+
USER root
|
26 |
+
RUN apt-get update \
|
27 |
+
&& apt-get install nginx supervisor -y
|
28 |
+
COPY --from=builder /usr/src/app/dist /usr/share/nginx/html
|
29 |
+
COPY --chown=user ./docker/nginx.prod.conf /etc/nginx/sites-available/default
|
30 |
+
COPY --chown=user ./docker/supervisord.conf /etc/supervisord.conf
|
31 |
+
|
32 |
+
# Create nginx folders
|
33 |
+
RUN mkdir -p /var/cache/nginx \
|
34 |
+
/var/log/nginx \
|
35 |
+
/var/lib/nginx
|
36 |
+
RUN touch /var/run/nginx.pid
|
37 |
+
RUN chown -R user:user \
|
38 |
+
/var/cache/nginx \
|
39 |
+
/var/log/nginx \
|
40 |
+
/var/lib/nginx \
|
41 |
+
/var/run/nginx.pid
|
42 |
+
|
43 |
+
RUN chown -R user:user $HOME/app
|
44 |
+
|
45 |
+
# Install poetry
|
46 |
+
RUN pip install "poetry==$POETRY_VERSION"
|
47 |
+
COPY --from=builder /usr/src/app/poetry.lock /usr/src/app/pyproject.toml /usr/src/app/README.md ./
|
48 |
+
|
49 |
+
# Project initialization:
|
50 |
+
RUN poetry install --no-cache --no-interaction --no-ansi --no-root --without dev
|
51 |
+
COPY --from=builder /usr/src/app/use_case_voting ./use_case_voting
|
52 |
+
RUN poetry install --only-root
|
53 |
+
|
54 |
+
USER user
|
55 |
+
RUN touch $HOME/app/supervisord.pid
|
56 |
+
|
57 |
+
# Start nginx and FastAPI
|
58 |
+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
|
docker/nginx.prod.conf
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
server {
|
2 |
+
listen 7860;
|
3 |
+
location / {
|
4 |
+
root /usr/share/nginx/html;
|
5 |
+
index index.html;
|
6 |
+
try_files $uri $uri/ /index.html;
|
7 |
+
}
|
8 |
+
location /api {
|
9 |
+
proxy_pass http://localhost:8000;
|
10 |
+
proxy_set_header Host $host;
|
11 |
+
proxy_set_header X-Real-IP $remote_addr;
|
12 |
+
}
|
13 |
+
location /ws {
|
14 |
+
proxy_pass http://localhost:8000/api/v1/ws;
|
15 |
+
proxy_http_version 1.1;
|
16 |
+
proxy_set_header Upgrade $http_upgrade;
|
17 |
+
proxy_set_header Connection "upgrade";
|
18 |
+
}
|
19 |
+
}
|
docker/supervisord.conf
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[supervisord]
|
2 |
+
nodaemon=true
|
3 |
+
logfile=/home/user/supervisord.log
|
4 |
+
childlogdir=/home/user/
|
5 |
+
user=user
|
6 |
+
|
7 |
+
[program:nginx]
|
8 |
+
redirect_stderr=true
|
9 |
+
command=/usr/sbin/nginx -g "daemon off;"
|
10 |
+
|
11 |
+
[program:uvicorn]
|
12 |
+
command=uvicorn api:app --host 0.0.0.0 --port 8000
|
13 |
+
directory=/home/user/app/use_case_voting
|