-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
582 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.git/ | ||
.github/ | ||
.pytest_cache/ | ||
.venv/ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
##### Builder Stage ##### | ||
FROM python:3.10-slim as builder | ||
|
||
# Set default path | ||
ENV PATH="/app/.venv/bin:${PATH}" | ||
|
||
# Set default workdir | ||
WORKDIR /app | ||
|
||
# Create virtualenv and install Python packages | ||
RUN pip install --no-cache-dir pip -U && \ | ||
pip install --no-cache-dir poetry && \ | ||
poetry config virtualenvs.in-project true | ||
COPY ./poetry.lock poetry.lock | ||
COPY ./pyproject.toml pyproject.toml | ||
RUN poetry install --no-dev | ||
|
||
# Copy app files and add directory to workdir | ||
COPY fastqueue ./fastqueue | ||
|
||
##### Final Stage ##### | ||
FROM python:3.10-slim | ||
|
||
# Disable Prompt During Packages Installation | ||
ARG DEBIAN_FRONTEND=noninteractive | ||
|
||
# Set default path | ||
ENV PATH="/app/.venv/bin:${PATH}" | ||
ENV PYTHONPATH /app | ||
|
||
# Copy content from builder stage | ||
COPY --from=builder /app /app | ||
|
||
# Install packages | ||
RUN apt-get update && \ | ||
apt-get install --no-install-recommends -y tini && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# Add fastqueue user and create directories | ||
RUN useradd -m fastqueue && mkdir -p /app | ||
|
||
# Set permissions | ||
RUN chown -R fastqueue:fastqueue /app | ||
|
||
# Set workdir and XAPO User | ||
WORKDIR /app | ||
USER fastqueue | ||
|
||
# Set entrypoint and cmd | ||
ENTRYPOINT ["/usr/bin/tini", "--"] | ||
CMD ["python", "/app/fastqueue/main.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fastqueue_debug='true' | ||
fastqueue_server_host='127.0.0.1' | ||
fastqueue_server_port='8000' | ||
fastqueue_server_reload='true' | ||
fastqueue_server_num_workers='1' | ||
fastqueue_log_level='info' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from pydantic import BaseSettings | ||
|
||
|
||
class Settings(BaseSettings): | ||
debug: bool = False | ||
server_host: str = "0.0.0.0" | ||
server_port: int = 8000 | ||
server_reload: bool = False | ||
server_num_workers: int = 1 | ||
log_level: str = "info" | ||
|
||
class Config: | ||
env_file = ".env" | ||
env_file_encoding = "utf-8" | ||
env_prefix = "fastqueue_" | ||
|
||
|
||
settings = Settings() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import uvicorn | ||
from fastapi import FastAPI | ||
|
||
from fastqueue.config import settings | ||
|
||
app = FastAPI(debug=settings.debug) | ||
|
||
|
||
@app.get("/") | ||
def read_root(): | ||
return {"Hello": "World"} | ||
|
||
|
||
def run_server(): | ||
uvicorn.run( | ||
"fastqueue.main:app", | ||
debug=settings.debug, | ||
host=settings.server_host, | ||
port=settings.server_port, | ||
log_level=settings.log_level.lower(), | ||
reload=settings.server_reload, | ||
workers=settings.server_num_workers, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
run_server() |
Oops, something went wrong.