Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9f07df262 |
12
Dockerfile
12
Dockerfile
@@ -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"]
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
2
app.ini
2
app.ini
@@ -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
45
docker-compose.yml
Normal 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:
|
||||
@@ -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
7
scripts/entrypoint.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
/wait
|
||||
flask db upgrade
|
||||
flask seed
|
||||
flask setup-rabmq
|
||||
uwsgi app.ini
|
||||
Reference in New Issue
Block a user