FROM node:24-bookworm-slim

WORKDIR /app

RUN sed -i \
      -e 's|http://deb.debian.org/debian|https://mirrors.aliyun.com/debian|g' \
      -e 's|http://deb.debian.org/debian-security|https://mirrors.aliyun.com/debian-security|g' \
      /etc/apt/sources.list.d/debian.sources && \
    apt-get update && \
    apt-get install -y --no-install-recommends ca-certificates python3 make g++ && \
    rm -rf /var/lib/apt/lists/* && \
    npm config set registry https://registry.npmmirror.com/ && \
    yarn config set registry https://registry.npmmirror.com/

COPY package.json yarn.lock ./

# The container runs the web/API service only, so strip Electron-only packages
# before installing to avoid downloading desktop binaries in CI.
RUN node -e "const fs=require('fs');const pkg=JSON.parse(fs.readFileSync('package.json','utf8'));for(const section of ['dependencies','devDependencies']){if(!pkg[section]) continue;for(const name of ['custom-electron-titlebar','electron','electron-builder','electron-rebuild','electronmon']) delete pkg[section][name];}fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2)+'\n');" && \
    yarn install --frozen-lockfile && \
    yarn cache clean

COPY . .

RUN yarn build && \
    mkdir -p /opt/toonflow-data && \
    cp -a data/. /opt/toonflow-data/ && \
    chmod +x scripts/docker-entrypoint.sh

ENV NODE_ENV=prod
ENV PORT=10588

EXPOSE 10588

ENTRYPOINT ["scripts/docker-entrypoint.sh"]
CMD ["node", "data/serve/app.js"]
