61 lines
1.6 KiB
Docker
61 lines
1.6 KiB
Docker
|
|
# Build-Phase für das Frontend
|
|
FROM node:latest AS frontend-build
|
|
WORKDIR /app
|
|
COPY ./frontend ./frontend
|
|
WORKDIR /app/frontend
|
|
RUN npm install
|
|
RUN npm run build
|
|
|
|
# Build-Phase für das Backend
|
|
FROM node:latest AS backend-build
|
|
WORKDIR /usr/src/app
|
|
COPY ./backend ./backend
|
|
WORKDIR /usr/src/app/backend
|
|
RUN npm install -g typescript
|
|
RUN npm install
|
|
RUN tsc
|
|
|
|
# Produktionsphase
|
|
FROM node:latest
|
|
WORKDIR /usr/src/app
|
|
|
|
# Kopieren des React-Builds
|
|
COPY --from=frontend-build /app/frontend/build /var/www/html
|
|
|
|
# Backend-Quelldateien und kompilierte JavaScript-Dateien kopieren
|
|
COPY --from=backend-build /usr/src/app/backend /usr/src/app/backend
|
|
|
|
# Nginx installieren
|
|
RUN apt-get update && apt-get install -y nginx
|
|
|
|
# Standard Nginx-Konfiguration überschreiben, falls notwendig
|
|
RUN echo 'server { \
|
|
listen 80; \
|
|
root /var/www/html; \
|
|
index index.html index.htm; \
|
|
location /sw.js { \
|
|
add_header Cache-Control "no-cache"; \
|
|
proxy_cache_bypass $http_pragma; \
|
|
proxy_cache_revalidate on; \
|
|
expires off; \
|
|
access_log off; \
|
|
} \
|
|
location / { \
|
|
try_files $uri $uri/ /index.html; \
|
|
} \
|
|
location /api { \
|
|
proxy_pass http://127.0.0.1:8800; \
|
|
proxy_set_header Host $http_host; \
|
|
proxy_set_header X-Real-IP $remote_addr; \
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; \
|
|
proxy_set_header X-Forwarded-Proto $scheme; \
|
|
proxy_redirect off; \
|
|
} \
|
|
}' > /etc/nginx/sites-enabled/default
|
|
|
|
EXPOSE 80
|
|
|
|
# Startkommando
|
|
CMD sh -c "nginx -g 'daemon off;' & node backend/dist/index.js"
|
|
|