Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .envs/.local/.django
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ USE_DOCKER=yes
IPYTHONDIR=/app/.ipython
# Redis
# ------------------------------------------------------------------------------
REDIS_URL=redis://redis:6379/0
CELERY_BROKER_URL=REDIS_URL

# Django
DATABASE_URL=sqlite:///django.db
DJANGO_SETTINGS_MODULE=config.settings.local


SCRAM_HOSTNAME="localhost"
3 changes: 3 additions & 0 deletions .envs/.local/.django-primary
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
REDIS_URL=redis://scram-redis-1:6379/0
REDIS_HOST=scram-redis-1
SCRAM_HOSTNAME="django"
3 changes: 3 additions & 0 deletions .envs/.local/.django-secondary
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
REDIS_URL=redis://scram-redis-2:6379/0
REDIS_HOST=scram-redis-2
SCRAM_HOSTNAME="django-secondary"
3 changes: 0 additions & 3 deletions .envs/.local/.translator
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Translator
# ------------------------------------------------------------------------------
TRANSLATOR_HOSTNAME = localhost
TRANSLATOR_URL = "ws://django:8000/ws/route_manager/translator_block/"
SCRAM_HOSTNAME = "localhost"
LOG_LEVEL = "DEBUG"
6 changes: 6 additions & 0 deletions .envs/.local/.translator-primary
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Translator
# ------------------------------------------------------------------------------
SCRAM_EVENTS_URL = "ws://django:8000/ws/route_manager/translator_block/"
GOBGP_HOST = "scram-gobgp-1"
GOBGP_PORT = 50051
SCRAM_HOSTNAME = "django"
6 changes: 6 additions & 0 deletions .envs/.local/.translator-secondary
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Translator
# ------------------------------------------------------------------------------
SCRAM_EVENTS_URL = "ws://django-secondary:8000/ws/route_manager/translator_block/"
GOBGP_HOST = "scram-gobgp-secondary-1"
GOBGP_PORT = 50051
SCRAM_HOSTNAME = "django-secondary"
38 changes: 34 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"version": "0.2.0",
"configurations": [
{
"name": "Django Debugger",
"name": "Primary Django Debugger",
"type": "debugpy",
"request": "attach",
"connect": {
Expand All @@ -20,19 +20,49 @@
]
},
{
"name": "Translator Debugger",
"name": "Secondary Django Debugger",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "0.0.0.0",
"port": 56781
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app"
}
]
},
{
"name": "Primary Translator Debugger",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "0.0.0.0",
"port": 56781
"port": 56782
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}/translator",
"remoteRoot": "/app"
}
]
}
},
{
"name": "Secondary Translator Debugger",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "0.0.0.0",
"port": 56783
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}/translator",
"remoteRoot": "/app"
}
]
}
]
}
55 changes: 54 additions & 1 deletion compose.override.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ services:
- /tmp/profile_data:/tmp/profile_data
env_file:
- ./.envs/.local/.django
- ./.envs/.local/.django-primary
- ./.envs/.local/.postgres
healthcheck:
test: ["CMD", "curl", "-f", "http://django:8000/process_updates/"]
Expand All @@ -25,6 +26,29 @@ services:
# This can be set to either `debugpy` or `pycharm-pydevd` currently.
- DEBUG=${DEBUG:-}

django-secondary:
platform: linux/amd64
build:
dockerfile: ./compose/local/django/Dockerfile
image: scram_local_django
volumes:
- $CI_PROJECT_DIR:/app:z
- /tmp/profile_data:/tmp/profile_data
env_file:
- ./.envs/.local/.django
- ./.envs/.local/.django-secondary
- ./.envs/.local/.postgres
healthcheck:
test: ["CMD", "curl", "-f", "http://django-secondary:8000/process_updates/"]
ports:
- "8000"
- 56781:56780
environment:
# This can be set to either `debugpy` or `pycharm-pydevd` currently.
- DEBUG=${DEBUG:-}
deploy:
replicas: 1

postgres:
volumes:
- local_postgres_data:/var/lib/postgresql/data:Z
Expand Down Expand Up @@ -56,25 +80,54 @@ services:
redis:
ports:
- "6379"
deploy:
replicas: 2

gobgp:
volumes:
- $CI_PROJECT_DIR/gobgp_config:/config:z
ports:
- "179"
- "50051"
deploy:
replicas: 1


gobgp-secondary:
volumes:
- $CI_PROJECT_DIR/gobgp_config:/config:z
ports:
- "179"
- "50051"
deploy:
replicas: 1

