-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch to SQLModel Database stuff #93
Changes from all commits
da1d679
aee5aed
f1d1f53
630de0c
563bbca
4941cbc
e8f8d46
03969cf
31259c1
272671e
7d0070b
81c3e51
5093ef0
1b0604d
6dbc0d8
9ed938d
9f8fe3f
0cb90e6
b1d25bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
*.pyc | ||
__pycache__ | ||
config/ | ||
database/ | ||
.terraform* | ||
terraform.* | ||
clouds.yaml | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 . | ||
|
@@ -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 . . | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include a .Dockerignore for files that don't need to be in the container There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
@@ -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"] |
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 . | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this further down, any changes to requirements will cause the apt execution to restart There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
# 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the official installation method for the bitwarden SDK? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes https://bitwarden.com/help/secrets-manager-cli/ I didn't see they had an sdk before might switch to that https://bitwarden.com/help/secrets-manager-sdk/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
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"] |
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 |
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsure if this is a good idea or not but haven't seen it used before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This create a pip cache that is stored outside of the docker container, speeding up rebuilds
https://pythonspeed.com/articles/docker-cache-pip-downloads/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just looking at random repo and came across this. If you want a faster build, you can always setup CI pipeline with GH Action and store it on PKG registry, then fetch it on the server.