- add docker-swarm deployment example

- update dependencies
This commit is contained in:
Amruth Pillai
2023-11-22 09:08:23 +01:00
parent 55e94ca792
commit dfb3ef60dd
12 changed files with 602 additions and 413 deletions

View File

@ -1,4 +1,4 @@
version: "3"
version: "3.8"
# In this Docker Compose example, we only fire up the services required for local development.
# This is not advised for production use as it exposes ports to the database insecurely.
@ -6,22 +6,22 @@ version: "3"
services:
# Database (Postgres)
postgres:
image: postgres:alpine
restart: unless-stopped
ports:
- ${POSTGRES_PORT:-5432}:5432
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
POSTGRES_DB: ${POSTGRES_DB:-postgres}
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres} -d ${POSTGRES_DB:-postgres}"]
interval: 10s
timeout: 5s
retries: 5
# postgres:
# image: postgres:alpine
# restart: unless-stopped
# ports:
# - ${POSTGRES_PORT:-5432}:5432
# volumes:
# - postgres_data:/var/lib/postgresql/data
# environment:
# POSTGRES_DB: ${POSTGRES_DB:-postgres}
# POSTGRES_USER: ${POSTGRES_USER:-postgres}
# POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
# healthcheck:
# test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres} -d ${POSTGRES_DB:-postgres}"]
# interval: 10s
# timeout: 5s
# retries: 5
# Storage (for image uploads)
minio:

View File

@ -1,4 +1,4 @@
version: "3"
version: "3.8"
# In this Docker Compose example, we use Nginx Proxy Manager to manage the reverse proxy and SSL certificates.
# There's very little configuration to be made on the compose file itself, and most of it is done on the Nginx Proxy Manager UI.

View File

@ -1,4 +1,4 @@
version: "3"
version: "3.8"
# In this Docker Compose example, it assumes that you maintain a reverse proxy externally (or chose not to).
# The only two exposed ports here are from minio (:9000) and the app itself (:3000).

189
tools/compose/swarm.yml Normal file
View File