translator:
volumes:
- ./translator/tests/:/app/tests/
env_file:
- ./.envs/.local/.translator
- ./.envs/.local/.translator-primary
ports:
- 56781:56781
- 56782:56781
environment:
# This can be set to either `debugpy` or `pycharm-pydevd` currently.
- DEBUG=${DEBUG:-}

translator-secondary:
volumes:
- ./translator/tests/:/app/tests/
env_file:
- ./.envs/.local/.translator
- ./.envs/.local/.translator-secondary
ports:
- 56783:56781
environment:
# This can be set to either `debugpy` or `pycharm-pydevd` currently.
- DEBUG=${DEBUG:-}
deploy:
replicas: 1

networks:
default:
ipam:
Expand Down
60 changes: 60 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
django:
build:
context: .
dockerfile: ./compose/production/django/Dockerfile
depends_on:
postgres:
condition: service_healthy
Expand All @@ -15,13 +16,39 @@ services:
- net.ipv6.conf.all.disable_ipv6=0
command: /start
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/process_updates/"]
interval: 30s
timeout: 30s
start_period: 30s
retries: 5
deploy:
replicas: ${DJANGO_REPLICAS:-1}

django-secondary:
build:
context: .
dockerfile: ./compose/production/django/Dockerfile
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
django:
condition: service_healthy
networks:
default: {}
sysctls:
- net.ipv6.conf.all.disable_ipv6=0
command: /start
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/process_updates/"]
interval: 30s
timeout: 30s
start_period: 30s
retries: 5
deploy:
replicas: ${DJANGO_REPLICAS:-0}

postgres:
build:
context: .
Expand All @@ -42,6 +69,8 @@ services:
- net.ipv6.conf.all.disable_ipv6=0
healthcheck:
test: ["CMD", "redis-cli", "--raw", "incr", "ping"]
deploy:
replicas: ${REDIS_REPLICAS:-1}

gobgp:
image: jauderho/gobgp:v3.37.0
Expand All @@ -54,6 +83,17 @@ services:
deploy:
replicas: ${GOBGP_REPLICAS:-1}

gobgp-secondary:
image: jauderho/gobgp:v3.33.0
networks:
default: {}
sysctls:
- net.ipv6.conf.all.disable_ipv6=0
healthcheck:
test: ["CMD", "gobgp", "global"]
deploy:
replicas: ${GOBGP_REPLICAS:-0}

translator:
build:
context: .
Expand All @@ -63,9 +103,29 @@ services:
condition: service_healthy
gobgp:
condition: service_healthy
django:
condition: service_healthy
networks:
default: {}
sysctls:
- net.ipv6.conf.all.disable_ipv6=0
deploy:
replicas: ${TRANSLATOR_REPLICAS:-1}

translator-secondary:
build:
context: .
dockerfile: ./compose/local/translator/Dockerfile
depends_on:
redis:
condition: service_healthy
gobgp-secondary:
condition: service_healthy
django-secondary:
condition: service_healthy
networks:
default: {}
sysctls:
- net.ipv6.conf.all.disable_ipv6=0
deploy:
replicas: ${TRANSLATOR_REPLICAS:-0}
2 changes: 1 addition & 1 deletion requirements/local.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ watchgod==0.8.2 # https://github.com/samuelcolvin/watchgod
# Testing
# ------------------------------------------------------------------------------
django-stubs==1.11.0 # https://github.com/typeddjango/django-stubs
pytest-sugar==0.9.6 # https://github.com/Frozenball/pytest-sugar
pytest-sugar==1.1.1 # https://github.com/Frozenball/pytest-sugar
behave-django==1.7.0 # https://github.com/behave/behave-django

# Documentation
Expand Down
6 changes: 5 additions & 1 deletion translator/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
from grpc import RpcError

LOG_LEVEL = getenv("LOG_LEVEL", "INFO")
GOBGP_HOST = getenv("GOBGP_HOST", "gobgp")
GOBGP_PORT = getenv("GOBGP_PORT", "50051")
GOBGP_URL = GOBGP_HOST + ":" + GOBGP_PORT

logging.basicConfig(level=LOG_LEVEL)
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -107,7 +110,8 @@ async def process(message, websocket, g):

async def websocket_loop():
"""Connect to the websocket and start listening for messages for Gobgp."""
g = GoBGP("gobgp:50051")
logger.info("connecting to gobgp at %s", GOBGP_URL)
g = GoBGP(GOBGP_URL)
async for websocket in websockets.connect(url):
try:
async for message in websocket:
Expand Down
Loading