separate images, no more .env

This commit is contained in:
msramalho
2025-02-10 23:49:08 +00:00
parent 6f3d3427c8
commit 37ebba73bf
6 changed files with 38 additions and 11 deletions

View File

@@ -3,20 +3,20 @@ clean-dev:
docker compose -f docker-compose.yml -f docker-compose.dev.yml down --volumes --remove-orphans docker compose -f docker-compose.yml -f docker-compose.dev.yml down --volumes --remove-orphans
dev: dev:
docker compose -f docker-compose.yml -f docker-compose.dev.yml build docker compose --env-file .env.dev -f docker-compose.yml -f docker-compose.dev.yml build
docker compose -f docker-compose.yml -f docker-compose.dev.yml up --remove-orphans docker compose --env-file .env.dev -f docker-compose.yml -f docker-compose.dev.yml up --remove-orphans
dev-redis-only: dev-redis-only:
docker compose -f docker-compose.yml -f docker-compose.dev.yml build redis docker compose --env-file .env.dev -f docker-compose.yml -f docker-compose.dev.yml build redis
docker compose -f docker-compose.yml -f docker-compose.dev.yml up --remove-orphans redis docker compose --env-file .env.dev -f docker-compose.yml -f docker-compose.dev.yml up --remove-orphans redis
stop-dev: stop-dev:
docker compose -f docker-compose.yml -f docker-compose.dev.yml down --volumes docker compose -f docker-compose.yml -f docker-compose.dev.yml down --volumes
prod: prod:
docker compose build docker compose --env-file .env.prod build
docker compose up -d --remove-orphans docker compose --env-file .env.prod up -d --remove-orphans
docker buildx prune --keep-storage 20gb -f docker buildx prune --keep-storage 20gb -f
docker image prune -f docker image prune -f
docker system df docker system df

View File

View File

@@ -1,15 +1,16 @@
from functools import lru_cache from functools import lru_cache
import os
from fastapi_mail import ConnectionConfig from fastapi_mail import ConnectionConfig
from pydantic_settings import BaseSettings from pydantic_settings import BaseSettings, SettingsConfigDict
from pydantic import ConfigDict
from typing import Annotated, Set from typing import Annotated, Set
from annotated_types import Len from annotated_types import Len
class Settings(BaseSettings): class Settings(BaseSettings):
model_config = ConfigDict(extra='ignore', str_strip_whitespace=True)
model_config = SettingsConfigDict(env_file=os.environ.get("ENVIRONMENT_FILE") , env_file_encoding='utf-8', extra='ignore', str_strip_whitespace=True)
# general # general
SERVE_LOCAL_ARCHIVE: str = "" SERVE_LOCAL_ARCHIVE: str = ""
USER_GROUPS_FILENAME: str = "user-groups.yaml" USER_GROUPS_FILENAME: str = "user-groups.yaml"

View File

@@ -6,6 +6,7 @@ services:
volumes: volumes:
- ./app:/aa-api/app # for --reload to work - ./app:/aa-api/app # for --reload to work
environment: environment:
- ENVIRONMENT_FILE=.env.dev
- SERVE_LOCAL_ARCHIVE=/aa-api/app/local_archive # See orchestration.yaml local_storage.save_to - SERVE_LOCAL_ARCHIVE=/aa-api/app/local_archive # See orchestration.yaml local_storage.save_to
- ALLOWED_ORIGINS=["http://localhost:8000","http://localhost:8004","http://localhost:8081","chrome-extension://ojcimmjndnlmmlgnjaeojoebaceokpdp"] - ALLOWED_ORIGINS=["http://localhost:8000","http://localhost:8004","http://localhost:8081","chrome-extension://ojcimmjndnlmmlgnjaeojoebaceokpdp"]
- USER_GROUPS_FILENAME=/aa-api/app/user-groups.dev.yaml - USER_GROUPS_FILENAME=/aa-api/app/user-groups.dev.yaml
@@ -20,7 +21,6 @@ services:
- ./app:/aa-api/app # for watchmedo - ./app:/aa-api/app # for watchmedo
redis: redis:
command: redis-server /conf/redis.conf --requirepass ${REDIS_PASSWORD}
restart: "no" restart: "no"
env_file: .env.dev env_file: .env.dev
ports: ports:

View File

@@ -7,11 +7,12 @@ services:
web: web:
build: build:
context: . context: .
dockerfile: worker.Dockerfile dockerfile: web.Dockerfile
restart: always restart: always
env_file: .env.prod env_file: .env.prod
environment: environment:
CELERY_BROKER_URL: redis://:${REDIS_PASSWORD}@redis:6379/0 CELERY_BROKER_URL: redis://:${REDIS_PASSWORD}@redis:6379/0
ENVIRONMENT_FILE: .env.prod
ports: ports:
- "127.0.0.1:8004:8000" - "127.0.0.1:8004:8000"
#TODO: should prod have the --reload flag? #TODO: should prod have the --reload flag?
@@ -42,6 +43,7 @@ services:
- crawls:/crawls # BROWSERTRIX_HOME_HOST:BROWSERTRIX_HOME_CONTAINER, do not change /crawls - crawls:/crawls # BROWSERTRIX_HOME_HOST:BROWSERTRIX_HOME_CONTAINER, do not change /crawls
environment: environment:
CELERY_BROKER_URL: redis://:${REDIS_PASSWORD}@redis:6379/0 CELERY_BROKER_URL: redis://:${REDIS_PASSWORD}@redis:6379/0
ENVIRONMENT_FILE: .env.prod
WACZ_ENABLE_DOCKER: 1 # Enable calling docker from this container WACZ_ENABLE_DOCKER: 1 # Enable calling docker from this container
BROWSERTRIX_HOME_HOST: auto-archiver-api_crawls BROWSERTRIX_HOME_HOST: auto-archiver-api_crawls
BROWSERTRIX_HOME_CONTAINER: /crawls BROWSERTRIX_HOME_CONTAINER: /crawls
@@ -57,6 +59,7 @@ services:
redis: redis:
image: redis:6-alpine image: redis:6-alpine
restart: always restart: always
env_file: .env.prod
command: redis-server /conf/redis.conf --requirepass ${REDIS_PASSWORD} command: redis-server /conf/redis.conf --requirepass ${REDIS_PASSWORD}
volumes: volumes:
- ./redis/data:/data - ./redis/data:/data

23
web.Dockerfile Normal file
View File

@@ -0,0 +1,23 @@
# Stage 1: install dependencies
FROM python:3.10-slim AS build
WORKDIR /aa-api
# TODO: multistage build
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
gcc \
g++ \
&& rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir poetry
COPY pyproject.toml poetry.lock .
RUN poetry install --with web --no-interaction --no-ansi --no-root --no-cache
# Copy the application code
COPY alembic.ini ./
COPY .env* ./app/
COPY ./secrets/ ./secrets/
COPY ./app/ ./app/
# Run the FastAPI app with Uvicorn
ENTRYPOINT ["poetry", "run"]