version: '3.5'
services:
  node:
    build: ./node
    container_name: Raikyakun-Mobile-Node
    restart: always
    ports:
      - 127.0.0.1::3000
      - 10.3.0.3:2225:22
      - 192.168.10.253:2225:22
    volumes:
      - yarn-cache:/usr/local/share/.cache/yarn/v6
      - ./node:/usr/src/node
      - ./node/ssh:/ssh-authorized-keys:ro
    networks:
      proxy-net:
        ipv4_address: 172.18.2.102
    environment:
      VIRTUAL_HOST: dev.mobile.raikyakun.app
      VIRTUAL_PORT: 3000
      LETSENCRYPT_HOST: dev.mobile.raikyakun.app
      LETSENCRYPT_EMAIL: tohyama@office-gate.com
    tty: true
    # /usr/src/node/.prod-mode が在れば本番ビルド (yarn build && yarn start)、無ければ yarn dev。
    # 切り替えは .prod-mode を touch / rm して `docker compose restart node` するだけ。
    command: bash -c 'if [ -f /ssh-authorized-keys/authorized_keys ]; then cp /ssh-authorized-keys/authorized_keys /home/codex/.ssh/authorized_keys && chown codex:codex /home/codex/.ssh/authorized_keys && chmod 600 /home/codex/.ssh/authorized_keys; fi && mkdir -p /run/sshd && /usr/sbin/sshd && cd /usr/src/node && (if [ -f .prod-mode ]; then echo "[run] prod build mode (yarn build && yarn start)" && yarn build && yarn start; else echo "[run] dev mode (yarn dev)" && yarn dev; fi) 2>&1 | tee /tmp/next-dev.log'
volumes:
  yarn-cache:
networks:
  proxy-net:
    external: true
