version: '3'

networks:
  main:
    external: true

services:
  backend:
    image: node:lts-bookworm
    container_name: pca_pijac_backend
    restart: unless-stopped
    env_file: ./backend/.env.production
    networks:
      - main
    volumes:
      - ./backend:/app
      - ./data:/data
    labels:
      caddy: admin.pca-pijac.dev.civokram.com
      caddy.reverse_proxy: '{{upstreams 8055}}'
    command:
      - sh
      - -c
      - |
        npm i -g pnpm
        cd /app
        pnpm install --production
        rm -f .env
        pnpm run start

  frontend:
    image: node:lts-bookworm
    container_name: pca_pijac_frontend
    restart: unless-stopped
    env_file: ./frontend/.env.production
    depends_on:
      - backend
    networks:
      - main
    volumes:
      - ./frontend:/app
    labels:
      caddy: pca-pijac.dev.civokram.com
      caddy.reverse_proxy: '{{upstreams 3000}}'
    command:
      - sh
      - -c
      - |
        npm i -g pnpm
        cd /app
        pnpm install --production
        sleep 10
        rm -f .env
        pnpm run build
        pnpm run start
