From bf2d6e67cc65f53ecfb7bfbf953c93be518ccdc9 Mon Sep 17 00:00:00 2001 From: Redume Date: Wed, 9 Oct 2024 14:45:20 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=BD=D1=82=D0=B5=D0=B3=D1=80=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=20Docker=20compose?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env-sample | 4 +++ .gitignore | 4 ++- Dockerfile-collect-currency | 38 ++++++++++++++++++++++++ Dockerfile-server | 38 ++++++++++++++++++++++++ chart/.dockerignore | 2 ++ chart/Dockerfile | 12 ++++++++ collect-currency/.dockerignore | 1 + docker-compose.yaml | 54 ++++++++++++++++++++++++++++++++++ server/.dockerignore | 1 + 9 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 .env-sample create mode 100644 Dockerfile-collect-currency create mode 100644 Dockerfile-server create mode 100644 chart/.dockerignore create mode 100644 chart/Dockerfile create mode 100644 collect-currency/.dockerignore create mode 100644 docker-compose.yaml create mode 100644 server/.dockerignore diff --git a/.env-sample b/.env-sample new file mode 100644 index 0000000..cfc6a0c --- /dev/null +++ b/.env-sample @@ -0,0 +1,4 @@ +POSTGRES_USER=postgres +POSTGRES_PASSWORD=my_password +POSTGRES_DB=my_database +DB_HOST=postgres \ No newline at end of file diff --git a/.gitignore b/.gitignore index eaaeca8..7507d26 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,7 @@ CertSSL/ charts/ node_modules/ +postgres-data/ -config.yaml \ No newline at end of file +config.yaml +.env \ No newline at end of file diff --git a/Dockerfile-collect-currency b/Dockerfile-collect-currency new file mode 100644 index 0000000..642c4d4 --- /dev/null +++ b/Dockerfile-collect-currency @@ -0,0 +1,38 @@ +FROM node:20 as shared-config +# Устанавливаем зависимости shared/config +WORKDIR / +COPY ./shared/config/package*.json . +RUN npm install + +FROM node:20 as shared-database +# Устанавливаем зависимости shared/database +WORKDIR / +COPY ./shared/database/package*.json . +RUN npm install + +FROM node:20 as shared-logger +# Устанавливаем зависимости shared/logger +WORKDIR / +COPY ./shared/logger/package*.json . +RUN npm install + +FROM node:20 as collect-currency + +WORKDIR / + +# Устанавливаем зависимости server +COPY ./collect-currency/package*.json ./ +RUN npm install + +# Копируем зависимости shared +COPY --from=shared-config /node_modules /node_modules +COPY --from=shared-database /node_modules /node_modules +COPY --from=shared-logger /node_modules /node_modules + +# Копируем все остальные файлы +COPY ./collect-currency/ ./ +COPY ./shared/ ./shared/ + +EXPOSE 3000 + +CMD ["node", "main.js"] diff --git a/Dockerfile-server b/Dockerfile-server new file mode 100644 index 0000000..57cf692 --- /dev/null +++ b/Dockerfile-server @@ -0,0 +1,38 @@ +FROM node:20 as shared-config +# Устанавливаем зависимости shared/config +WORKDIR / +COPY ./shared/config/package*.json . +RUN npm install + +FROM node:20 as shared-database +# Устанавливаем зависимости shared/database +WORKDIR / +COPY ./shared/database/package*.json . +RUN npm install + +FROM node:20 as shared-logger +# Устанавливаем зависимости shared/logger +WORKDIR / +COPY ./shared/logger/package*.json . +RUN npm install + +FROM node:20 as server + +WORKDIR / + +# Устанавливаем зависимости server +COPY ./server/package*.json ./ +RUN npm install + +# Копируем зависимости shared +COPY --from=shared-config /node_modules /node_modules +COPY --from=shared-database /node_modules /node_modules +COPY --from=shared-logger /node_modules /node_modules + +# Копируем все остальные файлы +COPY ./server/ ./ +COPY ./shared/ ./shared/ + +EXPOSE 3000 + +CMD ["node", "main.js"] diff --git a/chart/.dockerignore b/chart/.dockerignore new file mode 100644 index 0000000..b1da149 --- /dev/null +++ b/chart/.dockerignore @@ -0,0 +1,2 @@ +mypy.ini +pylintrc \ No newline at end of file diff --git a/chart/Dockerfile b/chart/Dockerfile new file mode 100644 index 0000000..2d765e7 --- /dev/null +++ b/chart/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.12 + +WORKDIR / + +COPY ./requirements.txt ./ + +RUN pip3 install --no-cache-dir --upgrade -r ./requirements.txt + +COPY . . + +EXPOSE 3030 +CMD ["python", "main.py"] \ No newline at end of file diff --git a/collect-currency/.dockerignore b/collect-currency/.dockerignore new file mode 100644 index 0000000..40b878d --- /dev/null +++ b/collect-currency/.dockerignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..d02ddff --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,54 @@ +version: '3.8' + +services: + server: + build: + context: ./ + dockerfile: Dockerfile-server + restart: unless-stopped + ports: + - '0.0.0.0:3000:3000' + volumes: + - './CertSSL:/CertSSL' + - './config.yaml:/config.yaml' + depends_on: + - postgres + + chart: + build: + context: ./chart + restart: unless-stopped + ports: + - '0.0.0.0:3030:3030' + volumes: + - './CertSSL:/CertSSL' + - './config.yaml:/config.yaml' + depends_on: + - postgres + + collect-currency: + build: + context: ./ + dockerfile: Dockerfile-collect-currency + restart: unless-stopped + volumes: + - './config.yaml:/config.yaml' + depends_on: + - postgres + + postgres: + image: postgres:latest + restart: unless-stopped + env_file: .env + volumes: + - ./postgres-data:/var/lib/postgresql/data + +volumes: + server: + driver: local + chart: + driver: local + collect-currency: + driver: local + postgres: + driver: local \ No newline at end of file diff --git a/server/.dockerignore b/server/.dockerignore new file mode 100644 index 0000000..40b878d --- /dev/null +++ b/server/.dockerignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file