networking
This commit is contained in:
parent
c6383ffb31
commit
f26b530ff8
@ -5,7 +5,5 @@ from aiohttp import web
|
|||||||
|
|
||||||
|
|
||||||
async def delete_file(request):
|
async def delete_file(request):
|
||||||
if 'token' not in request.headers or request.headers['token'] != os.getenv('FS_TOKEN'):
|
|
||||||
return web.json_response({"success": False}, status=403)
|
|
||||||
remove("data/" + request.rel_url.query['id'])
|
remove("data/" + request.rel_url.query['id'])
|
||||||
return web.json_response({"success": True})
|
return web.json_response({"success": True})
|
||||||
|
@ -5,8 +5,6 @@ from aiohttp import web
|
|||||||
|
|
||||||
|
|
||||||
async def get_file(request):
|
async def get_file(request):
|
||||||
if 'token' not in request.headers or request.headers['token'] != os.getenv('FS_TOKEN'):
|
|
||||||
return web.json_response({"success": False}, status=403)
|
|
||||||
response = web.StreamResponse()
|
response = web.StreamResponse()
|
||||||
await response.prepare(request)
|
await response.prepare(request)
|
||||||
async with aiofiles.open("data/" + request.rel_url.query['id'], "rb") as fs:
|
async with aiofiles.open("data/" + request.rel_url.query['id'], "rb") as fs:
|
||||||
|
@ -7,8 +7,6 @@ import aiofiles
|
|||||||
|
|
||||||
|
|
||||||
async def upload_file(request):
|
async def upload_file(request):
|
||||||
if 'token' not in request.headers or request.headers['token'] != os.getenv('FS_TOKEN'):
|
|
||||||
return web.json_response({"success": False}, status=403)
|
|
||||||
file_id = await write_meta(request)
|
file_id = await write_meta(request)
|
||||||
async with aiofiles.open("data/" + str(file_id), "wb") as fs:
|
async with aiofiles.open("data/" + str(file_id), "wb") as fs:
|
||||||
await fs.write(await request.content.read())
|
await fs.write(await request.content.read())
|
||||||
|
@ -88,7 +88,7 @@ DATABASES = {
|
|||||||
"NAME": "sprint",
|
"NAME": "sprint",
|
||||||
"USER": "postgres",
|
"USER": "postgres",
|
||||||
"PASSWORD": os.getenv("DB_PASSWORD"),
|
"PASSWORD": os.getenv("DB_PASSWORD"),
|
||||||
"HOST": os.getenv("DB_HOST"),
|
"HOST": os.getenv("DB_HOST", "postgres"),
|
||||||
"PORT": 5432,
|
"PORT": 5432,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -144,10 +144,10 @@ for root in DATA_ROOT, EXTRA_FILES_ROOT:
|
|||||||
|
|
||||||
SOLUTIONS_ROOT = os.path.join(DATA_ROOT, "solutions")
|
SOLUTIONS_ROOT = os.path.join(DATA_ROOT, "solutions")
|
||||||
|
|
||||||
RABBIT_HOST = os.getenv("RABBIT_HOST")
|
RABBIT_HOST = os.getenv("RABBIT_HOST", "rabbitmq")
|
||||||
RABBIT_PORT = 5672
|
RABBIT_PORT = 5672
|
||||||
|
|
||||||
FS_HOST = "http://" + os.getenv("FS_HOST")
|
FS_HOST = "http://" + os.getenv("FS_HOST", "storage")
|
||||||
FS_PORT = 5555
|
FS_PORT = 5555
|
||||||
|
|
||||||
# Authentication backends
|
# Authentication backends
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import os
|
|
||||||
from random import choice
|
from random import choice
|
||||||
|
|
||||||
from requests import get, post
|
from requests import get, post
|
||||||
@ -10,19 +9,19 @@ from Sprint import settings
|
|||||||
def write_bytes(data: bytes):
|
def write_bytes(data: bytes):
|
||||||
url = settings.FS_HOST + ":" + str(settings.FS_PORT) + "/upload_file"
|
url = settings.FS_HOST + ":" + str(settings.FS_PORT) + "/upload_file"
|
||||||
print(url)
|
print(url)
|
||||||
return post(url, data=data, headers={'token': os.getenv('FS_TOKEN')}).json()["id"]
|
return post(url, data=data).json()["id"]
|
||||||
|
|
||||||
|
|
||||||
def get_bytes(num: int) -> bytes:
|
def get_bytes(num: int) -> bytes:
|
||||||
url = settings.FS_HOST + ":" + str(settings.FS_PORT) + "/get_file?id=" + str(num)
|
url = settings.FS_HOST + ":" + str(settings.FS_PORT) + "/get_file?id=" + str(num)
|
||||||
print(url)
|
print(url)
|
||||||
return get(url, headers={'token': os.getenv('FS_TOKEN')}).content
|
return get(url).content
|
||||||
|
|
||||||
|
|
||||||
def delete_file(num: int):
|
def delete_file(num: int):
|
||||||
url = settings.FS_HOST + ":" + str(settings.FS_PORT) + "/delete_file?id=" + str(num)
|
url = settings.FS_HOST + ":" + str(settings.FS_PORT) + "/delete_file?id=" + str(num)
|
||||||
print(url)
|
print(url)
|
||||||
post(url, headers={'token': os.getenv('FS_TOKEN')})
|
post(url)
|
||||||
|
|
||||||
|
|
||||||
def generate_token():
|
def generate_token():
|
||||||
|
@ -12,8 +12,8 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- /sprint-data/postgres-data:/var/lib/postgresql/data
|
- /sprint-data/postgres-data:/var/lib/postgresql/data
|
||||||
# - ./pg_hba.conf:/var/lib/postgresql/data/pg_hba.conf
|
# - ./pg_hba.conf:/var/lib/postgresql/data/pg_hba.conf
|
||||||
ports:
|
networks:
|
||||||
- "5432:5432"
|
- net
|
||||||
deploy:
|
deploy:
|
||||||
mode: replicated
|
mode: replicated
|
||||||
restart_policy:
|
restart_policy:
|
||||||
@ -25,15 +25,13 @@ services:
|
|||||||
migrations:
|
migrations:
|
||||||
image: mathwave/sprint-repo:sprint
|
image: mathwave/sprint-repo:sprint
|
||||||
command: ./manage.py migrate
|
command: ./manage.py migrate
|
||||||
|
networks:
|
||||||
|
- net
|
||||||
environment:
|
environment:
|
||||||
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
||||||
DB_HOST: $DB_HOST
|
|
||||||
DB_PASSWORD: $DB_PASSWORD
|
DB_PASSWORD: $DB_PASSWORD
|
||||||
RABBIT_HOST: $RABBIT_HOST
|
|
||||||
FS_HOST: $FS_HOST
|
|
||||||
DEBUG: $DEBUG
|
DEBUG: $DEBUG
|
||||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
||||||
FS_TOKEN: $FS_TOKEN
|
|
||||||
deploy:
|
deploy:
|
||||||
mode: replicated
|
mode: replicated
|
||||||
restart_policy:
|
restart_policy:
|
||||||
@ -41,15 +39,13 @@ services:
|
|||||||
|
|
||||||
collect_static:
|
collect_static:
|
||||||
image: mathwave/sprint-repo:sprint
|
image: mathwave/sprint-repo:sprint
|
||||||
|
networks:
|
||||||
|
- net
|
||||||
environment:
|
environment:
|
||||||
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
||||||
DB_HOST: $DB_HOST
|
|
||||||
DB_PASSWORD: $DB_PASSWORD
|
DB_PASSWORD: $DB_PASSWORD
|
||||||
RABBIT_HOST: $RABBIT_HOST
|
|
||||||
FS_HOST: $FS_HOST
|
|
||||||
DEBUG: $DEBUG
|
DEBUG: $DEBUG
|
||||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
||||||
FS_TOKEN: $FS_TOKEN
|
|
||||||
volumes:
|
volumes:
|
||||||
- /sprint-data/static:/usr/src/app/static
|
- /sprint-data/static:/usr/src/app/static
|
||||||
command: ./manage.py collectstatic --noinput
|
command: ./manage.py collectstatic --noinput
|
||||||
@ -60,15 +56,13 @@ services:
|
|||||||
|
|
||||||
web:
|
web:
|
||||||
image: mathwave/sprint-repo:sprint
|
image: mathwave/sprint-repo:sprint
|
||||||
|
networks:
|
||||||
|
- net
|
||||||
environment:
|
environment:
|
||||||
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
||||||
DB_HOST: $DB_HOST
|
|
||||||
DB_PASSWORD: $DB_PASSWORD
|
DB_PASSWORD: $DB_PASSWORD
|
||||||
RABBIT_HOST: $RABBIT_HOST
|
|
||||||
FS_HOST: $FS_HOST
|
|
||||||
DEBUG: $DEBUG
|
DEBUG: $DEBUG
|
||||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
||||||
FS_TOKEN: $FS_TOKEN
|
|
||||||
volumes:
|
volumes:
|
||||||
- /sprint-data/static:/usr/src/app/static
|
- /sprint-data/static:/usr/src/app/static
|
||||||
command: ./manage.py runserver 0.0.0.0:80 --noreload --insecure
|
command: ./manage.py runserver 0.0.0.0:80 --noreload --insecure
|
||||||
@ -84,18 +78,14 @@ services:
|
|||||||
|
|
||||||
storage:
|
storage:
|
||||||
image: mathwave/sprint-repo:sprint
|
image: mathwave/sprint-repo:sprint
|
||||||
|
networks:
|
||||||
|
- net
|
||||||
command: ./manage.py storage
|
command: ./manage.py storage
|
||||||
environment:
|
environment:
|
||||||
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
||||||
DB_HOST: $DB_HOST
|
|
||||||
DB_PASSWORD: $DB_PASSWORD
|
DB_PASSWORD: $DB_PASSWORD
|
||||||
RABBIT_HOST: $RABBIT_HOST
|
|
||||||
FS_HOST: $FS_HOST
|
|
||||||
DEBUG: $DEBUG
|
DEBUG: $DEBUG
|
||||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
||||||
FS_TOKEN: $FS_TOKEN
|
|
||||||
ports:
|
|
||||||
- "5555:5555"
|
|
||||||
volumes:
|
volumes:
|
||||||
- /sprint-data/data:/usr/src/app/data
|
- /sprint-data/data:/usr/src/app/data
|
||||||
deploy:
|
deploy:
|
||||||
@ -108,16 +98,14 @@ services:
|
|||||||
|
|
||||||
health_check:
|
health_check:
|
||||||
image: mathwave/sprint-repo:sprint
|
image: mathwave/sprint-repo:sprint
|
||||||
|
networks:
|
||||||
|
- net
|
||||||
command: ./manage.py health_check
|
command: ./manage.py health_check
|
||||||
environment:
|
environment:
|
||||||
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
||||||
DB_HOST: $DB_HOST
|
|
||||||
DB_PASSWORD: $DB_PASSWORD
|
DB_PASSWORD: $DB_PASSWORD
|
||||||
RABBIT_HOST: $RABBIT_HOST
|
|
||||||
FS_HOST: $FS_HOST
|
|
||||||
DEBUG: $DEBUG
|
DEBUG: $DEBUG
|
||||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
||||||
FS_TOKEN: $FS_TOKEN
|
|
||||||
deploy:
|
deploy:
|
||||||
mode: replicated
|
mode: replicated
|
||||||
restart_policy:
|
restart_policy:
|
||||||
@ -128,15 +116,13 @@ services:
|
|||||||
|
|
||||||
bot:
|
bot:
|
||||||
image: mathwave/sprint-repo:sprint
|
image: mathwave/sprint-repo:sprint
|
||||||
|
networks:
|
||||||
|
- net
|
||||||
environment:
|
environment:
|
||||||
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
||||||
DB_HOST: $DB_HOST
|
|
||||||
DB_PASSWORD: $DB_PASSWORD
|
DB_PASSWORD: $DB_PASSWORD
|
||||||
RABBIT_HOST: $RABBIT_HOST
|
|
||||||
FS_HOST: $FS_HOST
|
|
||||||
DEBUG: $DEBUG
|
DEBUG: $DEBUG
|
||||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
||||||
FS_TOKEN: $FS_TOKEN
|
|
||||||
command: ./manage.py bot
|
command: ./manage.py bot
|
||||||
deploy:
|
deploy:
|
||||||
mode: replicated
|
mode: replicated
|
||||||
@ -148,15 +134,13 @@ services:
|
|||||||
|
|
||||||
loop:
|
loop:
|
||||||
image: mathwave/sprint-repo:sprint
|
image: mathwave/sprint-repo:sprint
|
||||||
|
networks:
|
||||||
|
- net
|
||||||
environment:
|
environment:
|
||||||
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
||||||
DB_HOST: $DB_HOST
|
|
||||||
DB_PASSWORD: $DB_PASSWORD
|
DB_PASSWORD: $DB_PASSWORD
|
||||||
RABBIT_HOST: $RABBIT_HOST
|
|
||||||
FS_HOST: $FS_HOST
|
|
||||||
DEBUG: $DEBUG
|
DEBUG: $DEBUG
|
||||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
||||||
FS_TOKEN: $FS_TOKEN
|
|
||||||
command: ./manage.py loop
|
command: ./manage.py loop
|
||||||
deploy:
|
deploy:
|
||||||
mode: replicated
|
mode: replicated
|
||||||
@ -171,6 +155,8 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "15672:15672"
|
- "15672:15672"
|
||||||
- "5672:5672"
|
- "5672:5672"
|
||||||
|
networks:
|
||||||
|
- net
|
||||||
deploy:
|
deploy:
|
||||||
mode: replicated
|
mode: replicated
|
||||||
restart_policy:
|
restart_policy:
|
||||||
@ -181,16 +167,14 @@ services:
|
|||||||
|
|
||||||
worker:
|
worker:
|
||||||
image: mathwave/sprint-repo:sprint
|
image: mathwave/sprint-repo:sprint
|
||||||
|
networks:
|
||||||
|
- net
|
||||||
command: ./manage.py receive
|
command: ./manage.py receive
|
||||||
environment:
|
environment:
|
||||||
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
||||||
DB_HOST: $DB_HOST
|
|
||||||
DB_PASSWORD: $DB_PASSWORD
|
DB_PASSWORD: $DB_PASSWORD
|
||||||
RABBIT_HOST: $RABBIT_HOST
|
|
||||||
FS_HOST: $FS_HOST
|
|
||||||
DEBUG: $DEBUG
|
DEBUG: $DEBUG
|
||||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
||||||
FS_TOKEN: $FS_TOKEN
|
|
||||||
volumes:
|
volumes:
|
||||||
- /sprint-data/solutions:/usr/src/app/solutions
|
- /sprint-data/solutions:/usr/src/app/solutions
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
@ -205,16 +189,14 @@ services:
|
|||||||
|
|
||||||
file_generator:
|
file_generator:
|
||||||
image: mathwave/sprint-repo:sprint
|
image: mathwave/sprint-repo:sprint
|
||||||
|
networks:
|
||||||
|
- net
|
||||||
command: ./manage.py file_generator
|
command: ./manage.py file_generator
|
||||||
environment:
|
environment:
|
||||||
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
||||||
DB_HOST: $DB_HOST
|
|
||||||
DB_PASSWORD: $DB_PASSWORD
|
DB_PASSWORD: $DB_PASSWORD
|
||||||
RABBIT_HOST: $RABBIT_HOST
|
|
||||||
FS_HOST: $FS_HOST
|
|
||||||
DEBUG: $DEBUG
|
DEBUG: $DEBUG
|
||||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
||||||
FS_TOKEN: $FS_TOKEN
|
|
||||||
deploy:
|
deploy:
|
||||||
mode: replicated
|
mode: replicated
|
||||||
replicas: 1
|
replicas: 1
|
||||||
@ -226,16 +208,14 @@ services:
|
|||||||
|
|
||||||
notification_manager:
|
notification_manager:
|
||||||
image: mathwave/sprint-repo:sprint
|
image: mathwave/sprint-repo:sprint
|
||||||
|
networks:
|
||||||
|
- net
|
||||||
command: ./manage.py notification_manager
|
command: ./manage.py notification_manager
|
||||||
environment:
|
environment:
|
||||||
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
||||||
DB_HOST: $DB_HOST
|
|
||||||
DB_PASSWORD: $DB_PASSWORD
|
DB_PASSWORD: $DB_PASSWORD
|
||||||
RABBIT_HOST: $RABBIT_HOST
|
|
||||||
FS_HOST: $FS_HOST
|
|
||||||
DEBUG: $DEBUG
|
DEBUG: $DEBUG
|
||||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
||||||
FS_TOKEN: $FS_TOKEN
|
|
||||||
deploy:
|
deploy:
|
||||||
mode: replicated
|
mode: replicated
|
||||||
replicas: 1
|
replicas: 1
|
||||||
@ -247,17 +227,19 @@ services:
|
|||||||
|
|
||||||
apply-languages:
|
apply-languages:
|
||||||
image: mathwave/sprint-repo:sprint
|
image: mathwave/sprint-repo:sprint
|
||||||
|
networks:
|
||||||
|
- net
|
||||||
command: ./manage.py apply_languages
|
command: ./manage.py apply_languages
|
||||||
environment:
|
environment:
|
||||||
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
|
||||||
DB_HOST: $DB_HOST
|
|
||||||
DB_PASSWORD: $DB_PASSWORD
|
DB_PASSWORD: $DB_PASSWORD
|
||||||
RABBIT_HOST: $RABBIT_HOST
|
|
||||||
FS_HOST: $FS_HOST
|
|
||||||
DEBUG: $DEBUG
|
DEBUG: $DEBUG
|
||||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
TELEGRAM_TOKEN: $TELEGRAM_TOKEN
|
||||||
FS_TOKEN: $FS_TOKEN
|
|
||||||
deploy:
|
deploy:
|
||||||
mode: replicated
|
mode: replicated
|
||||||
restart_policy:
|
restart_policy:
|
||||||
condition: on-failure
|
condition: on-failure
|
||||||
|
|
||||||
|
networks:
|
||||||
|
net:
|
||||||
|
driver: overlay
|
||||||
|
Loading…
Reference in New Issue
Block a user