Skip to content

Commit

Permalink
docker
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomNick2 committed Oct 19, 2024
1 parent 3c2764c commit 5233fbd
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 29 deletions.
Binary file added .DS_Store
Binary file not shown.
28 changes: 24 additions & 4 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
FROM node:lts-alpine
# Stage 1: Build the NestJS app
FROM node:lts-alpine AS build

WORKDIR /docker
WORKDIR /docker/backend

# Копируем package.json и yarn.lock для установки зависимостей
COPY package.json yarn.lock ./

RUN yarn install --frozen-lockfile
# Устанавливаем зависимости
RUN yarn install

# Копируем остальные файлы
COPY . .

# RUN yarn prisma migrate deploy
# Генерируем Prisma Client
RUN yarn prisma generate

# Сборка проекта
RUN yarn build

# Stage 2: Запуск приложения
FROM node:lts-alpine

WORKDIR /docker/backend

# Копируем только необходимые файлы для работы приложения
COPY --from=build /docker/backend/dist ./dist
COPY --from=build /docker/backend/package.json ./
COPY --from=build /docker/backend/yarn.lock ./

# Устанавливаем только производственные зависимости
RUN yarn install --production=true

# Открываем порт
EXPOSE 3000

# Запускаем приложение
CMD ["yarn", "start:prod"]
2 changes: 1 addition & 1 deletion bot/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:3.9-slim-buster

WORKDIR /docker
WORKDIR /docker/bot
COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt
Expand Down
34 changes: 20 additions & 14 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ services:
container_name: frontend
depends_on:
- backend
restart: always
volumes:
- ./frontend:/docker/frontend

ports:
- '80:80'
networks:
- custom

backend:
build: ./backend
container_name: backend
Expand Down Expand Up @@ -40,19 +45,20 @@ services:
restart: always
networks:
- custom

nginx:
image: nginx:alpine
container_name: nginx
ports:
- '80:80'
depends_on:
- frontend
- backend
volumes:
- ./docker/app.conf:/etc/nginx/conf.d/app.conf
- ./docker/frontend:/usr/share/nginx/html
restart: always

# nginx:
# image: nginx:alpine
# container_name: nginx
# ports:
# - '80:80'
# depends_on:
# - frontend
# - backend
# volumes:
# - ./frontend/nginx.conf:/etc/nginx/conf.d/app.conf
# restart: always
# networks:
# - custom

volumes:
pgdata:
Expand Down
4 changes: 0 additions & 4 deletions docker/Dockerfile.nginx

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VITE_API_BASE_URL=http://localhost:3000/api
VITE_API_BASE_URL=http://localhost/api
24 changes: 20 additions & 4 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
FROM node:lts-alpine
# Dockerfile

WORKDIR /docker
# Stage 1: Build Vue app
FROM node:lts-alpine AS build
WORKDIR /docker/frontend

COPY package*.json ./
RUN yarn install --frozen-lockfile
# Copy only the essential files for install and build
COPY package.json yarn.lock ./
RUN yarn install

# Copy the rest of the project files
COPY . .

# Build the Vue app
RUN yarn build

# Stage 2: Serve with Nginx
FROM nginx:stable-alpine AS production

# Copy built files from the build stage to the Nginx directory
RUN ls
COPY --from=build /docker/frontend/dist /usr/share/nginx/html
# Nginx config (if needed)
COPY ./nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
6 changes: 5 additions & 1 deletion docker/app.conf → frontend/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
upstream backend {
server backend:3000;
}

server {
listen 80;
charset utf-8;
Expand All @@ -10,7 +14,7 @@ server {
}

location /api {
proxy_pass http://127.0.0.1:3000/api;
proxy_pass http://backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand Down

0 comments on commit 5233fbd

Please sign in to comment.