Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
362b58b
add deployment docker compose file
AfeezGL Mar 24, 2025
a90a9b5
make migrations
AfeezGL Mar 24, 2025
7f3e6b6
add fly.toml
AfeezGL Mar 25, 2025
4b6a398
update flyio config
AfeezGL Mar 25, 2025
0be69b5
update flyio config
AfeezGL Mar 25, 2025
fc1c955
update deployment config
AfeezGL Mar 25, 2025
66f7a93
update flyio config
AfeezGL Mar 25, 2025
6b183b7
update flyio config
AfeezGL Mar 25, 2025
c2d14de
update flyio config
AfeezGL Mar 25, 2025
a39d3e3
update flyio config to specify build target
AfeezGL Mar 25, 2025
327713b
replace fly.toml with a simplified configuration for Fly.io deployment
AfeezGL Mar 25, 2025
7a5be65
update Dockerfile to install specific setuptools version and switch t…
AfeezGL Mar 25, 2025
c1dc351
update Fly.io configuration for integraflow-backend and adjust Gunico…
AfeezGL Mar 25, 2025
e2c5506
add base64 decoding support in JWTManager and utility function for va…
AfeezGL Mar 25, 2025
6221364
reduce Gunicorn worker count from 4 to 2 in supervisord configuration
AfeezGL Mar 25, 2025
f607e54
add debug print statement for decoded PEM in JWTManager
AfeezGL Mar 25, 2025
858323b
update Fly.io configuration to include internal port and force HTTPS;…
AfeezGL Mar 25, 2025
13e806a
remove HTTP service configuration from Fly.io settings
AfeezGL Mar 25, 2025
de01e2e
update Fly.io configuration to define internal port and set up HTTP a…
AfeezGL Mar 25, 2025
4e09abb
expose port 8000 in Dockerfile for application access
AfeezGL Mar 26, 2025
d288a8d
refactor Fly.io configuration to use [http_service] section and enfor…
AfeezGL Mar 26, 2025
2b2c5c6
refactor GoogleUserAuth to use client configuration instead of secret…
AfeezGL Mar 26, 2025
7fdd319
refactor GoogleUserAuth to load client credentials from JSON
AfeezGL Mar 26, 2025
4e55a86
remove unused docker-compose-deploy.yml file
AfeezGL Mar 26, 2025
c1bc012
add logging for error handling in GoogleUserAuth
AfeezGL Mar 28, 2025
2aad589
enable jobs for celery
AfeezGL Apr 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@ RUN apt-get clean && rm -rf /var/lib/apt/lists/*

RUN pip install --upgrade pip

RUN pip install poetry
# Install setuptools==68.2.2 to avoid the following error:
# ERROR: setuptools==58.1.0 is used in combination with setuptools-scm>=8.x
RUN pip install setuptools==68.2.2

WORKDIR /backend

COPY requirements.txt requirements.txt
COPY requirements_dev.txt requirements_dev.txt
COPY poetry.lock poetry.lock
COPY pyproject.toml pyproject.toml

RUN poetry install --no-interaction
RUN pip install -r requirements.txt

COPY . .

COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

EXPOSE 8000

CMD ["/usr/bin/supervisord"]
18 changes: 18 additions & 0 deletions backend/fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

app = "integraflow-backend"
primary_region = "fra"
swap_size_mb = 512

[build]
dockerfile = "Dockerfile"

[[vm]]
size = "shared-cpu-2x"
memory = "512mb"

[http_service]
internal_port = 8000
force_https = true
auto_stop_machines = "stop"
auto_start_machines = true
min_machines_running = 1
8 changes: 6 additions & 2 deletions backend/integraflow/core/jwt_manager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
import json
import logging
from os.path import exists, join
Expand All @@ -15,7 +16,7 @@
from jwt import api_jws
from jwt.algorithms import RSAAlgorithm

from .utils import build_absolute_uri, get_domain
from .utils import build_absolute_uri, get_domain, is_base_64

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -92,7 +93,10 @@ def get_private_key(cls) -> rsa.RSAPrivateKey:
@classmethod
def _get_private_key(cls, pem: Union[str, bytes]) -> rsa.RSAPrivateKey:
if isinstance(pem, str):
pem = pem.encode("utf-8")
if is_base_64(pem):
pem = base64.b64decode(pem)
else:
pem = pem.encode("utf-8")

password: Union[str, bytes, None] = settings.RSA_PRIVATE_PASSWORD
if isinstance(password, str):
Expand Down
14 changes: 12 additions & 2 deletions backend/integraflow/core/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import base64
import binascii
import datetime
import secrets
import socket
import string
import pytz
from random import choice
from typing import (
TYPE_CHECKING,
Expand All @@ -12,10 +13,11 @@
Optional,
Tuple,
TypeVar,
Union
Union,
)
from urllib.parse import urljoin, urlparse

import pytz
from celery.utils.log import get_task_logger
from django.conf import settings
from django.db import IntegrityError, transaction
Expand Down Expand Up @@ -382,3 +384,11 @@ def __eq__(self, other):
self.name == other.name and self.expression == other.expression
)
return super().__eq__(other)


def is_base_64(text: str):
try:
base64.b64decode(text, validate=True)
return True
except binascii.Error:
return False
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json
import logging
from typing import Dict, cast

import graphene
Expand All @@ -20,6 +22,8 @@

GOOGLE_AUTH_CLIENT_CREDENTIALS = settings.GOOGLE_AUTH_CLIENT_CREDENTIALS

logger = logging.getLogger(__name__)


class GoogleUserAuth(BaseMutation):
"""
Expand Down Expand Up @@ -67,8 +71,8 @@ class Meta:
@classmethod
def _get_credentials(cls, code: str) -> Dict[str, str]:
try:
flow = Flow.from_client_secrets_file(
GOOGLE_AUTH_CLIENT_CREDENTIALS,
flow = Flow.from_client_config(
json.loads(GOOGLE_AUTH_CLIENT_CREDENTIALS),
scopes=[
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/userinfo.email",
Expand All @@ -83,7 +87,9 @@ def _get_credentials(cls, code: str) -> Dict[str, str]:
clock_skew_in_seconds=10
)
return credentials # type: ignore
except Exception:
except Exception as err:
logger.exception(f"Google auth error: {err}")

raise ValidationError(
"Failed to fetch user info from google auth.",
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.23 on 2025-03-24 19:13

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('survey', '0014_auto_20240511_2019'),
]

operations = [
migrations.AlterModelOptions(
name='surveyresponse',
options={'ordering': ['-created_at'], 'verbose_name': 'SurveyResponse', 'verbose_name_plural': 'SurveyResponses'},
),
]
4 changes: 2 additions & 2 deletions backend/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ stdout_logfile_maxbytes=0
redirect_stderr=true

[program:django]
command=gunicorn --bind :8000 --workers 8 --worker-class integraflow.asgi.gunicorn_worker.UvicornWorker integraflow.asgi:application
command=gunicorn --bind :8000 --workers 2 --worker-class integraflow.asgi.gunicorn_worker.UvicornWorker integraflow.asgi:application
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true

[program:celery]
command=celery -A integraflow worker --loglevel=info
command=celery -A integraflow worker --loglevel=info --beat
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true