-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathswarm-stack.yml
157 lines (148 loc) · 4.86 KB
/
swarm-stack.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
version: "3.8"
services:
boilerplate-api:
image: definya/definya-team:api-latest
healthcheck:
test: ["CMD", "curl", "--fail", "http://localhost:5002"]
interval: 60s
timeout: 30s
retries: 3
deploy:
replicas: 3
restart_policy:
condition: on-failure
placement:
constraints:
- node.role == worker #! Only runs in worker node to preserve the DB on the manager node
preferences:
- spread: node.id
max_replicas_per_node: 1
update_config:
parallelism: 2
delay: 10s
failure_action: rollback
rollback_config:
parallelism: 2
delay: 10s
labels:
# Basic setup for API
- traefik.enable=true
- traefik.http.routers.boilerplate-api.rule=Host(`na.definya.com`)
- traefik.http.routers.boilerplate-api.entrypoints=websecure
- traefik.http.routers.boilerplate-api.tls.certresolver=myresolver
- traefik.http.services.boilerplate-api-service.loadbalancer.server.port=5002
- traefik.http.routers.boilerplate-api.service=boilerplate-api-service
# Websockets
- traefik.http.routers.boilerplate-api-socket.rule=Host(`na.definya.com`) && Path(`/socket.io/`)
- traefik.http.routers.boilerplate-api-socket.entrypoints=websecure
- traefik.http.routers.boilerplate-api-socket.tls.certresolver=myresolver
- traefik.http.services.boilerplate-api-socket-service.loadbalancer.server.port=5101
- traefik.http.routers.boilerplate-api-socket.service=boilerplate-api-socket-service
# Add sticky session for websockets
- "traefik.http.services.boilerplate-api-socket-service.loadbalancer.sticky=true"
- "traefik.http.services.boilerplate-api-socket-service.loadbalancer.sticky.cookie.name=StickyCookie"
- "traefik.http.services.boilerplate-api-socket-service.loadbalancer.sticky.cookie.secure=true"
logging:
options:
max-size: "10m"
max-file: "3"
environment:
FORCE_COLOR: "true"
NEW_RELIC_LICENSE_KEY: "${NEW_RELIC_LICENSE_KEY}"
NEW_RELIC_APP_NAME: "Definya API"
networks:
- boilerplate-network
boilerplate-client:
image: definya/definya-team:client-latest
healthcheck:
test: ["CMD", "curl", "--fail", "http://localhost:8080"]
interval: 120s
timeout: 10s
retries: 3
logging:
options:
max-size: "10m"
max-file: "3"
deploy:
replicas: 1
restart_policy:
condition: on-failure
labels:
- "traefik.enable=true"
- "traefik.http.routers.boilerplate-client.rule=Host(`play.definya.com`)"
- "traefik.http.routers.boilerplate-client.entrypoints=websecure"
- "traefik.http.routers.boilerplate-client.tls.certresolver=myresolver"
- "traefik.http.services.boilerplate-client.loadbalancer.server.port=8080"
placement:
constraints:
- node.role == manager
networks:
- boilerplate-network
boilerplate-db:
image: mongo:7.0.0
command: mongod --port ${MONGO_PORT}
logging:
options:
max-size: "10m"
max-file: "3"
volumes:
- boilerplate-db-data:/data/db
- ./docker_scripts/:/docker-entrypoint-initdb.d
ports:
- "${MONGO_PORT}:${MONGO_PORT}"
environment:
MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE}
MONGO_PORT: ${MONGO_PORT}
MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
deploy: # db should be only on the manager node
placement:
constraints:
- node.role == manager
healthcheck:
test: ["CMD", "mongosh", "--port", "${MONGO_PORT}", "--eval", "db.runCommand({ ping: 1 })"]
interval: 30s
timeout: 15s
retries: 3
networks:
- boilerplate-network
boilerplate-redis:
image: redis:7.2.0
ports:
- "${REDIS_PORT}:${REDIS_PORT}"
volumes:
- boilerplate-redis-data:/data
- ./config/redis.conf:/usr/local/etc/redis/redis.conf
command: ["redis-server", "/usr/local/etc/redis/redis.conf", "--port", "${REDIS_PORT}"]
networks:
- boilerplate-network
deploy:
placement:
constraints:
- node.role == manager
healthcheck:
test: ["CMD", "redis-cli", "-p", "6380", "ping"]
interval: 30s
timeout: 15s
retries: 3
newrelic-infra:
image: newrelic/infrastructure:latest
environment:
NRIA_LICENSE_KEY: "${NEW_RELIC_LICENSE_KEY}"
NRIA_DISPLAY_NAME: "Boilerplate API Docker"
volumes:
- "/:/host:ro"
- "/var/run/docker.sock:/var/run/docker.sock"
deploy:
mode: global
resources:
limits:
memory: 128M
cap_add:
- SYS_PTRACE
networks:
boilerplate-network:
external: true
volumes:
boilerplate-db-data:
boilerplate-redis-data: