py-builder-too
This commit is contained in:
parent
70079c38ad
commit
899cb05c1b
|
@ -2,7 +2,7 @@ fail_fast: true
|
||||||
|
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v4.0.1
|
rev: v4.5.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: check-yaml
|
- id: check-yaml
|
||||||
- id: check-toml
|
- id: check-toml
|
||||||
|
@ -15,8 +15,7 @@ repos:
|
||||||
- id: check-merge-conflict
|
- id: check-merge-conflict
|
||||||
|
|
||||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
rev: v0.1.8
|
rev: v0.1.13
|
||||||
hooks:
|
hooks:
|
||||||
- id: ruff
|
- id: ruff
|
||||||
args: [--fix]
|
args: [--fix]
|
||||||
- id: ruff-format
|
|
||||||
|
|
87
Dockerfile
87
Dockerfile
|
@ -1,22 +1,83 @@
|
||||||
# Use an official Python runtime as a parent image
|
# Python builder stage
|
||||||
FROM python:slim
|
FROM python:alpine3.18 AS py-builder
|
||||||
|
|
||||||
# Set the working directory in the container to /app
|
# Set the working directory
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Add metadata to the image to describe that the container is listening on port 80
|
# Copy only the pyproject.toml files
|
||||||
EXPOSE 8000
|
COPY core/pyproject.toml /app/core/
|
||||||
|
COPY chat/pyproject.toml /app/chat/
|
||||||
|
COPY notifier/pyproject.toml /app/notifier/
|
||||||
|
|
||||||
# Copy the current directory contents into the container at /app
|
# Install system dependencies
|
||||||
COPY . /app
|
RUN apk update && apk add --no-cache \
|
||||||
|
gcc \
|
||||||
|
curl \
|
||||||
|
git
|
||||||
|
|
||||||
# Install any needed packages specified in pyproject.toml
|
# Install Poetry
|
||||||
RUN apt-get update && apt-get install -y gcc curl && \
|
RUN curl -sSL https://install.python-poetry.org | python -
|
||||||
curl -sSL https://install.python-poetry.org | python - && \
|
|
||||||
echo "export PATH=$PATH:/root/.local/bin" >> ~/.bashrc && \
|
# Configure environment variables and install Python dependencies
|
||||||
|
RUN echo "export PATH=$PATH:/root/.local/bin" >> ~/.bashrc && \
|
||||||
. ~/.bashrc && \
|
. ~/.bashrc && \
|
||||||
poetry config virtualenvs.create false && \
|
poetry config virtualenvs.create false && \
|
||||||
poetry install --no-dev
|
poetry install --no-dev
|
||||||
|
|
||||||
# Run server when the container launches
|
# Go builder stage
|
||||||
CMD granian --no-ws --host 0.0.0.0 --port 8000 --interface asgi main:app
|
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"]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "discoursio-inbox"
|
name = "discoursio-inbox"
|
||||||
version = "0.2.19"
|
version = "0.2.22"
|
||||||
description = "Inbox server for discours.io"
|
description = "Inbox server for discours.io"
|
||||||
authors = ["Tony Rewin <anton.rewin@gmail.com>"]
|
authors = ["Tony Rewin <anton.rewin@gmail.com>"]
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ python = "^3.12"
|
||||||
sentry-sdk = "^1.39.1"
|
sentry-sdk = "^1.39.1"
|
||||||
redis = { extras = ["hiredis"], version = "^5.0.1" }
|
redis = { extras = ["hiredis"], version = "^5.0.1" }
|
||||||
ariadne = "^0.21"
|
ariadne = "^0.21"
|
||||||
starlette = "^0.34.0"
|
starlette = "^0.36.1"
|
||||||
itsdangerous = "^2.1.2"
|
itsdangerous = "^2.1.2"
|
||||||
aiohttp = "^3.9.1"
|
aiohttp = "^3.9.1"
|
||||||
requests = "^2.31.0"
|
requests = "^2.31.0"
|
||||||
|
|
|
@ -39,15 +39,22 @@ async def check_auth(req) -> str | None:
|
||||||
}
|
}
|
||||||
# Asynchronous HTTP request to the authentication server
|
# Asynchronous HTTP request to the authentication server
|
||||||
async with ClientSession() as session:
|
async with ClientSession() as session:
|
||||||
async with session.post(AUTH_URL, json=gql, headers=headers) as response:
|
async with session.post(
|
||||||
|
AUTH_URL, json=gql, headers=headers
|
||||||
|
) as response:
|
||||||
if response.status == 200:
|
if response.status == 200:
|
||||||
data = await response.json()
|
data = await response.json()
|
||||||
errors = data.get('errors')
|
errors = data.get('errors')
|
||||||
if errors:
|
if errors:
|
||||||
logger.error(f'{errors}')
|
logger.error(f'{errors}')
|
||||||
else:
|
else:
|
||||||
user_id = data.get('data', {}).get(query_name, {}).get('claims', {}).get('sub')
|
user_id = (
|
||||||
logger.info(f'[services.auth] got user_id: {user_id}')
|
data.get('data', {})
|
||||||
|
.get(query_name, {})
|
||||||
|
.get('claims', {})
|
||||||
|
.get('sub')
|
||||||
|
)
|
||||||
|
logger.info(f'got user_id: {user_id}')
|
||||||
return user_id
|
return user_id
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Handling and logging exceptions during authentication check
|
# Handling and logging exceptions during authentication check
|
||||||
|
|
Loading…
Reference in New Issue
Block a user