From 0031b7ec627342d8483b334e370e945fe4727e49 Mon Sep 17 00:00:00 2001 From: aradhyacp Date: Thu, 1 Jan 2026 02:48:22 +0530 Subject: [PATCH 1/6] chore: stop tracking .env, add to gitignore --- .env | 15 --------------- .gitignore | 1 - 2 files changed, 16 deletions(-) delete mode 100644 .env diff --git a/.env b/.env deleted file mode 100644 index 4116ee9..0000000 --- a/.env +++ /dev/null @@ -1,15 +0,0 @@ -MAX_CONTENT_LENGTH=1048576 -MAX_PENDING_TIME=600 -MAX_STORE_TIME=259200 -FLASK_DEBUG=0 -FLASK_ENV=production -DB_URI=postgresql://aperiuser:aperipass@postgres:5432/aperisolve -RQ_DASHBOARD_REDIS_URL=redis://redis:6379/0 -POSTGRES_DB=aperisolve -POSTGRES_USER=aperiuser -POSTGRES_PASSWORD=aperipass -SENTRY_DSN=https://your-dsn@sentry.io/project-id -SENTRY_TRACES_SAMPLE_RATE=0.1 -SENTRY_PROFILES_SAMPLE_RATE=0.1 -SENTRY_RELEASE=1.0.0 -ENVIRONMENT=production \ No newline at end of file diff --git a/.gitignore b/.gitignore index 5482ea4..646de31 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ __pycache__/ .mypy_cache/ results/ -.env From 49ad16f02da9a1b5638ff5d7d99f5c8ccb772186 Mon Sep 17 00:00:00 2001 From: aradhyacp Date: Thu, 1 Jan 2026 02:49:25 +0530 Subject: [PATCH 2/6] chore: add .env to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 646de31..8a70dc2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # Python +.env __pycache__/ .mypy_cache/ results/ From 676f655f0deb637cb8549c8cb9a5f83baf9ad6bb Mon Sep 17 00:00:00 2001 From: aradhyacp Date: Thu, 1 Jan 2026 02:54:50 +0530 Subject: [PATCH 3/6] chore: add example environment configuration file --- .env.example | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..b4bc151 --- /dev/null +++ b/.env.example @@ -0,0 +1,15 @@ +MAX_CONTENT_LENGTH=1048576 +MAX_PENDING_TIME=600 +MAX_STORE_TIME=259200 +FLASK_DEBUG=0 +FLASK_ENV=development +DB_URI=postgresql://aperiuser:aperipass@postgres:5432/aperisolve +RQ_DASHBOARD_REDIS_URL=redis://redis:6379/0 +POSTGRES_DB=aperisolve +POSTGRES_USER=aperiuser +POSTGRES_PASSWORD=aperipass +SENTRY_DSN=https://your-dsn@sentry.io/project-id +SENTRY_TRACES_SAMPLE_RATE=0.1 +SENTRY_PROFILES_SAMPLE_RATE=0.1 +SENTRY_RELEASE=1.0.0 +ENVIRONMENT=development \ No newline at end of file From 52b084321c53202a298c42e5aa9d134002bfbf15 Mon Sep 17 00:00:00 2001 From: aradhyacp Date: Thu, 1 Jan 2026 02:55:09 +0530 Subject: [PATCH 4/6] chore: update env_file references to use .env.example in compose.dev.yml --- compose.dev.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compose.dev.yml b/compose.dev.yml index e23163d..0b19a14 100644 --- a/compose.dev.yml +++ b/compose.dev.yml @@ -17,7 +17,7 @@ services: worker: condition: service_started env_file: - - .env + - .env.example environment: - FLASK_DEBUG=true - FLASK_ENV=development @@ -34,7 +34,7 @@ services: - redis - postgres env_file: - - .env + - .env.example environment: - FLASK_DEBUG=true - FLASK_ENV=development @@ -44,7 +44,7 @@ services: container_name: redis restart: always env_file: - - .env + - .env.example postgres: image: postgres:14 @@ -58,7 +58,7 @@ services: timeout: 5s retries: 5 env_file: - - .env + - .env.example rqdashboard: @@ -70,7 +70,7 @@ services: depends_on: - redis env_file: - - .env + - .env.example volumes: pgdata: \ No newline at end of file From faec51c6c6e0209aad64a06b59b9cec7924b8c49 Mon Sep 17 00:00:00 2001 From: Zeecka Date: Wed, 31 Dec 2025 23:04:10 +0100 Subject: [PATCH 5/6] Rebase edits from main --- .env.example | 15 +++++++++++++-- compose.dev.yml | 5 ++--- compose.yml | 14 +++++++++++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/.env.example b/.env.example index b4bc151..38a8106 100644 --- a/.env.example +++ b/.env.example @@ -1,15 +1,26 @@ +# Application configuration MAX_CONTENT_LENGTH=1048576 MAX_PENDING_TIME=600 MAX_STORE_TIME=259200 +CLEAR_AT_RESTART=1 +SKIP_IHDR_FILL=1 + +# Flask configuration FLASK_DEBUG=0 FLASK_ENV=development -DB_URI=postgresql://aperiuser:aperipass@postgres:5432/aperisolve + +# Redis configuration RQ_DASHBOARD_REDIS_URL=redis://redis:6379/0 + +# Database configuration POSTGRES_DB=aperisolve POSTGRES_USER=aperiuser POSTGRES_PASSWORD=aperipass +DB_URI=postgresql://aperiuser:aperipass@postgres:5432/aperisolve + +# Sentry configuration SENTRY_DSN=https://your-dsn@sentry.io/project-id SENTRY_TRACES_SAMPLE_RATE=0.1 SENTRY_PROFILES_SAMPLE_RATE=0.1 SENTRY_RELEASE=1.0.0 -ENVIRONMENT=development \ No newline at end of file +SENTRY_ENVIRONMENT=development diff --git a/compose.dev.yml b/compose.dev.yml index 0b19a14..6f46315 100644 --- a/compose.dev.yml +++ b/compose.dev.yml @@ -60,7 +60,6 @@ services: env_file: - .env.example - rqdashboard: image: eoranged/rq-dashboard container_name: rq-dashboard @@ -71,6 +70,6 @@ services: - redis env_file: - .env.example - + volumes: - pgdata: \ No newline at end of file + pgdata: diff --git a/compose.yml b/compose.yml index 777fef2..4489e66 100644 --- a/compose.yml +++ b/compose.yml @@ -17,6 +17,12 @@ services: condition: service_started env_file: - .env + healthcheck: + test: ["CMD-SHELL", "dd if=/dev/urandom of=/tmp/healthcheck.png bs=1 count=1000000 && curl -X POST -F 'image=@/tmp/healthcheck.png' http://localhost:5000/upload -s -o /dev/null -w '%{http_code}' | grep -q 200"] + interval: 3600s + timeout: 30s + retries: 3 + start_period: 900s worker: image: ghcr.io/zeecka/aperisolve:latest @@ -31,13 +37,15 @@ services: - postgres env_file: - .env + environment: + - CLEAR_AT_RESTART=0 # Always false for worker to prevent double clearing postgres: - image: postgres:14 + image: postgres:18 container_name: postgres restart: always volumes: - - pgdata:/var/lib/postgresql/data + - pgdata:/var/lib/postgresql healthcheck: test: ["CMD-SHELL", "pg_isready -U aperiuser -d aperisolve"] interval: 5s @@ -63,7 +71,7 @@ services: - redis env_file: - .env - + volumes: apresults: pgdata: From 6f62eefd7787af3b4c81e2e5f39a2c59a9590ca0 Mon Sep 17 00:00:00 2001 From: Zeecka Date: Wed, 31 Dec 2025 23:07:15 +0100 Subject: [PATCH 6/6] black lint --- aperisolve/app.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/aperisolve/app.py b/aperisolve/app.py index 3b1ee5d..295faaa 100644 --- a/aperisolve/app.py +++ b/aperisolve/app.py @@ -43,10 +43,13 @@ queue = Queue(connection=redis_conn) @app.errorhandler(413) def too_large(_: Any) -> tuple[Response, int]: """Error Handler for Max File Size.""" - sentry_sdk.set_context("upload", { - "content_length": request.content_length, - "max_allowed": app.config["MAX_CONTENT_LENGTH"], - }) + sentry_sdk.set_context( + "upload", + { + "content_length": request.content_length, + "max_allowed": app.config["MAX_CONTENT_LENGTH"], + }, + ) sentry_sdk.capture_message("Upload failed: 413 Payload Too Large", level="warning") return jsonify({"error": "Image size exceeded"}), 413 @@ -56,8 +59,10 @@ def not_found(_: Any) -> str: """Error Handler for 404 not found.""" return render_template("error.html", message="Resource not found", statuscode=404) + # Sentry automatically captures 500 errors + @app.route("/") def index() -> str: """Render the main index page.""" @@ -127,9 +132,7 @@ def upload_image() -> tuple[Response, int]: submission_path = RESULT_FOLDER / img_hash / submission_hash # Check if hash is present on the DB - submission: Submission = Submission.query.filter_by( - hash=submission_hash - ).first() + submission: Submission = Submission.query.filter_by(hash=submission_hash).first() # Only return if BOTH the file exists AND the DB entry exists if submission_path.exists() and submission is not None: @@ -145,9 +148,7 @@ def upload_image() -> tuple[Response, int]: f.write(image_data) # Try to find image in DB by hash - sub_img = Image.query.filter_by( - hash=img_hash - ).first() + sub_img = Image.query.filter_by(hash=img_hash).first() # If DB entry is missing (even if file exists on disk), create it! if sub_img is None: