From ab1e426a17d04598eed7338881e8c60968e83c3c Mon Sep 17 00:00:00 2001 From: Untone Date: Sat, 17 Feb 2024 13:31:05 +0300 Subject: [PATCH] refresh --- Dockerfile | 85 +++++------------------------------------------------ main.py | 5 ---- server.py | 19 ++++++++++++ settings.py | 2 +- 4 files changed, 27 insertions(+), 84 deletions(-) create mode 100644 server.py diff --git a/Dockerfile b/Dockerfile index fd62f39..05c855d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,83 +1,12 @@ -# Python builder stage -FROM python:alpine3.18 AS py-builder - -# Set the working directory +FROM python:alpine3.18 WORKDIR /app +COPY . /app -# Copy only the pyproject.toml files -COPY core/pyproject.toml /app/core/ -COPY chat/pyproject.toml /app/chat/ -COPY notifier/pyproject.toml /app/notifier/ +RUN apk update && apk add --no-cache git gcc curl postgresql-client +RUN curl -sSL https://install.python-poetry.org | python +ENV PATH="${PATH}:/root/.local/bin" +RUN poetry config virtualenvs.create false && poetry install --no-dev -# Install system dependencies -RUN apk update && apk add --no-cache \ - gcc \ - curl \ - git - -# Install Poetry -RUN curl -sSL https://install.python-poetry.org | python - - -# Configure environment variables and install Python dependencies -RUN echo "export PATH=$PATH:/root/.local/bin" >> ~/.bashrc && \ - . ~/.bashrc && \ - poetry config virtualenvs.create false && \ - poetry install --no-dev - -# Go builder stage -FROM golang:1.21.3-alpine3.18 AS go-builder - -# Set the working directory -WORKDIR /authorizer - -# Copy the entire submodule directory -COPY authorizer /authorizer - -# Fetch submodules -RUN apk update && apk add --no-cache git && \ - git submodule update --init --recursive - -ARG VERSION="latest" -ENV VERSION="$VERSION" - -# Build the server -RUN cd /authorizer && \ - make clean && make && \ - chmod 777 build/server - -# Final image -FROM alpine:3.18 - -# Set the working directory -WORKDIR /app - -# Copy built services from previous stages -COPY --from=go-builder /authorizer /app/authorizer - -# Copy Python dependencies from the py-builder stage -COPY --from=py-builder /root/.local /root/.local - -# Install system dependencies -RUN apk update && apk add --no-cache \ - gcc \ - curl \ - git \ - postgresql \ - supervisor \ - make \ - python3 \ - py3-pip - -# Install Python dependencies for gateway project -COPY . /app/ -RUN poetry config virtualenvs.create false && \ - poetry install --no-dev - -# Supervisor configuration -COPY supervisor/conf.d/* /etc/supervisor/conf.d/ - -# Expose ports for each service EXPOSE 8000 -# Command to start Supervisor -CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"] +CMD ["python", "server.py"] diff --git a/main.py b/main.py index 5b193c3..4e25d54 100644 --- a/main.py +++ b/main.py @@ -4,8 +4,6 @@ from os.path import exists from ariadne import load_schema_from_path, make_executable_schema from ariadne.asgi import GraphQL -from granian import Granian -from granian.server import Interfaces from sentry_sdk.integrations.aiohttp import AioHttpIntegration from sentry_sdk.integrations.ariadne import AriadneIntegration from sentry_sdk.integrations.redis import RedisIntegration @@ -57,6 +55,3 @@ async def shutdown(): app = Starlette(debug=True, on_startup=[start_up], on_shutdown=[shutdown]) app.mount('/', GraphQL(schema, debug=True)) - -if __name__ == '__main__': - Granian(target='main:app', port=8888, interface=Interfaces.ASGI, reload=True).serve() diff --git a/server.py b/server.py new file mode 100644 index 0000000..c381a4b --- /dev/null +++ b/server.py @@ -0,0 +1,19 @@ +from granian.constants import Interfaces +from granian.server import Granian + +from settings import PORT + + +if __name__ == '__main__': + print('[server] starting...') + + granian_instance = Granian( + 'main:app', + address='0.0.0.0', # noqa S104 + port=PORT, + threads=2, + websockets=False, + interface=Interfaces.ASGI, + reload=True + ) + granian_instance.serve() diff --git a/settings.py b/settings.py index aba17ad..fb39c84 100644 --- a/settings.py +++ b/settings.py @@ -1,7 +1,7 @@ from os import environ -PORT = 80 +PORT = 8000 REDIS_URL = environ.get('REDIS_URL') or 'redis://127.0.0.1' API_BASE = environ.get('API_BASE') or 'https://core.discours.io/' AUTH_URL = environ.get('AUTH_URL') or 'https://auth.discours.io/'