Add cache-proxy service to Docker configurations and update deployment workflow</message>

<message>
- Introduced a new cache-proxy service in both `docker-compose.dev.yml` and `docker-compose.yml`, with dependencies on Redis and integration into the web and bot services.
- Updated GitHub Actions workflow to include build and push steps for the cache-proxy image, ensuring it is deployed alongside web and bot services.
- Modified environment variable management to accommodate the cache-proxy, enhancing the overall deployment process.
- Adjusted GraphQL cached URL to point to the cache-proxy service for improved request handling.
This commit is contained in:
vchikalkin 2025-10-06 20:10:30 +03:00
parent b8b8ca6004
commit 50ef49d01f
5 changed files with 40 additions and 2 deletions

View File

@ -1,4 +1,4 @@
name: Build & Deploy Web & Bot
name: Build & Deploy Web, Bot & Cache Proxy
on:
push:
@ -12,6 +12,7 @@ jobs:
outputs:
web_tag: ${{ steps.vars.outputs.web_tag }}
bot_tag: ${{ steps.vars.outputs.bot_tag }}
cache_proxy_tag: ${{ steps.vars.outputs.cache_proxy_tag }}
steps:
- name: Checkout code
uses: actions/checkout@v3
@ -33,6 +34,7 @@ jobs:
run: |
echo "web_tag=web-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
echo "bot_tag=bot-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
echo "cache_proxy_tag=cache-proxy-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
- name: Login to Docker Hub
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin
@ -53,6 +55,14 @@ jobs:
run: |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-bot:${{ steps.vars.outputs.bot_tag }}
- name: Build cache-proxy image
run: |
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-cache-proxy:${{ steps.vars.outputs.cache_proxy_tag }} -f ./apps/cache-proxy/Dockerfile .
- name: Push cache-proxy image to Docker Hub
run: |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-cache-proxy:${{ steps.vars.outputs.cache_proxy_tag }}
deploy:
name: Deploy to VPS
needs: build-and-push
@ -84,6 +94,7 @@ jobs:
echo "BOT_URL=${{ secrets.BOT_URL }}" >> .env
echo "WEB_IMAGE_TAG=${{ needs.build-and-push.outputs.web_tag }}" >> .env
echo "BOT_IMAGE_TAG=${{ needs.build-and-push.outputs.bot_tag }}" >> .env
echo "CACHE_PROXY_IMAGE_TAG=${{ needs.build-and-push.outputs.cache_proxy_tag }}" >> .env
echo "DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}" >> .env
echo "REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }}" >> .env
echo "BOT_PROVIDER_TOKEN=${{ secrets.BOT_PROVIDER_TOKEN }}" >> .env

View File

@ -14,6 +14,7 @@ import { env } from 'src/config/env';
store: redisStore,
ttl: env.CACHE_TTL,
password: env.REDIS_PASSWORD,
db: 1,
}),
],
})

View File

@ -1,4 +1,13 @@
services:
cache-proxy:
build:
context: .
dockerfile: ./apps/cache-proxy/Dockerfile
env_file:
- .env
depends_on:
- redis
restart: always
web:
env_file:
- .env
@ -6,6 +15,8 @@ services:
context: .
dockerfile: ./apps/web/Dockerfile
restart: always
depends_on:
- cache-proxy
ports:
- 3000:3000
bot:
@ -16,6 +27,7 @@ services:
- .env
depends_on:
- redis
- cache-proxy
restart: always
redis:

View File

@ -1,4 +1,14 @@
services:
cache-proxy:
image: ${DOCKERHUB_USERNAME}/zapishis-cache-proxy:${CACHE_PROXY_IMAGE_TAG}
env_file:
- .env
restart: always
depends_on:
- redis
networks:
- app
- web
web:
image: ${DOCKERHUB_USERNAME}/zapishis-web:${WEB_IMAGE_TAG}
env_file:
@ -9,6 +19,8 @@ services:
interval: 10s
timeout: 3s
retries: 5
depends_on:
- cache-proxy
networks:
- app
- web
@ -20,6 +32,7 @@ services:
- .env
depends_on:
- redis
- cache-proxy
networks:
- app

View File

@ -1,3 +1,4 @@
/* eslint-disable sonarjs/no-clear-text-protocols */
/* eslint-disable unicorn/prevent-abbreviations */
import { z } from 'zod';
@ -6,7 +7,7 @@ export const envSchema = z.object({
LOGIN_GRAPHQL: z.string(),
PASSWORD_GRAPHQL: z.string(),
URL_GRAPHQL: z.string(),
URL_GRAPHQL_CACHED: z.string().default('http://localhost:5000/proxy/graphql'),
URL_GRAPHQL_CACHED: z.string().default('http://cache-proxy:5000/proxy/graphql'),
});
export const env = envSchema.parse(process.env);