diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index cd8d08b..ab5adac 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -1,15 +1,12 @@ +networks: + cc-shared-network: + external: true + name: cc-prod-shared-network + volumes: subgraphs_data: services: - mongo: - image: mongo:4.4 - volumes: - - /mnt/share/mongo:/data/db - env_file: - - $CC_CONFIG_PATH/prod/global - restart: unless-stopped - gateway: # image: cc-gateway:${IMAGE_TAG_GATEWAY:-latest} build: ./gateway @@ -26,35 +23,16 @@ services: - members - events - users + networks: + - cc-shared-network + healthcheck: + test: ["CMD-SHELL", "node -e \"require('http').get('http://localhost:80/health', (r) => {if (r.statusCode !== 200) throw new Error(r.statusCode)})\""] + interval: 10s + timeout: 10s + retries: 30 + start_period: 60s restart: unless-stopped - nginx: - build: ./nginx - volumes: - - ./nginx:/etc/nginx/conf.d - depends_on: - - auth - - files - - gateway - - web - environment: - - VIRTUAL_HOST=clubs.iiit.ac.in - - LETSENCRYPT_HOST=clubs.iiit.ac.in - ports: - - "8000:80" - restart: unless-stopped - - # feeder: - # image: cc-feeder:${IMAGE_TAG_FEEDER:-latest} - # build: ./feeder - # volumes: - # - ./data:/data - # depends_on: - # - mongo - # env_file: - # - $CC_CONFIG_PATH/prod/global - # restart: no - web: image: cc-web:${IMAGE_TAG_WEB:-latest} # build: @@ -62,6 +40,8 @@ services: env_file: - $CC_CONFIG_PATH/prod/global - $CC_CONFIG_PATH/prod/web + networks: + - cc-shared-network restart: unless-stopped auth: @@ -72,6 +52,8 @@ services: - $CC_CONFIG_PATH/prod/auth volumes: - ./config:/app/config + networks: + - cc-shared-network restart: unless-stopped files: @@ -84,6 +66,8 @@ services: env_file: - $CC_CONFIG_PATH/prod/global - $CC_CONFIG_PATH/prod/files + networks: + - cc-shared-network restart: unless-stopped # subgraphs @@ -93,11 +77,11 @@ services: volumes: - subgraphs_data:/subgraphs - ./config:/app/config - depends_on: - - mongo env_file: - $CC_CONFIG_PATH/prod/global - $CC_CONFIG_PATH/prod/interfaces + networks: + - cc-shared-network restart: unless-stopped clubs: @@ -106,10 +90,10 @@ services: volumes: - subgraphs_data:/subgraphs - ./config:/app/config - depends_on: - - mongo env_file: - $CC_CONFIG_PATH/prod/global + networks: + - cc-shared-network restart: unless-stopped members: @@ -118,10 +102,10 @@ services: volumes: - subgraphs_data:/subgraphs - ./config:/app/config - depends_on: - - mongo env_file: - $CC_CONFIG_PATH/prod/global + networks: + - cc-shared-network restart: unless-stopped events: @@ -130,10 +114,10 @@ services: volumes: - subgraphs_data:/subgraphs - ./config:/app/config - depends_on: - - mongo env_file: - $CC_CONFIG_PATH/prod/global + networks: + - cc-shared-network restart: unless-stopped users: @@ -142,8 +126,8 @@ services: volumes: - subgraphs_data:/subgraphs - ./config:/app/config - depends_on: - - mongo env_file: - $CC_CONFIG_PATH/prod/global + networks: + - cc-shared-network restart: unless-stopped diff --git a/docker-compose.shared.prod.yml b/docker-compose.shared.prod.yml new file mode 100644 index 0000000..31343f5 --- /dev/null +++ b/docker-compose.shared.prod.yml @@ -0,0 +1,28 @@ +networks: + cc-shared-network: + name: cc-prod-shared-network + driver: bridge + +services: + mongo: + image: mongo:4.4 + volumes: + - /mnt/share/mongo:/data/db + env_file: + - $CC_CONFIG_PATH/prod/global + networks: + - cc-shared-network + restart: unless-stopped + + nginx: + build: ./nginx + volumes: + - ./nginx:/etc/nginx/conf.d + environment: + - VIRTUAL_HOST=clubs.iiit.ac.in + - LETSENCRYPT_HOST=clubs.iiit.ac.in + ports: + - "8000:80" + networks: + - cc-shared-network + restart: unless-stopped diff --git a/docker-compose.shared.staging.yml b/docker-compose.shared.staging.yml new file mode 100644 index 0000000..4621d28 --- /dev/null +++ b/docker-compose.shared.staging.yml @@ -0,0 +1,28 @@ +networks: + cc-shared-network: + name: cc-staging-shared-network + driver: bridge + +services: + mongo: + image: mongo:4.4 + volumes: + - /mnt/share/mongo_stage:/data/db + env_file: + - $CC_CONFIG_PATH/staging/global + networks: + - cc-shared-network + restart: unless-stopped + + nginx: + build: ./nginx + volumes: + - ./nginx:/etc/nginx/conf.d + environment: + - VIRTUAL_HOST=dev-clubs.iiit.ac.in + # - LETSENCRYPT_HOST=clubs.iiit.ac.in + ports: + - "9000:80" + networks: + - cc-shared-network + restart: unless-stopped diff --git a/docker-compose.staging.yml b/docker-compose.staging.yml index 894ad23..47f11eb 100644 --- a/docker-compose.staging.yml +++ b/docker-compose.staging.yml @@ -1,15 +1,12 @@ +networks: + cc-shared-network: + external: true + name: cc-staging-shared-network + volumes: subgraphs_data: services: - mongo: - image: mongo:4.4 - volumes: - - /mnt/share/mongo_stage:/data/db - env_file: - - $CC_CONFIG_PATH/staging/global - restart: unless-stopped - gateway: # image: cc-gateway:${IMAGE_TAG_GATEWAY:-latest} build: ./gateway @@ -26,39 +23,23 @@ services: - members - events - users + networks: + - cc-shared-network + healthcheck: + test: ["CMD-SHELL", "node -e \"require('http').get('http://localhost:80/health', (r) => {if (r.statusCode !== 200) throw new Error(r.statusCode)})\""] + interval: 10s + timeout: 10s + retries: 30 + start_period: 60s restart: unless-stopped - nginx: - build: ./nginx - volumes: - - ./nginx:/etc/nginx/conf.d - depends_on: - - auth - - files - - gateway - - web - environment: - - VIRTUAL_HOST=dev.clubs.iiit.ac.in - # - LETSENCRYPT_HOST=clubs.iiit.ac.in - ports: - - "9000:80" - restart: unless-stopped - - # feeder: - # image: cc-feeder:${IMAGE_TAG_FEEDER:-latest} - # volumes: - # - ./data:/data - # depends_on: - # - mongo - # env_file: - # - $CC_CONFIG_PATH/staging/global - # restart: no - web: image: cc-web:${IMAGE_TAG_WEB:-latest} env_file: - $CC_CONFIG_PATH/staging/global - $CC_CONFIG_PATH/staging/web + networks: + - cc-shared-network restart: unless-stopped auth: @@ -68,6 +49,8 @@ services: - $CC_CONFIG_PATH/staging/auth volumes: - ./config:/app/config + networks: + - cc-shared-network restart: unless-stopped files: @@ -79,6 +62,8 @@ services: env_file: - $CC_CONFIG_PATH/staging/global - $CC_CONFIG_PATH/staging/files + networks: + - cc-shared-network restart: unless-stopped # subgraphs @@ -87,11 +72,11 @@ services: volumes: - subgraphs_data:/subgraphs - ./config:/app/config - depends_on: - - mongo env_file: - $CC_CONFIG_PATH/staging/global - $CC_CONFIG_PATH/staging/interfaces + networks: + - cc-shared-network restart: unless-stopped clubs: @@ -99,10 +84,10 @@ services: volumes: - subgraphs_data:/subgraphs - ./config:/app/config - depends_on: - - mongo env_file: - $CC_CONFIG_PATH/staging/global + networks: + - cc-shared-network restart: unless-stopped members: @@ -110,10 +95,10 @@ services: volumes: - subgraphs_data:/subgraphs - ./config:/app/config - depends_on: - - mongo env_file: - $CC_CONFIG_PATH/staging/global + networks: + - cc-shared-network restart: unless-stopped events: @@ -121,10 +106,10 @@ services: volumes: - subgraphs_data:/subgraphs - ./config:/app/config - depends_on: - - mongo env_file: - $CC_CONFIG_PATH/staging/global + networks: + - cc-shared-network restart: unless-stopped users: @@ -132,8 +117,8 @@ services: volumes: - subgraphs_data:/subgraphs - ./config:/app/config - depends_on: - - mongo env_file: - $CC_CONFIG_PATH/staging/global + networks: + - cc-shared-network restart: unless-stopped diff --git a/docker-compose.yml b/docker-compose.yml index 6a392c6..3311a39 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,6 +27,12 @@ services: env_file: - ./.env.example - ./gateway/.env.example + healthcheck: + test: ["CMD-SHELL", "node -e \"require('http').get('http://localhost:80/health', (r) => {if (r.statusCode !== 200) throw new Error(r.statusCode)})\""] + interval: 10s + timeout: 10s + retries: 30 + start_period: 60s depends_on: - interfaces - clubs diff --git a/nginx/app.conf.template b/nginx/app.conf.template new file mode 100644 index 0000000..438a72c --- /dev/null +++ b/nginx/app.conf.template @@ -0,0 +1,85 @@ +upstream auth { + server ${PROJECT_NAME}-auth-1; +} + +upstream files { + server ${PROJECT_NAME}-files-1; +} + +upstream graphql { + server ${PROJECT_NAME}-gateway-1; +} + +upstream web { + server ${PROJECT_NAME}-web-1; +} + +js_path "/etc/nginx/conf.d"; +js_import http.js; + +js_set $gallery_index http.gallery_index; +js_set $version http.version; + +server { + listen 80; + server_name ${VIRTUAL_HOST}; + client_max_body_size 100M; + + location ~ ^/(login|logout|logoutCallback) { + proxy_pass http://auth$request_uri; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_redirect off; + } + + location /files { + proxy_pass http://files$request_uri; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_redirect off; + } + + location /graphql { + proxy_pass http://graphql$request_uri; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_redirect off; + } + + error_page 404 /custom_404.html; + location = /custom_404.html { + root /usr/share/nginx/html; + internal; + } + + error_page 500 502 503 504 /custom_50x.html; + location = /custom_50x.html { + root /usr/share/nginx/html; + internal; + } + + location ~ ^/static/(.*)$ { + # expires off; + # expires 1h; + expires -1; + root /usr/share/nginx; + try_files /$1 /others/$1 /$1/ /others/$1/ =404; + } + + # ignore cache frontend + location ~* (service-worker\.js)$ { + add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0'; + expires off; + proxy_no_cache 1; + } + + location / { + proxy_pass http://web$request_uri; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } +}