Browse Source

devide cloud and local

tomoya 2 years ago
parent
commit
0fc706c4c1

+ 3 - 2
.env

@@ -1,4 +1,5 @@
 DOMAIN=localhost
+SERVER_ADDRESS=http://172.105.219.42:8080
 # DOMAIN=local.dockertoolbox.tiangolo.com
 # DOMAIN=localhost.tiangolo.com
 # DOMAIN=dev.ai-anchor.com
@@ -14,7 +15,7 @@ DOCKER_IMAGE_CELERYWORKER=celeryworker
 DOCKER_IMAGE_FRONTEND=frontend
 
 # Backend
-BACKEND_CORS_ORIGINS=["http://172.105.219.42", "http://local.ai-anchor.com:5173", "http://local.ai-anchor.com:8080", "http://localhost", "http://localhost:4200", "http://localhost:3000", "http://localhost:5173", "http://localhost:8080", "https://localhost", "https://localhost:4200", "https://localhost:3000", "https://localhost:8080", "http://dev.ai-anchor.com", "http://dev.ai-anchor.com:5173", "http://dev.ai-anchor.com:8080", "https://stag.ai-anchor.com", "https://ai-anchor.com", "http://local.dockertoolbox.tiangolo.com", "http://localhost.tiangolo.com"]
+BACKEND_CORS_ORIGINS=["https://cloud.choozmo:8080", "http://cloud.choozmo.com:8080", "https://cloud.choozmo.com", "http://cloud.choozmo.com","http://172.105.219.42", "http://local.ai-anchor.com:5173", "http://local.ai-anchor.com:8080", "http://localhost", "http://localhost:4200", "http://localhost:3000", "http://localhost:5173", "http://localhost:8080", "https://localhost", "https://localhost:4200", "https://localhost:3000", "https://localhost:8080", "http://dev.ai-anchor.com", "http://dev.ai-anchor.com:5173", "http://dev.ai-anchor.com:8080", "https://stag.ai-anchor.com", "https://ai-anchor.com", "http://local.dockertoolbox.tiangolo.com", "http://localhost.tiangolo.com"]
 PROJECT_NAME=AI anchor
 SECRET_KEY=1df1f2180c7b2550e76a8ccf5e67a76e5321d8c2d3fee4a725f8b80baf9a0c91
 FIRST_SUPERUSER=admin@ai-anchor.com
@@ -46,4 +47,4 @@ PGADMIN_DEFAULT_PASSWORD=password
 
 # Initial data
 MEMBERSHIP_TYPES=["normal", "infinite"]
-PROGRESS_TYPES=["waiting", "processing", "complete"]
+PROGRESS_TYPES=["waiting", "processing", "completed"]

+ 2 - 1
backend/app/app/api/api_v1/api.py

@@ -1,9 +1,10 @@
 from fastapi import APIRouter
 
-from app.api.api_v1.endpoints import items, login, users, utils
+from app.api.api_v1.endpoints import items, login, users, utils, videos
 
 api_router = APIRouter()
 api_router.include_router(login.router, tags=["login"])
 api_router.include_router(users.router, prefix="/users", tags=["users"])
 api_router.include_router(utils.router, prefix="/utils", tags=["utils"])
 api_router.include_router(items.router, prefix="/items", tags=["items"])
+api_router.include_router(videos.router, prefix="/videos", tags=["videos"])

+ 76 - 10
backend/app/app/api/api_v1/endpoints/videos.py

@@ -1,5 +1,7 @@
 from typing import Any, List
 
+from fastapi import UploadFile, File
+from fastapi.responses import FileResponse
 from fastapi import APIRouter, Depends, HTTPException
 from sqlalchemy.orm import Session
 
@@ -8,6 +10,14 @@ import app.models as models
 import app.schemas as schemas 
 from app.api import deps
 
+from app.core.celery_app import celery_app
+
+from pathlib import Path
+
+ZIP_STORAGE = "/app/backend/zips"
+VIDEO_STORAGE = "/app/backend/videos"
+
+
 router = APIRouter()
 
 @router.get("/", response_model=List[schemas.Video])
@@ -32,32 +42,88 @@ def get_video_list(
 def upload_plot(
     *,
     db: Session = Depends(deps.get_db),
-    video_upload: schemas.VideoUpload,
+    title: str, 
+    upload_file: UploadFile=File(),
     current_user: models.User = Depends(deps.get_current_active_user),
 ) -> Any:
     """
     Create new video.
     """
     video_create = schemas.VideoCreate
-    video_create.title = video_upload.title
+    video_create.title = title
     video_create.progress = models.Progress.WAITING
-    video = crud.item.create_with_owner(db=db, obj_in=video_create, owner_id=current_user.id)
+    video_create.title = title
+    file_name = crud.video.generate_file_name(db=db, n=20)
+    video_create.stored_file_name = file_name
+    video = crud.video.create_with_owner(db=db, obj_in=video_create, owner_id=current_user.id)
+
+    try:
+        with open(str(Path(ZIP_STORAGE).joinpath(video.stored_file_name+".zip")), 'wb') as f:
+            while contents := upload_file.file.read(1024 * 1024):
+                f.write(contents)
+    except Exception as e:
+        print(e, type(e))
+        return {"error": str(e)}
+    finally:
+        upload_file.file.close()
     return video
 
 @router.get("/{id}")
 def download_video(
-
+    *,
+    db: Session = Depends(deps.get_db),
+    id: int,
+    current_user: models.User = Depends(deps.get_current_active_user),
 ) -> Any:
-    pass
+    
+    video = db.query(models.Video).filter(db=db, id=id).first()
+    if not video:
+        raise HTTPException(status_code=404, detail="Video not found")
+    if not crud.user.is_superuser(current_user) and (video.owner_id != current_user.id):
+        raise HTTPException(status_code=400, detail="Not enough permissions")
+    if not video.progress == "completed":
+        raise HTTPException(status_code=400, detail="Video not completed yet")
+    
+    result = celery_app.send_task("app.worker.upload_to_server", args=[video.id, video.stored_file_name])
+
+    if result.get() == "completed" and (file_path:=Path(VIDEO_STORAGE).joinpath(video.stored_file_name+".mp4")).exit():
+        return FileResponse(path=str(file_path), filename=video.title+".mp4")
+    else:
+        raise HTTPException(status_code=404, detail="Error occurs")
+
 
 @router.get("/worker/{id}")
 def download_plot(
-
+  *,
+  db: Session = Depends(deps.get_db),
+  id: int
 ) -> Any:
-    pass
+    video = db.query(models.Video).filter(db=db, id=id).first()
+    if not video:
+        raise HTTPException(status_code=404, detail="Video not found")
+    
+    file_path = Path(ZIP_STORAGE).joinpath(video.stored_file_name+".zip")
+    return FileResponse(path=str(file_path))
 
-@router.get("/worker")
+@router.post("/worker/{id}")
 def upload_complete_video(
-
+    *,
+    db: Session = Depends(deps.get_db),
+    id: int,
+    upload_video: UploadFile=File(),
 ) -> Any:
-    pass
+    
+    video = db.query(models.Video).filter(db=db, id=id).first()
+    if not video:
+        raise HTTPException(status_code=404, detail="Video not found")
+    
+    try:
+        with open(str(Path(VIDEO_STORAGE).joinpath(video.stored_file_name+".mp4")), 'wb') as f:
+            while contents := upload_video.file.read(1024 * 1024):
+                f.write(contents)
+    except Exception as e:
+        print(e, type(e))
+        return {"error": str(e)}
+    finally:
+        upload_video.file.close()
+    return video

+ 4 - 1
backend/app/app/core/celery_app.py

@@ -2,4 +2,7 @@ from celery import Celery
 
 celery_app = Celery("worker", broker="amqp://guest@queue//")
 
-celery_app.conf.task_routes = {"app.worker.test_celery": "main-queue"}
+
+
+celery_app.conf.task_routes = {"app.worker.test_celery": "main-queue", 
+                                  "app.worker.make_video": "main-queue"}

+ 2 - 0
backend/app/app/core/config.py

@@ -100,6 +100,8 @@ class Settings(BaseSettings):
     MEMBERSHIP_TYPES: List[str]
     PROGRESS_TYPES: List[str]
 
+    SERVER_ADDRESS: AnyHttpUrl
+
     class Config:
         case_sensitive = True
 

+ 9 - 0
backend/app/app/crud/crud_video.py

@@ -7,6 +7,7 @@ from app.crud.base import CRUDBase
 from app.models.video import Video
 from app.schemas.video import VideoCreate, VideoUpdate
 
+from app.utils import random_name
 
 class CRUDVideo(CRUDBase[Video, VideoCreate, VideoUpdate]):
     def create_with_owner(
@@ -30,5 +31,13 @@ class CRUDVideo(CRUDBase[Video, VideoCreate, VideoUpdate]):
             .all()
         )
 
+    def generate_file_name(
+      self, db: Session, *, n:int
+    ) -> bool:
+        while True:
+            file_name = random_name(n)
+            if not db.query(self.model).filter(Video.stored_file_name==file_name).first():
+              return file_name
+
 
 video = CRUDVideo(Video)

+ 1 - 1
backend/app/app/schemas/video.py

@@ -11,7 +11,7 @@ class VideoBase(BaseModel):
 # Properties to receive on item upload
 class VideoUpload(VideoBase):
     title: str
-    zip_file: UploadFile=File()
+    stored_file_name: str
 
 # Properties to receive on item creation
 class VideoCreate(VideoBase):

+ 6 - 0
backend/app/app/utils.py

@@ -9,6 +9,8 @@ from jose import jwt
 
 from app.core.config import settings
 
+import random, string
+
 
 def send_email(
     email_to: str,
@@ -104,3 +106,7 @@ def verify_password_reset_token(token: str) -> Optional[str]:
         return decoded_token["email"]
     except jwt.JWTError:
         return None
+
+def random_name(n):
+   randlst = [random.choice(string.ascii_letters + string.digits) for i in range(n)]
+   return ''.join(randlst)

+ 50 - 0
backend/app/app/worker.py

@@ -2,10 +2,60 @@ from raven import Client
 
 from app.core.celery_app import celery_app
 from app.core.config import settings
+import requests
+from pathlib import Path
+from urllib.parse import urlparse, urljoin
 
 client_sentry = Client(settings.SENTRY_DSN)
 
+download_to_local_url = urljoin(settings.SERVER_ADDRESS, settings.API_V1_STR, "/videos/worker")
+upload_to_server_url = urljoin(settings.SERVER_ADDRESS, settings.API_V1_STR, "/videos/worker")
+
+ZIP_STORAGE = "/app/celery/zips"
+VIDEO_STORAGE = "app/celery/videos"
+
 
 @celery_app.task(acks_late=True)
 def test_celery(word: str) -> str:
     return f"test task return {word}"
+
+@celery_app.task(acks_late=True)
+def download_to_local(id:int, file_name:str) -> str:
+
+    zip_file = Path(file_name+"/.zip")
+    r = requests.get(download_to_local_url, stream=True)
+
+    with open(str(VIDEO_STORAGE/zip_file), 'wb') as f:
+        r.raise_for_status()
+        for chunk in r.iter_content(chunk_size=1024):
+            f.write(chunk)
+    return "complete"
+
+
+@celery_app.task(acks_late=True)
+def make_video(id:int, file_name) -> str:
+    # download 
+    zip_file = Path(file_name+"/.zip")
+    r = requests.get(download_to_local_url, stream=True)
+
+    with open(str(VIDEO_STORAGE/zip_file), 'wb') as f:
+        r.raise_for_status()
+        for chunk in r.iter_content(chunk_size=1024):
+            f.write(chunk)
+
+    # make video
+
+
+    video_file = Path(file_name+".mp4")
+    r = requests.post(urljoin(upload_to_server_url,str(id)))
+
+
+    return "complete"
+
+
+@celery_app.task(acks_late=True)
+def upload_to_server(id:int, file_name:str) -> str:
+
+    video_file = Path(file_name+".mp4")
+    r = requests.post(urljoin(upload_to_server_url,str(id)))
+    return "complete"

+ 2 - 0
backend/app/worker-start.sh

@@ -4,3 +4,5 @@ set -e
 python /app/app/celeryworker_pre_start.py
 
 celery -A app.worker worker -l info -Q main-queue -c 1
+
+celery -A app.wo

+ 50 - 0
cloud-docker-compose.override.yml

@@ -0,0 +1,50 @@
+version: "3.3"
+services:
+
+  proxy:
+    ports:
+      - "8080:80"
+      - "8090:8080"
+    command:
+      # Enable Docker in Traefik, so that it reads labels from Docker services
+      - --providers.docker
+      # Add a constraint to only use services with the label for this stack
+      # from the env var TRAEFIK_TAG
+      - --providers.docker.constraints=Label(`traefik.constraint-label-stack`, `${TRAEFIK_TAG?Variable not set}`)
+      # Do not expose all Docker services, only the ones explicitly exposed
+      - --providers.docker.exposedbydefault=false
+      # Disable Docker Swarm mode for local development
+      # - --providers.docker.swarmmode
+      # Enable the access log, with HTTP requests
+      - --accesslog
+      # Enable the Traefik log, for configurations and errors
+      - --log
+      # Enable the Dashboard and API
+      - --api
+      # Enable the Dashboard and API in insecure mode for local development
+      - --api.insecure=true
+    labels:
+      - traefik.enable=true
+      - traefik.http.routers.${STACK_NAME?Variable not set}-traefik-public-http.rule=Host(`${DOMAIN?Variable not set}`)
+      - traefik.http.services.${STACK_NAME?Variable not set}-traefik-public.loadbalancer.server.port=80
+
+
+
+
+
+
+  frontend:
+    build:
+      context: ./frontend
+      args:
+        FRONTEND_ENV: dev
+    labels:
+      - traefik.enable=true
+      - traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
+      - traefik.http.routers.${STACK_NAME?Variable not set}-frontend-http.rule=PathPrefix(`/`)
+      - traefik.http.services.${STACK_NAME?Variable not set}-frontend.loadbalancer.server.port=80
+
+networks:
+  traefik-public:
+    # For local dev, don't expect an external Traefik network
+    external: false

+ 0 - 21
choozmo-docker-compose.yml → cloud-docker-compose.yml

@@ -69,27 +69,6 @@ services:
         - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-http.middlewares=${STACK_NAME?Variable not set}-www-redirect,${STACK_NAME?Variable not set}-https-redirect
 
   
-  backend:
-    image: '${DOCKER_IMAGE_BACKEND?Variable not set}:${TAG-latest}'
-    env_file:
-      - .env
-    environment:
-      - SERVER_NAME=${DOMAIN?Variable not set}
-      - SERVER_HOST=https://${DOMAIN?Variable not set}
-      # Allow explicit env var override for tests
-      - SMTP_HOST=${SMTP_HOST}
-    build:
-      context: ./backend
-      dockerfile: backend.dockerfile
-      args:
-        INSTALL_DEV: ${INSTALL_DEV-false}
-    deploy:
-      labels:
-        - traefik.enable=true
-        - traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
-        - traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.rule=PathPrefix(`/api`) || PathPrefix(`/docs`) || PathPrefix(`/redoc`)
-        - traefik.http.services.${STACK_NAME?Variable not set}-backend.loadbalancer.server.port=80
-  
   frontend:
     image: '${DOCKER_IMAGE_FRONTEND?Variable not set}:${TAG-latest}'
     build:

+ 1 - 1
frontend/.env

@@ -1,4 +1,4 @@
-VITE_APP_DOMAIN_DEV=172.105.219.42:8080
+VITE_APP_DOMAIN_DEV=172.104.93.163:10000
 # VUE_APP_DOMAIN_DEV=local.dockertoolbox.tiangolo.com
 # VUE_APP_DOMAIN_DEV=localhost.tiangolo.com
 # VUE_APP_DOMAIN_DEV=dev.ai-anchor.com

+ 16 - 12
choozmo-docker-compose.override.yml → local-docker-compose.override.yml

@@ -3,7 +3,7 @@ services:
 
   proxy:
     ports:
-      - "8080:80"
+      - "80:80"
       - "8090:8080"
     command:
       # Enable Docker in Traefik, so that it reads labels from Docker services
@@ -28,8 +28,9 @@ services:
       - traefik.http.routers.${STACK_NAME?Variable not set}-traefik-public-http.rule=Host(`${DOMAIN?Variable not set}`)
       - traefik.http.services.${STACK_NAME?Variable not set}-traefik-public.loadbalancer.server.port=80
 
-
-
+  flower:
+    ports:
+      - "5555:5555"
 
   backend:
     volumes:
@@ -48,17 +49,20 @@ services:
       - traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.rule=PathPrefix(`/api`) || PathPrefix(`/docs`) || PathPrefix(`/redoc`)
       - traefik.http.services.${STACK_NAME?Variable not set}-backend.loadbalancer.server.port=80
 
-
-  frontend:
+  celeryworker:
+    volumes:
+      - ./backend/app:/app
+    environment:
+      - RUN=celery worker -A app.worker -l info -Q main-queue -c 1
+      - JUPYTER=jupyter lab --ip=0.0.0.0 --allow-root --NotebookApp.custom_display_url=http://127.0.0.1:8888
+      - SERVER_HOST=http://${DOMAIN?Variable not set}
     build:
-      context: ./frontend
+      context: ./backend
+      dockerfile: celeryworker.dockerfile
       args:
-        FRONTEND_ENV: dev
-    labels:
-      - traefik.enable=true
-      - traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
-      - traefik.http.routers.${STACK_NAME?Variable not set}-frontend-http.rule=PathPrefix(`/`)
-      - traefik.http.services.${STACK_NAME?Variable not set}-frontend.loadbalancer.server.port=80
+        INSTALL_DEV: ${INSTALL_DEV-true}
+        INSTALL_JUPYTER: ${INSTALL_JUPYTER-true}
+
 
 networks:
   traefik-public:

+ 150 - 0
local-docker-compose.yml

@@ -0,0 +1,150 @@
+version: "3.3"
+services:
+
+  proxy:
+    image: traefik:v2.9
+    networks:
+      - ${TRAEFIK_PUBLIC_NETWORK?Variable not set}
+      - default
+    volumes:
+      - /var/run/docker.sock:/var/run/docker.sock
+    command:
+      # Enable Docker in Traefik, so that it reads labels from Docker services
+      - --providers.docker
+      # Add a constraint to only use services with the label for this stack
+      # from the env var TRAEFIK_TAG
+      - --providers.docker.constraints=Label(`traefik.constraint-label-stack`, `${TRAEFIK_TAG?Variable not set}`)
+      # Do not expose all Docker services, only the ones explicitly exposed
+      - --providers.docker.exposedbydefault=false
+      # Enable Docker Swarm mode
+      - --providers.docker.swarmmode
+      # Enable the access log, with HTTP requests
+      - --accesslog
+      # Enable the Traefik log, for configurations and errors
+      - --log
+      # Enable the Dashboard and API
+      - --api
+    deploy:
+      placement:
+        constraints:
+          - node.role == manager
+      labels:
+        # Enable Traefik for this service, to make it available in the public network
+        - traefik.enable=true
+        # Use the traefik-public network (declared below)
+        - traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
+        # Use the custom label "traefik.constraint-label=traefik-public"
+        # This public Traefik will only use services with this label
+        - traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
+        # traefik-http set up only to use the middleware to redirect to https
+        - traefik.http.middlewares.${STACK_NAME?Variable not set}-https-redirect.redirectscheme.scheme=https
+        - traefik.http.middlewares.${STACK_NAME?Variable not set}-https-redirect.redirectscheme.permanent=true
+        # Handle host with and without "www" to redirect to only one of them
+        # Uses environment variable DOMAIN
+        # To disable www redirection remove the Host() you want to discard, here and
+        # below for HTTPS
+        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-http.rule=Host(`${DOMAIN?Variable not set}`) || Host(`www.${DOMAIN?Variable not set}`)
+        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-http.entrypoints=http
+        # traefik-https the actual router using HTTPS
+        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.rule=Host(`${DOMAIN?Variable not set}`) || Host(`www.${DOMAIN?Variable not set}`)
+        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.entrypoints=https
+        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.tls=true
+        # Use the "le" (Let's Encrypt) resolver created below
+        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.tls.certresolver=le
+        # Define the port inside of the Docker service to use
+        - traefik.http.services.${STACK_NAME?Variable not set}-proxy.loadbalancer.server.port=80
+        # Handle domain with and without "www" to redirect to only one
+        # To disable www redirection remove the next line
+        - traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.regex=^https?://(www.)?(${DOMAIN?Variable not set})/(.*)
+        # Redirect a domain with www to non-www
+        # To disable it remove the next line
+        - traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.replacement=https://${DOMAIN?Variable not set}/$${3}
+        # Redirect a domain without www to www
+        # To enable it remove the previous line and uncomment the next
+        # - traefik.http.middlewares.${STACK_NAME}-www-redirect.redirectregex.replacement=https://www.${DOMAIN}/$${3}
+        # Middleware to redirect www, to disable it remove the next line 
+        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.middlewares=${STACK_NAME?Variable not set}-www-redirect
+        # Middleware to redirect www, and redirect HTTP to HTTPS
+        # to disable www redirection remove the section: ${STACK_NAME?Variable not set}-www-redirect,
+        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-http.middlewares=${STACK_NAME?Variable not set}-www-redirect,${STACK_NAME?Variable not set}-https-redirect
+
+
+
+  queue:
+    image: rabbitmq:3
+    # Using the below image instead is required to enable the "Broker" tab in the flower UI:
+    # image: rabbitmq:3-management
+    #
+    # You also have to change the flower command
+  
+  flower:
+    image: mher/flower:0.9.7
+    networks:
+      - ${TRAEFIK_PUBLIC_NETWORK?Variable not set}
+      - default
+    env_file:
+      - .env
+    command:
+      - "--broker=amqp://guest@queue:5672//"
+      # For the "Broker" tab to work in the flower UI, uncomment the following command argument,
+      # and change the queue service's image as well
+      # - "--broker_api=http://guest:guest@queue:15672/api//"
+    deploy:
+      labels:
+        - traefik.enable=true
+        - traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
+        - traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
+        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.rule=Host(`flower.${DOMAIN?Variable not set}`)
+        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.entrypoints=http
+        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.middlewares=${STACK_NAME?Variable not set}-https-redirect
+        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.rule=Host(`flower.${DOMAIN?Variable not set}`)
+        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.entrypoints=https
+        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.tls=true
+        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.tls.certresolver=le
+        - traefik.http.services.${STACK_NAME?Variable not set}-flower.loadbalancer.server.port=5555
+  
+  backend:
+    image: '${DOCKER_IMAGE_BACKEND?Variable not set}:${TAG-latest}'
+    env_file:
+      - .env
+    environment:
+      - SERVER_NAME=${DOMAIN?Variable not set}
+      - SERVER_HOST=https://${DOMAIN?Variable not set}
+      # Allow explicit env var override for tests
+      - SMTP_HOST=${SMTP_HOST}
+    build:
+      context: ./backend
+      dockerfile: backend.dockerfile
+      args:
+        INSTALL_DEV: ${INSTALL_DEV-false}
+    deploy:
+      labels:
+        - traefik.enable=true
+        - traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
+        - traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.rule=PathPrefix(`/api`) || PathPrefix(`/docs`) || PathPrefix(`/redoc`)
+        - traefik.http.services.${STACK_NAME?Variable not set}-backend.loadbalancer.server.port=80
+  
+  celeryworker:
+    image: '${DOCKER_IMAGE_CELERYWORKER?Variable not set}:${TAG-latest}'
+    depends_on:
+      - queue
+    env_file:
+      - .env
+    environment:
+      - SERVER_NAME=${DOMAIN?Variable not set}
+      - SERVER_HOST=https://${DOMAIN?Variable not set}
+      # Allow explicit env var override for tests
+      - SMTP_HOST=${SMTP_HOST?Variable not set}
+    build:
+      context: ./backend
+      dockerfile: celeryworker.dockerfile
+      args:
+        INSTALL_DEV: ${INSTALL_DEV-false}
+  
+
+
+
+networks:
+  traefik-public:
+    # Allow setting it to false for testing
+    external: true