From 8d3b3f9fe3366670884514af639c8ccd102dccab Mon Sep 17 00:00:00 2001 From: robonen Date: Mon, 14 Nov 2022 05:18:27 +0700 Subject: [PATCH] feat(repo): two application replicas in docker-compose --- .env.example | 11 ++++++++++- Dockerfile | 4 ++-- config/nginx/{proxy.conf => proxy_lb.conf} | 1 + docker-compose.yml | 17 +++++++++++------ package.json | 6 ++++++ src/server/api/test.ts | 9 +++++++++ 6 files changed, 39 insertions(+), 9 deletions(-) rename config/nginx/{proxy.conf => proxy_lb.conf} (98%) create mode 100644 src/server/api/test.ts diff --git a/.env.example b/.env.example index 888e107..aaa2bd8 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,10 @@ -NUXT_API_HOST=https://localhost +# Infrastucture config +FORWARD_APP_PORT=3000 + +FORWARD_DB_PORT=5432 +DB_USERNAME=postgres +DB_PASSWORD=password +DB_DATABASE=c3d + +# App config +NUXT_API_HOST=http://app diff --git a/Dockerfile b/Dockerfile index c9234ba..f6536d0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,7 @@ FROM node:${NODE_VERSION} AS builder WORKDIR /build +# See .dockerignore COPY . . RUN npm cache clean --force && npm ci && npm run build @@ -19,7 +20,6 @@ COPY --from=builder /build/src/.output . ENV HOST=0.0.0.0 ENV PORT=3000 -VOLUME /app EXPOSE 3000 -CMD ["node", "./server/index.mjs"] +ENTRYPOINT ["node", "./server/index.mjs"] diff --git a/config/nginx/proxy.conf b/config/nginx/proxy_lb.conf similarity index 98% rename from config/nginx/proxy.conf rename to config/nginx/proxy_lb.conf index 82b0fad..5077d16 100644 --- a/config/nginx/proxy.conf +++ b/config/nginx/proxy_lb.conf @@ -1,6 +1,7 @@ server { listen 80; + # Default docker DNS resolver 127.0.0.11 ipv6=off valid=10s; # . files diff --git a/docker-compose.yml b/docker-compose.yml index 2e9ade6..dd9760c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,26 +2,31 @@ version: '3' services: - proxy: - container_name: proxy + proxy_lb: + container_name: proxy_lb image: nginx:latest ports: - '${PROXY_PORT:-80}:80' - '${PROXY_PORT_SSL:-443}:443' volumes: - - './config/nginx/proxy.conf:/etc/nginx/conf.d/default.conf' + - './config/nginx/proxy_lb.conf:/etc/nginx/conf.d/default.conf' networks: - c3d_net depends_on: - app app: - container_name: app +# container_name: app build: context: . dockerfile: Dockerfile - ports: - - '${FORWARD_APP_PORT:-3000}:3000' + deploy: + mode: replicated + replicas: 2 + expose: + - '${FORWARD_APP_PORT:-3000}' +# ports: +# - '${FORWARD_APP_PORT:-3000}:3000' networks: - c3d_net depends_on: diff --git a/package.json b/package.json index 2455ec9..2f92493 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,10 @@ { + "name": "canvas3d", + "description": "Web application for affine transformations of three-dimensional figures", + "bugs": { + "url": "https://github.com/robonen/canvas-3d/issues?q=is:open is:issue label:bug" + }, + "license": "MIT", "private": true, "scripts": { "build": "nuxt build", diff --git a/src/server/api/test.ts b/src/server/api/test.ts new file mode 100644 index 0000000..b926d2e --- /dev/null +++ b/src/server/api/test.ts @@ -0,0 +1,9 @@ +import {defineEventHandler} from 'h3'; + +export default defineEventHandler((event) => { + console.log('Request received'); + + return { + api: 'works', + }; +});