Compare commits

1 Commits
master ... main

Author SHA1 Message Date
Gardient
c9f07df262 fix things for docker compose 2021-12-19 20:27:13 +02:00
8 changed files with 67 additions and 14 deletions

View File

@@ -1,5 +1,8 @@
# Use the Python3.9.7 image
FROM python:3.9.7-bullseye
FROM python:3.10.1-bullseye
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.9.0/wait /wait
RUN chmod +x /wait
# Set the working directory to /app
WORKDIR /app
@@ -10,10 +13,7 @@ ADD . /app
# Install the dependencies
RUN pip install -r requirements/prod.txt
#make sure we have everything we need
RUN flask db upgrade
RUN flask seed
RUN flask setup-rabmq
RUN chmod +x scripts/entrypoint.sh
# run the command to start uWSGI
CMD ["uwsgi", "app.ini"]
CMD ["scripts/entrypoint.sh"]

View File

@@ -91,6 +91,7 @@ def register_shellcontext(app: Flask):
'TargetExchange': target_exchange.models.TargetExchange,
'Target': target.models.Target,
'Registration': registration.models.Registration,
'config': app.config,
}
app.shell_context_processor(shell_context)

View File

@@ -35,11 +35,11 @@ def get_list(exchange=None, target=None):
@use_kwargs(registration_schema)
@marshal_with(registration_schema)
def create(name, routing_key, targets):
target_ids = [t.id for t in targets]
target_ids = [t["id"] for t in targets]
db_targets = Target.query.filter(Target.id.in_(target_ids))
if len(db_targets) != len(targets):
xchange_ids = [t.id for t in db_targets]
not_found = ','.join([f'{t.name}({t.id})' for t in targets if t.id not in xchange_ids])
xchange_ids = [t["id"] for t in db_targets]
not_found = ','.join([f'{t["name"]}({t["id"]})' for t in targets if t["id"] not in xchange_ids])
raise BadRequestException(f"the target {not_found} could not be found")
registration = Registration(name=name, token=routing_key, targets=db_targets)
registration.save()

View File

@@ -32,9 +32,9 @@ def get_list(exchange=None):
@use_kwargs(target_schema)
@marshal_with(target_schema)
def create(name, routing_key, exchange):
xchange = TargetExchange.get_by_id(exchange.id)
xchange = TargetExchange.get_by_id(exchange["id"])
if xchange is None:
raise BadRequestException(f"the exchange {exchange.name}({exchange.id}) could not be found")
raise BadRequestException(f"the exchange {exchange['name']}({exchange['id']}) could not be found")
target = Target(name=name, routing_key=routing_key, target_exchange_id=xchange.id)
target.save()
return target

View File

@@ -1,7 +1,7 @@
[uwsgi]
wsgi-file = run.py
callable = app
socket = :8080
http = 0.0.0.0:8080
processes = 4
threads = 2
master = true

45
docker-compose.yml Normal file
View File

@@ -0,0 +1,45 @@
version: "3.9"
services:
rabbit:
image: rabbitmq:management
container_name: rabbit
volumes:
- rabbit_data:/var/lib/rabbitmq
expose:
- 5672
- 15672
ports:
- 15672:15762
networks:
net:
aliases:
- rabbit
api:
build: .
restart: always
environment:
FLASK_APP: run.py
SECRET_KEY: $API_SECRET
API_PASS: $API_PASS
RABBITMQ_HOST: rabbit
DB_PATH: /app/db/prod.db
WAIT_HOSTS: rabbit:15672
expose:
- 8080
ports:
- 8080:8080
networks:
net:
aliases:
- api
volumes:
- api_db:/app/db
depends_on:
- rabbit
volumes:
rabbit_data:
api_db:
networks:
net:

View File

@@ -6,8 +6,8 @@ from pika.adapters.blocking_connection import BlockingChannel
class RabbitMQ:
host: str
connection: pika.BlockingConnection
channel: BlockingChannel
connection: pika.BlockingConnection = None
channel: BlockingChannel = None
def __init__(self, app: Flask = None):
if app is not None:

7
scripts/entrypoint.sh Normal file
View File

@@ -0,0 +1,7 @@
#!/usr/bin/env bash
/wait
flask db upgrade
flask seed
flask setup-rabmq
uwsgi app.ini