@ -0,0 +1,189 @@
version: "3.8"
# In this Docker Compose example, we use Docker Swarm to deploy Reactive Resume on multiple servers, with Traefik as the load balancer.
services:
# Database (Postgres)
postgres:
image: postgres:alpine
networks:
- reactive_resume_network
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d postgres"]
interval: 10s
timeout: 5s
retries: 5
deploy:
replicas: 1
restart_policy:
condition: on-failure
# Storage (for image uploads)
minio:
image: minio/minio
command: server /data
networks:
- reactive_resume_network
volumes:
- minio_data:/data
environment:
MINIO_ROOT_USER: minioadmin
MINIO_ROOT_PASSWORD: minioadmin
deploy:
replicas: 1
restart_policy:
condition: on-failure
labels:
- traefik.enable=true
- traefik.http.routers.storage.rule=Host(`storage.arkpg.xyz`)
- traefik.http.routers.storage.entrypoints=websecure
- traefik.http.routers.storage.tls.certresolver=letsencrypt
- traefik.http.services.storage.loadbalancer.server.port=9000
# Chrome Browser (for printing and previews)
chrome:
image: browserless/chrome:1.61.0-puppeteer-21.4.1
networks:
- reactive_resume_network
environment:
TOKEN: chrome_token
deploy:
replicas: 3
restart_policy:
condition: on-failure
labels:
- traefik.enable=true
- traefik.http.routers.printer.rule=Host(`printer.arkpg.xyz`)
- traefik.http.routers.printer.entrypoints=websecure
- traefik.http.routers.printer.tls.certresolver=letsencrypt
- traefik.http.services.printer.loadbalancer.server.port=3000
# Redis (for cache & server session management)
redis:
image: redis:alpine
command: redis-server --save 60 1 --loglevel warning --bind 0.0.0.0 --requirepass password
networks:
- reactive_resume_network
volumes:
- redis_data:/data
deploy:
replicas: 1
restart_policy:
condition: on-failure
app:
image: amruthpillai/reactive-resume:v4.0.0-alpha.8
networks:
- reactive_resume_network
environment:
# -- Environment Variables --
PORT: 3000
NODE_ENV: production
# -- URLs --
PUBLIC_URL: https://arkpg.xyz
STORAGE_URL: https://storage.arkpg.xyz
# -- Printer (Chrome) --
CHROME_TOKEN: chrome_token
CHROME_URL: wss://printer.arkpg.xyz
# -- Database (Postgres) --
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/postgres
# -- Auth --
ACCESS_TOKEN_SECRET: access_token_secret
REFRESH_TOKEN_SECRET: refresh_token_secret
# -- Emails --
# SMTP_URL: smtp://user:pass@smtp:587 # Optional
# -- Storage (Minio) --
STORAGE_ENDPOINT: minio
STORAGE_PORT: 9000
STORAGE_REGION: us-east-1 # Optional
STORAGE_BUCKET: default
STORAGE_ACCESS_KEY: minioadmin
STORAGE_SECRET_KEY: minioadmin
# -- Cache (Redis) --
REDIS_URL: redis://default:password@redis:6379
# -- Sentry --
# VITE_SENTRY_DSN: https://id.sentry.io # Optional
# -- Crowdin (Optional) --
CROWDIN_PROJECT_ID:
CROWDIN_PERSONAL_TOKEN:
# -- Email --
# DISABLE_EMAIL_AUTH: true
# -- GitHub --
GITHUB_CLIENT_ID: github_client_id
GITHUB_CLIENT_SECRET: github_client_secret
GITHUB_CALLBACK_URL: https://arkpg.xyz/api/auth/github/callback
# -- Google --
GOOGLE_CLIENT_ID: google_client_id
GOOGLE_CLIENT_SECRET: google_client_secret
GOOGLE_CALLBACK_URL: https://arkpg.xyz/api/auth/google/callback
deploy:
replicas: 3
restart_policy:
condition: on-failure
labels:
- traefik.enable=true
- traefik.http.routers.app.rule=Host(`arkpg.xyz`)
- traefik.http.routers.app.entrypoints=websecure
- traefik.http.routers.app.tls.certresolver=letsencrypt
- traefik.http.services.app.loadbalancer.server.port=3000
traefik:
image: traefik
command:
- --api=true
- --providers.docker=true
- --providers.docker.swarmMode=true
- --providers.docker.exposedbydefault=false
- --providers.docker.network=reactive_resume_network
- --entrypoints.web.address=:80
- --entrypoints.websecure.address=:443
- --certificatesresolvers.letsencrypt.acme.tlschallenge=true
- --certificatesresolvers.letsencrypt.acme.email=noreply@arkpg.xyz
- --certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json
# Let's Encrypt Staging Server (for testing)
# - --certificatesResolvers.letsencrypt.acme.caServer=https://acme-staging-v02.api.letsencrypt.org/directory
# Redirect all HTTP requests to HTTPS
- --entrypoints.web.http.redirections.entrypoint.to=websecure
- --entrypoints.web.http.redirections.entrypoint.scheme=https
ports:
- 80:80
- 443:443
- 8080:8080
networks:
- reactive_resume_network
volumes:
- letsencrypt_data:/letsencrypt
- /var/run/docker.sock:/var/run/docker.sock
deploy:
placement:
constraints: [node.role == manager]
volumes:
minio_data:
redis_data:
postgres_data:
letsencrypt_data:
networks:
reactive_resume_network:
external: true

View File

@ -1,4 +1,4 @@
version: "3"
version: "3.8"
# In this Docker Compose example, we use Traefik to route requests to the app and storage containers in a secure manner (HTTPS).
# This example assumes you have a domain name (example.com) and a wildcard DNS record pointing to your server.

View File

@ -1,4 +1,4 @@
version: "3"
version: "3.8"
# In this Docker Compose example, we use Traefik to route requests to the app and storage containers.
# This example assumes you have a domain name (example.com) and a wildcard DNS record pointing to your server.

View File

@ -63,15 +63,15 @@ CREATE UNIQUE INDEX "Secrets_resetToken_key" ON "Secrets"("resetToken");
-- CreateIndex
CREATE UNIQUE INDEX "Secrets_userId_key" ON "Secrets"("userId");
-- CreateIndex
CREATE UNIQUE INDEX "Resume_slug_key" ON "Resume"("slug");
-- CreateIndex
CREATE INDEX "Resume_userId_idx" ON "Resume"("userId");
-- CreateIndex
CREATE UNIQUE INDEX "Resume_userId_id_key" ON "Resume"("userId", "id");
-- CreateIndex
CREATE UNIQUE INDEX "Resume_userId_slug_key" ON "Resume"("userId", "slug");
-- AddForeignKey
ALTER TABLE "Secrets" ADD CONSTRAINT "Secrets_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;