caddy proxy path

This commit is contained in:
hay-kot 2021-04-29 17:40:48 -08:00
commit ef5a9b203b
9 changed files with 57 additions and 57 deletions

View file

@ -5,7 +5,7 @@
:80 { :80 {
@proxied path /api/* /docs /openapi.json @proxied path /api/* /docs /openapi.json
root * /app/dist root * /app/dist
encode gzip encode gzip
uri strip_suffix / uri strip_suffix /

View file

@ -30,7 +30,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
&& apt-get remove -y curl apt-transport-https debian-keyring g++ gnupg gnupg2 gnupg1 && apt-get remove -y curl apt-transport-https debian-keyring g++ gnupg gnupg2 gnupg1
RUN pip install --no-cache-dir "poetry==$POETRY_VERSION" RUN pip install --no-cache-dir "poetry==$POETRY_VERSION"
#! Future #! Future

33
Dockerfile.dev Normal file
View file

@ -0,0 +1,33 @@
FROM python:3.9-slim-buster
ENV PRODUCTION false
ENV POETRY_VERSION 1.1.6
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc g++ \
curl \
gnupg gnupg2 gnupg1 \
apt-transport-https \
debian-archive-keyring \
debian-keyring \
libwebp-dev \
&& curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | apt-key add - \
&& curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee -a /etc/apt/sources.list.d/caddy-stable.list \
&& apt-get update && apt-get install -y --no-install-recommends \
&& apt autoremove \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get remove -y curl apt-transport-https debian-keyring g++ gnupg gnupg2 gnupg1
RUN pip install --no-cache-dir "poetry==$POETRY_VERSION"
WORKDIR /app/
# Copy poetry.lock* in case it doesn't exist in the repo
COPY ./pyproject.toml /app/
COPY ./mealie /app/mealie
RUN poetry config virtualenvs.create false \
&& poetry install
RUN chmod +x /app/mealie/run.sh
CMD ["/app/mealie/run.sh", "reload"]

View file

@ -6,7 +6,7 @@ services:
container_name: mealie-frontend container_name: mealie-frontend
image: mealie-frontend:dev image: mealie-frontend:dev
build: build:
context: ../frontend context: ./frontend
dockerfile: frontend.Dockerfile dockerfile: frontend.Dockerfile
restart: always restart: always
ports: ports:
@ -14,7 +14,7 @@ services:
environment: environment:
VUE_APP_API_BASE_URL: "http://mealie-api:9000" VUE_APP_API_BASE_URL: "http://mealie-api:9000"
volumes: volumes:
- ../frontend/:/app - ./frontend/:/app
- /app/node_modules - /app/node_modules
# Fast API # Fast API
@ -22,8 +22,8 @@ services:
container_name: mealie-api container_name: mealie-api
image: mealie-api:dev image: mealie-api:dev
build: build:
context: ../ context: ./
dockerfile: ./docker/Dockerfile.dev dockerfile: Dockerfile.dev
restart: always restart: always
ports: ports:
- 9921:9000 - 9921:9000
@ -31,8 +31,8 @@ services:
db_type: sqlite db_type: sqlite
TZ: America/Anchorage # Specify Correct Timezone for Date/Time to line up correctly. TZ: America/Anchorage # Specify Correct Timezone for Date/Time to line up correctly.
volumes: volumes:
- ../dev/data:/app/dev/data - ./dev/data:/app/dev/data
- ../mealie:/app/mealie - ./mealie:/app/mealie
# Mkdocs # Mkdocs
mealie-docs: mealie-docs:
@ -42,5 +42,4 @@ services:
ports: ports:
- 9922:8000 - 9922:8000
volumes: volumes:
- ../docs:/docs - ./docs:/docs

View file

@ -2,8 +2,8 @@ version: "3.1"
services: services:
mealie: mealie:
build: build:
context: ../ context: ./
dockerfile: ./docker/Dockerfile dockerfile: Dockerfile
container_name: mealie container_name: mealie
restart: always restart: always
ports: ports:

View file

@ -1,24 +0,0 @@
FROM python:3
WORKDIR /app/
ENV PRODUCTION false
RUN apt-get update -y && \
apt-get install -y python-pip python-dev
# Install Poetry
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | POETRY_HOME=/opt/poetry python && \
cd /usr/local/bin && \
ln -s /opt/poetry/bin/poetry && \
poetry config virtualenvs.create false
# Copy poetry.lock* in case it doesn't exist in the repo
COPY ./pyproject.toml /app/
COPY ./mealie /app/mealie
RUN poetry install
RUN chmod +x /app/mealie/run.sh
CMD ["/app/mealie/run.sh", "reload"]

View file

@ -71,10 +71,10 @@ docs: ## Start Mkdocs Development Server
cd docs && poetry run python -m mkdocs serve cd docs && poetry run python -m mkdocs serve
docker-dev: ## Build and Start Docker Development Stack docker-dev: ## Build and Start Docker Development Stack
docker-compose -f ./docker/docker-compose.dev.yml -p dev-mealie up --build docker-compose -f docker-compose.dev.yml -p dev-mealie up --build
docker-prod: ## Build and Start Docker Production Stack docker-prod: ## Build and Start Docker Production Stack
docker-compose -f ./docker/docker-compose.yml -p mealie up --build -d docker-compose -f docker-compose.yml -p mealie up --build -d
code-gen: ## Run Code-Gen Scripts code-gen: ## Run Code-Gen Scripts
poetry run python dev/scripts/app_routes_gen.py poetry run python dev/scripts/app_routes_gen.py

View file

@ -2,6 +2,8 @@ from enum import Enum
from fastapi import APIRouter, Depends, File, Form, HTTPException from fastapi import APIRouter, Depends, File, Form, HTTPException
from fastapi.responses import FileResponse from fastapi.responses import FileResponse
from mealie.core.config import app_dirs
from mealie.core.root_logger import get_logger
from mealie.db.database import db from mealie.db.database import db
from mealie.db.db_setup import generate_session from mealie.db.db_setup import generate_session
from mealie.routes.deps import get_current_user from mealie.routes.deps import get_current_user
@ -12,6 +14,7 @@ from mealie.services.scraper.scraper import create_from_url
from sqlalchemy.orm.session import Session from sqlalchemy.orm.session import Session
router = APIRouter(prefix="/api/recipes", tags=["Recipe CRUD"]) router = APIRouter(prefix="/api/recipes", tags=["Recipe CRUD"])
logger = get_logger()
@router.post("/create", status_code=201, response_model=str) @router.post("/create", status_code=201, response_model=str)
@ -106,22 +109,15 @@ def delete_recipe(
class ImageType(str, Enum): class ImageType(str, Enum):
original = "original" original = "original.webp"
small = "small" small = "min-original.webp"
tiny = "tiny" tiny = "tiny-original.webp"
@router.get("/{recipe_slug}/image") @router.get("/image/{recipe_slug}/{file_name}")
async def get_recipe_img(recipe_slug: str, image_type: ImageType = ImageType.original): async def get_recipe_img(recipe_slug: str, file_name: ImageType = ImageType.original):
""" Takes in a recipe slug, returns the static image """ """ Takes in a recipe slug, returns the static image """
if image_type == ImageType.original: recipe_image = app_dirs.IMG_DIR.joinpath(recipe_slug, file_name.value)
which_image = IMG_OPTIONS.ORIGINAL_IMAGE
elif image_type == ImageType.small:
which_image = IMG_OPTIONS.MINIFIED_IMAGE
elif image_type == ImageType.tiny:
which_image = IMG_OPTIONS.TINY_IMAGE
recipe_image = read_image(recipe_slug, image_type=which_image)
if recipe_image: if recipe_image:
return FileResponse(recipe_image) return FileResponse(recipe_image)
else: else:

View file

@ -1,11 +1,8 @@
#!/bin/sh #!/bin/bash
# Get Reload Arg `run.sh reload` for dev server # Get Reload Arg `run.sh reload` for dev server
ARG1=${1:-production} ARG1=${1:-production}
# Set Script Directory - Used for running the script from a different directory.
# DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# # Initialize Database Prerun # # Initialize Database Prerun
poetry run python /app/mealie/db/init_db.py poetry run python /app/mealie/db/init_db.py
poetry run python /app/mealie/services/image/minify.py poetry run python /app/mealie/services/image/minify.py
@ -15,12 +12,12 @@ poetry run python /app/mealie/services/image/minify.py
# Migrations # Migrations
# Set Port from ENV Variable # Set Port from ENV Variable
if [[ "$ARG1" = "reload" ]] if [ "$ARG1" == "reload" ]
then then
echo "Hot Reload!" echo "Hot Reload!"
# Start API # Start API
uvicorn mealie.app:app --host 0.0.0.0 --port 9000 --reload python /app/mealie/app.py
else else
echo "Production" echo "Production"
# Web Server # Web Server