Skip to content

Commit e120272

Browse files
authored
feat(docker): Allow multiple instances of scram to run locally (WIP) (#156)
Runs multiple instances of SCRAM (and associated services) locally using a shared postgres instance, similar to how one would run more than one SCRAM instance in prod. We are not using docker replicas the normal way since that doesn't really work well for running 2 separate instances of the same application (different env vars, etc).
1 parent 79bcffb commit e120272

11 files changed

Lines changed: 172 additions & 15 deletions

File tree

.envs/.local/.django

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ USE_DOCKER=yes
44
IPYTHONDIR=/app/.ipython
55
# Redis
66
# ------------------------------------------------------------------------------
7-
REDIS_URL=redis://redis:6379/0
8-
CELERY_BROKER_URL=REDIS_URL
97

108
# Django
119
DATABASE_URL=sqlite:///django.db
1210
DJANGO_SETTINGS_MODULE=config.settings.local
13-
14-
15-
SCRAM_HOSTNAME="localhost"

.envs/.local/.django-primary

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
REDIS_URL=redis://scram-redis-1:6379/0
2+
REDIS_HOST=scram-redis-1
3+
SCRAM_HOSTNAME="django"

.envs/.local/.django-secondary

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
REDIS_URL=redis://scram-redis-2:6379/0
2+
REDIS_HOST=scram-redis-2
3+
SCRAM_HOSTNAME="django-secondary"

.envs/.local/.translator

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
# Translator
22
# ------------------------------------------------------------------------------
3-
TRANSLATOR_HOSTNAME = localhost
4-
TRANSLATOR_URL = "ws://django:8000/ws/route_manager/translator_block/"
5-
SCRAM_HOSTNAME = "localhost"
63
LOG_LEVEL = "DEBUG"

.envs/.local/.translator-primary

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Translator
2+
# ------------------------------------------------------------------------------
3+
SCRAM_EVENTS_URL = "ws://django:8000/ws/route_manager/translator_block/"
4+
GOBGP_HOST = "scram-gobgp-1"
5+
GOBGP_PORT = 50051
6+
SCRAM_HOSTNAME = "django"

.envs/.local/.translator-secondary

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Translator
2+
# ------------------------------------------------------------------------------
3+
SCRAM_EVENTS_URL = "ws://django-secondary:8000/ws/route_manager/translator_block/"
4+
GOBGP_HOST = "scram-gobgp-secondary-1"
5+
GOBGP_PORT = 50051
6+
SCRAM_HOSTNAME = "django-secondary"

.vscode/launch.json

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"version": "0.2.0",
66
"configurations": [
77
{
8-
"name": "Django Debugger",
8+
"name": "Primary Django Debugger",
99
"type": "debugpy",
1010
"request": "attach",
1111
"connect": {
@@ -20,19 +20,49 @@
2020
]
2121
},
2222
{
23-
"name": "Translator Debugger",
23+
"name": "Secondary Django Debugger",
24+
"type": "debugpy",
25+
"request": "attach",
26+
"connect": {
27+
"host": "0.0.0.0",
28+
"port": 56781
29+
},
30+
"pathMappings": [
31+
{
32+
"localRoot": "${workspaceFolder}",
33+
"remoteRoot": "/app"
34+
}
35+
]
36+
},
37+
{
38+
"name": "Primary Translator Debugger",
2439
"type": "debugpy",
2540
"request": "attach",
2641
"connect": {
2742
"host": "0.0.0.0",
28-
"port": 56781
43+
"port": 56782
2944
},
3045
"pathMappings": [
3146
{
3247
"localRoot": "${workspaceFolder}/translator",
3348
"remoteRoot": "/app"
3449
}
3550
]
36-
}
51+
},
52+
{
53+
"name": "Secondary Translator Debugger",
54+
"type": "debugpy",
55+
"request": "attach",
56+
"connect": {
57+
"host": "0.0.0.0",
58+
"port": 56783
59+
},
60+
"pathMappings": [
61+
{
62+
"localRoot": "${workspaceFolder}/translator",
63+
"remoteRoot": "/app"
64+
}
65+
]
66+
}
3767
]
3868
}

compose.override.local.yml

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ services:
1515
- /tmp/profile_data:/tmp/profile_data
1616
env_file:
1717
- ./.envs/.local/.django
18+
- ./.envs/.local/.django-primary
1819
- ./.envs/.local/.postgres
1920
healthcheck:
2021
test: ["CMD", "curl", "-f", "http://django:8000/process_updates/"]
@@ -25,6 +26,29 @@ services:
2526
# This can be set to either `debugpy` or `pycharm-pydevd` currently.
2627
- DEBUG=${DEBUG:-}
2728

29+
django-secondary:
30+
platform: linux/amd64
31+
build:
32+
dockerfile: ./compose/local/django/Dockerfile
33+
image: scram_local_django
34+
volumes:
35+
- $CI_PROJECT_DIR:/app:z
36+
- /tmp/profile_data:/tmp/profile_data
37+
env_file:
38+
- ./.envs/.local/.django
39+
- ./.envs/.local/.django-secondary
40+
- ./.envs/.local/.postgres
41+
healthcheck:
42+
test: ["CMD", "curl", "-f", "http://django-secondary:8000/process_updates/"]
43+
ports:
44+
- "8000"
45+
- 56781:56780
46+
environment:
47+
# This can be set to either `debugpy` or `pycharm-pydevd` currently.
48+
- DEBUG=${DEBUG:-}
49+
deploy:
50+
replicas: 1
51+
2852
postgres:
2953
volumes:
3054
- local_postgres_data:/var/lib/postgresql/data:Z
@@ -56,25 +80,54 @@ services:
5680
redis:
5781
ports:
5882
- "6379"
83+
deploy:
84+
replicas: 2
5985

6086
gobgp:
6187
volumes:
6288
- $CI_PROJECT_DIR/gobgp_config:/config:z
6389
ports:
6490
- "179"
6591
- "50051"
92+
deploy:
93+
replicas: 1
94+
95+
96+
gobgp-secondary:
97+
volumes:
98+
- $CI_PROJECT_DIR/gobgp_config:/config:z
99+
ports:
100+
- "179"
101+
- "50051"
102+
deploy:
103+
replicas: 1
66104

67105
translator:
68106
volumes:
69107
- ./translator/tests/:/app/tests/
70108
env_file:
71109
- ./.envs/.local/.translator
110+
- ./.envs/.local/.translator-primary
72111
ports:
73-
- 56781:56781
112+
- 56782:56781
74113
environment:
75114
# This can be set to either `debugpy` or `pycharm-pydevd` currently.
76115
- DEBUG=${DEBUG:-}
77116

117+
translator-secondary:
118+
volumes:
119+
- ./translator/tests/:/app/tests/
120+
env_file:
121+
- ./.envs/.local/.translator
122+
- ./.envs/.local/.translator-secondary
123+
ports:
124+
- 56783:56781
125+
environment:
126+
# This can be set to either `debugpy` or `pycharm-pydevd` currently.
127+
- DEBUG=${DEBUG:-}
128+
deploy:
129+
replicas: 1
130+
78131
networks:
79132
default:
80133
ipam:

compose.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ services:
44
django:
55
build:
66
context: .
7+
dockerfile: ./compose/production/django/Dockerfile
78
depends_on:
89
postgres:
910
condition: service_healthy
@@ -15,13 +16,39 @@ services:
1516
- net.ipv6.conf.all.disable_ipv6=0
1617
command: /start
1718
healthcheck:
19+
test: ["CMD", "curl", "-f", "http://localhost:8000/process_updates/"]
1820
interval: 30s
1921
timeout: 30s
2022
start_period: 30s
2123
retries: 5
2224
deploy:
2325
replicas: ${DJANGO_REPLICAS:-1}
2426

27+
django-secondary:
28+
build:
29+
context: .
30+
dockerfile: ./compose/production/django/Dockerfile
31+
depends_on:
32+
postgres:
33+
condition: service_healthy
34+
redis:
35+
condition: service_healthy
36+
django:
37+
condition: service_healthy
38+
networks:
39+
default: {}
40+
sysctls:
41+
- net.ipv6.conf.all.disable_ipv6=0
42+
command: /start
43+
healthcheck:
44+
test: ["CMD", "curl", "-f", "http://localhost:8000/process_updates/"]
45+
interval: 30s
46+
timeout: 30s
47+
start_period: 30s
48+
retries: 5
49+
deploy:
50+
replicas: ${DJANGO_REPLICAS:-0}
51+
2552
postgres:
2653
build:
2754
context: .
@@ -42,6 +69,8 @@ services:
4269
- net.ipv6.conf.all.disable_ipv6=0
4370
healthcheck:
4471
test: ["CMD", "redis-cli", "--raw", "incr", "ping"]
72+
deploy:
73+
replicas: ${REDIS_REPLICAS:-1}
4574

4675
gobgp:
4776
image: jauderho/gobgp:v3.37.0
@@ -54,6 +83,17 @@ services:
5483
deploy:
5584
replicas: ${GOBGP_REPLICAS:-1}
5685

86+
gobgp-secondary:
87+
image: jauderho/gobgp:v3.33.0
88+
networks:
89+
default: {}
90+
sysctls:
91+
- net.ipv6.conf.all.disable_ipv6=0
92+
healthcheck:
93+
test: ["CMD", "gobgp", "global"]
94+
deploy:
95+
replicas: ${GOBGP_REPLICAS:-0}
96+
5797
translator:
5898
build:
5999
context: .
@@ -63,9 +103,29 @@ services:
63103
condition: service_healthy
64104
gobgp:
65105
condition: service_healthy
106+
django:
107+
condition: service_healthy
66108
networks:
67109
default: {}
68110
sysctls:
69111
- net.ipv6.conf.all.disable_ipv6=0
70112
deploy:
71113
replicas: ${TRANSLATOR_REPLICAS:-1}
114+
115+
translator-secondary:
116+
build:
117+
context: .
118+
dockerfile: ./compose/local/translator/Dockerfile
119+
depends_on:
120+
redis:
121+
condition: service_healthy
122+
gobgp-secondary:
123+
condition: service_healthy
124+
django-secondary:
125+
condition: service_healthy
126+
networks:
127+
default: {}
128+
sysctls:
129+
- net.ipv6.conf.all.disable_ipv6=0
130+
deploy:
131+
replicas: ${TRANSLATOR_REPLICAS:-0}

requirements/local.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ watchgod==0.8.2 # https://github.com/samuelcolvin/watchgod
88
# Testing
99
# ------------------------------------------------------------------------------
1010
django-stubs==1.11.0 # https://github.com/typeddjango/django-stubs
11-
pytest-sugar==0.9.6 # https://github.com/Frozenball/pytest-sugar
11+
pytest-sugar==1.1.1 # https://github.com/Frozenball/pytest-sugar
1212
behave-django==1.7.0 # https://github.com/behave/behave-django
1313

1414
# Documentation

0 commit comments

Comments
 (0)