Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
72 changes: 72 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Dependencies
node_modules
.pnp
.pnp.js
.yarn/install-state.gz

# Testing
coverage

# Next.js
.next/
out/

# Production
build
dist

# Misc
.DS_Store
*.pem

# Debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Local env files
.env*.local
.env

# Turbo
.turbo

# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
env/
build/
develop-eggs/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# Virtual Environment
.venv
venv/
ENV/

# IDE
.idea
.vscode
*.swp
*.swo

# Cache
.ruff_cache/
.mypy_cache/
.pytest_cache/

# Flask
instance/
68 changes: 68 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Docker Build & Test

on:
push:
branches: [ dev ]
pull_request:
branches: [ dev ]

env:
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
SCHEMA: ${{ secrets.SCHEMA }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and tag images
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/Dockerfile
push: false
build-args: |
FLASK_APP=app
FLASK_ENV=production
DATABASE_URL=${{ env.DATABASE_URL }}
SCHEMA=${{ env.SCHEMA }}
SECRET_KEY=${{ env.SECRET_KEY }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: app:test

- name: Start Docker Compose
run: |
docker compose -f docker/compose.prod.yaml up -d

- name: Wait for web service
run: |
timeout 30s bash -c 'until curl --silent --fail --insecure https://localhost/ > /dev/null; do sleep 2; echo "Waiting for web service..."; done'

- name: Verify application
run: |
# Check if frontend is served
curl --fail --insecure https://localhost/ | grep -q "<html" || exit 1

# Check if API is accessible
curl --fail --insecure https://localhost/api/docs > /dev/null || exit 1

- name: Show container status
if: always()
run: |
docker compose -f docker/compose.prod.yaml ps
docker compose -f docker/compose.prod.yaml logs

- name: Cleanup
if: always()
run: |
docker compose -f docker/compose.prod.yaml down -v
docker image rm app:test
2 changes: 1 addition & 1 deletion backend/.python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.13
3.9
4 changes: 1 addition & 3 deletions backend/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ class Config:
# (only 'postgresql') but heroku's postgres add-on automatically sets the
# url in the hidden config vars to start with postgres.
# so the connection uri must be updated here (for production)
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL').replace(
'postgres://', 'postgresql://'
)
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL')
SQLALCHEMY_ECHO = True
7 changes: 5 additions & 2 deletions backend/app/models/server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Module for the Server model."""

from .db import SCHEMA, db, environment
from .db import SCHEMA, add_prefix_for_prod, db, environment


class Server(db.Model):
Expand All @@ -21,7 +21,10 @@ class Server(db.Model):

# Relationships
members = db.relationship(
'User', secondary='server_members', back_populates='servers', viewonly=True
'User',
secondary=add_prefix_for_prod('server_members'),
back_populates='servers',
viewonly=True,
)
server_members = db.relationship(
'ServerMember',
Expand Down
7 changes: 5 additions & 2 deletions backend/app/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from flask_login import UserMixin
from werkzeug.security import check_password_hash, generate_password_hash

from .db import SCHEMA, db, environment
from .db import SCHEMA, add_prefix_for_prod, db, environment


class User(db.Model, UserMixin):
Expand All @@ -24,7 +24,10 @@ class User(db.Model, UserMixin):
)

servers = db.relationship(
'Server', secondary='server_members', back_populates='members', viewonly=True
'Server',
secondary=add_prefix_for_prod('server_members'),
back_populates='members',
viewonly=True,
)
messages = db.relationship(
'Message', back_populates='user', cascade='all, delete-orphan'
Expand Down
50 changes: 27 additions & 23 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,47 @@ name = "backend"
version = "0.1.0"
description = "Flask-based backend API for Neocord - a modern real-time communication platform. Features user authentication, instant messaging, community server management, and channel organization. Built with SQLAlchemy and Alembic for robust data management and migrations."
readme = "README.md"
requires-python = ">=3.13"
requires-python = ">=3.9"

# Core dependencies grouped by purpose
dependencies = [
# Flask and Extensions
"flask>=3.0.3",
"flask-cors>=5.0.0",
"flask-login>=0.6.3",
"flask-migrate>=4.0.7",
"flask-sqlalchemy>=3.1.1",
"flask-wtf>=1.2.2",
"werkzeug>=3.1.2",
"flask==2.2.2",
"flask-cors==3.0.10",
"flask-login==0.6.2",
"flask-migrate==4.0.2",
"flask-sqlalchemy==3.0.2",
"flask-wtf==1.1.1",
"werkzeug==2.2.2",

# Database and ORM
"sqlalchemy>=2.0.36",
"alembic>=1.14.0",
"greenlet>=3.1.1",
"sqlalchemy==1.4.46",
"alembic==1.9.2",
"greenlet==3.0.1",

# Server
"gunicorn>=23.0.0",
"gunicorn==20.1.0",

# Utilities
"click>=8.1.7",
"itsdangerous>=2.2.0",
"python-dotenv>=1.0.1",
"python-dateutil>=2.9.0.post0",
"click==8.1.3",
"itsdangerous==2.1.2",
"python-dotenv==0.21.0",
"python-dateutil==2.8.2",

# Template Engine
"jinja2>=3.1.4",
"mako>=1.3.6",
"markupsafe>=3.0.2",
"jinja2==3.1.2",
"mako==1.2.4",
"markupsafe==2.1.2",

# Forms and Validation
"wtforms>=3.2.1",
"wtforms==3.0.1",

# Misc
"python-editor>=1.0.4",
"six>=1.16.0",
"python-editor==1.0.4",
"six==1.16.0",

# Database Drivers
"psycopg2-binary>=2.9.10",
]

[dependency-groups]
Expand Down Expand Up @@ -83,4 +87,4 @@ convention = "google"
[tool.ruff.lint.isort]
section-order = ["future", "standard-library", "third-party", "first-party", "local-folder"]
combine-as-imports = true
known-first-party = ["backend"]
known-first-party = ["backend"]
Loading