[cron] add dockerfile
Some checks are pending
Python lint and test / linttest (push) Waiting to run

This commit is contained in:
Piotr Domański 2024-08-03 23:24:52 +02:00
parent a701b952e8
commit 5bc37bc127
6 changed files with 40 additions and 7 deletions

6
Dockerfile.cron Normal file
View file

@ -0,0 +1,6 @@
FROM alpine
RUN apk add --no-cache curl
RUN crontab -l | { cat; echo '* * * * * curl -X POST "http://tasks:8000/api/cache_product_usage_data" -H "Authorization: Bearer ${API_KEY}"'; } | crontab -
CMD ["crond", "-f", "-l", "2"]

View file

@ -7,11 +7,17 @@ ifeq ($(shell uname -m), arm64)
DOCKER_BUILD=docker buildx build --platform linux/amd64
endif
build:
api: fooder Dockerfile requirements.txt
$(DOCKER_BUILD) -t registry.domandoman.xyz/fooder/api -f Dockerfile .
cron: Dockerfile.cron
$(DOCKER_BUILD) -t registry.domandoman.xyz/fooder/cron -f Dockerfile.cron .
build: api cron
push:
docker push registry.domandoman.xyz/fooder/api
docker push registry.domandoman.xyz/fooder/cron
black:
python -m black fooder

View file

@ -25,3 +25,23 @@ services:
- .env
ports:
- "8000:8000"
tasks:
restart: unless-stopped
image: registry.domandoman.xyz/fooder/api
networks:
- fooder
env_file:
- .env
command: "uvicorn fooder.tasks_app:app --host 0.0.0.0 --port 8000 --workers 1"
cron:
restart: unless-stopped
image: registry.domandoman.xyz/fooder/cron
build:
dockerfile: Dockerfile.cron
context: .
networks:
- fooder
env_file:
- .env

View file

@ -7,6 +7,7 @@ DB_URI="postgresql+asyncpg://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database/${PO
ECHO_SQL=0
SECRET_KEY="${SECRET_KEY}" # generate with $ openssl rand -hex 32
API_KEY="${API_KEY}" # generate with $ openssl rand -hex 32
REFRESH_SECRET_KEY="${REFRESH_SECRET_KEY}" # generate with $ openssl rand -hex 32
ALGORITHM="HS256"
ACCESS_TOKEN_EXPIRE_MINUTES=30

View file

@ -1,12 +1,12 @@
from fastapi import APIRouter
from .view.product import router as product_router
from .view.diary import router as diary_router
from .view.meal import router as meal_router
from .view.entry import router as entry_router
from .view.meal import router as meal_router
from .view.preset import router as preset_router
from .view.product import router as product_router
from .view.token import router as token_router
from .view.user import router as user_router
from .view.preset import router as preset_router
router = APIRouter(prefix="/api")
router.include_router(product_router, prefix="/product", tags=["product"])

View file

@ -1,12 +1,12 @@
from fastapi import APIRouter, Depends, Request
from ..controller.tasks import CacheProductUsageData
from ..controller.tasks import CacheProductUsageData
router = APIRouter(prefix="/api", tags=["tasks"])
@router.post("/cache_product_usage_data")
async def create_user(
async def cache_product_usage_data(
request: Request,
contoller: CacheProductUsageData = Depends(CacheProductUsageData),
):