Skip to content

Commit

Permalink
Switch to SQLModel Database stuff (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
jontyms authored May 27, 2024
1 parent 56d6870 commit 7522882
Show file tree
Hide file tree
Showing 85 changed files with 2,118 additions and 1,262 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.pyc
__pycache__
config/
database/
.terraform*
terraform.*
clouds.yaml
Expand Down
8 changes: 2 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@ repos:
- id: ruff-format
- id: ruff
exclude: ^tests/codegen/snapshots/python/
args: [--select, I, "--fix"]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier
files: '^docs/.*\.mdx?$'

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand Down
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
FROM python:3.11-bookworm

# Set the working directory in the container
WORKDIR /app
WORKDIR /src

# Copy the requirements file to the container
COPY requirements.txt .
Expand All @@ -22,7 +22,7 @@ RUN mv bws /usr/local/bin
RUN rm -r /tmp/

# Install the dependencies
RUN pip install --no-cache-dir -r requirements.txt
RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt

# Copy the application code to the container
COPY . .
Expand All @@ -31,4 +31,5 @@ COPY . .
EXPOSE 8000

# Start the FastAPI application
CMD ["uvicorn", "index:app", "--host", "0.0.0.0", "--port", "8000"]
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
#CMD ["sleep", "1h"]
34 changes: 34 additions & 0 deletions Dockerfile-testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Use the official Python base image
FROM python:3.11-bookworm

# Set the working directory in the container
WORKDIR /app

# Copy the requirements file to the container
COPY requirements.txt .

# Install build-essential
RUN apt-get update && apt-get install -y build-essential

# Clean up
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

ADD https://github.com/bitwarden/sdk/releases/download/bws-v0.4.0/bws-x86_64-unknown-linux-gnu-0.4.0.zip /tmp

RUN unzip /tmp/bws-x86_64-unknown-linux-gnu-0.4.0.zip

RUN mv bws /usr/local/bin

RUN rm -r /tmp/

# Install the dependencies
RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt

# Copy the application code to the container
COPY . .

# Expose the port that the FastAPI application will run on
EXPOSE 8000

# Start the FastAPI application
CMD ["sleep", "infinity"]
Empty file added app/__init__.py
Empty file.
112 changes: 112 additions & 0 deletions app/alembic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# A generic, single database configuration.

[alembic]
# path to migration scripts
script_location = ./migrations

# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
# Uncomment the line below if you want the files to be prepended with date and time
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s

# sys.path path, will be prepended to sys.path if present.
# defaults to the current working directory.
prepend_sys_path = ../

# timezone to use when rendering the date within the migration file
# as well as the filename.
# If specified, requires the python>=3.9 or backports.zoneinfo library.
# Any required deps can installed by adding `alembic[tz]` to the pip requirements
# string value is passed to ZoneInfo()
# leave blank for localtime
# timezone =

# max length of characters to apply to the
# "slug" field
# truncate_slug_length = 40

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false

# set to 'true' to allow .pyc and .pyo files without
# a source .py file to be detected as revisions in the
# versions/ directory
# sourceless = false

# version location specification; This defaults
# to migrations/versions. When using multiple version
# directories, initial revisions must be specified with --version-path.
# The path separator used here should be the separator specified by "version_path_separator" below.
# version_locations = %(here)s/bar:%(here)s/bat:migrations/versions

# version path separator; As mentioned above, this is the character used to split
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
# Valid values for version_path_separator are:
#
# version_path_separator = :
# version_path_separator = ;
# version_path_separator = space
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.

# set to 'true' to search source files recursively
# in each "version_locations" directory
# new in Alembic version 1.10
# recursive_version_locations = false

# the output encoding used when revision files
# are written from script.py.mako
# output_encoding = utf-8


[post_write_hooks]
# post_write_hooks defines scripts or Python functions that are run
# on newly generated revision scripts. See the documentation for further
# detail and examples

# format using "black" - use the console_scripts runner, against the "black" entrypoint
# hooks = black
# black.type = console_scripts
# black.entrypoint = black
# black.options = -l 79 REVISION_SCRIPT_FILENAME

# lint with attempts to fix using "ruff" - use the exec runner, execute a binary
# hooks = ruff
# ruff.type = exec
# ruff.executable = %(here)s/.venv/bin/ruff
# ruff.options = --fix REVISION_SCRIPT_FILENAME

# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console
qualname =

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
25 changes: 25 additions & 0 deletions app/entry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
import subprocess
import sys


# Define the default command to run uvicorn with environment variables
def run_uvicorn():
host = os.getenv("ONBOARD_HOST", "0.0.0.0")
port = os.getenv("ONBOARD_PORT", "8000")
command = ["uvicorn", "app.main:app", "--host", host, "--port", port]
subprocess.run(command)


# Define the migrate command
def run_migrate():
command = ["alembic", "upgrade", "head"]
subprocess.run(command)


# Entry point
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "migrate":
run_migrate()
else:
run_uvicorn()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@
"options": ["I promise not to do this."],
"key": "ethics_form.host_at_ucf"
},
{
"caption": "I have read and agree to the Hack@UCF Cloud Acceptable Use Policy located at <a href='https://help.hackucf.org/misc/aup/'> here </a>",
"input": "radio",
"required": true,
"options": ["I promise not to do this."],
"key": "ethics_form.cloud_aup"
},

{
"input": "signature",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 7522882

Please sign in to comment.