diff --git a/.dockerignore b/.dockerignore index d778136..86597ab 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,4 +3,5 @@ data/carrefour/ */*.db* downloader/ node_modules/ -*/node_modules/ \ No newline at end of file +*/node_modules/ +*/Containerfile \ No newline at end of file diff --git a/bun.lockb b/bun.lockb index c9d92d9..8dcbab0 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/scraper/Containerfile b/scraper/Containerfile index 84f0536..d2aa951 100644 --- a/scraper/Containerfile +++ b/scraper/Containerfile @@ -4,15 +4,23 @@ WORKDIR /usr/src/app FROM base AS builder ENV NODE_ENV=production COPY . . -RUN bun install --frozen-lockfile -RUN bun build scraper/auto.ts --target=bun --outfile=/tmp/auto.build.js +RUN bun install --frozen-lockfile \ + && bun build scraper/auto.ts --target=bun --outfile=/tmp/auto.build.js \ + && rm -rf node_modules/ FROM base +RUN apk add --no-cache wget zstd cronie tini +RUN printf "#!/bin/sh\nexec bun /app/built.js" > /etc/periodic/daily/scraper \ + && chmod +x /etc/periodic/daily/scraper + COPY --from=builder /tmp/auto.build.js /app/built.js COPY --from=builder /usr/src/app/db-datos/drizzle /app/drizzle +COPY --from=builder /usr/src/app/data /listas WORKDIR /app VOLUME /db ENV DB_PATH=/db/db.db +ENV LISTS_DIR=/listas/ -CMD ["bun", "/app/built.js"] \ No newline at end of file +CMD ["tini", "/usr/sbin/crond", "-n"] +# CMD ["bun", "/app/built.js"] \ No newline at end of file diff --git a/scraper/auto.ts b/scraper/auto.ts index dd5986d..c7359e2 100644 --- a/scraper/auto.ts +++ b/scraper/auto.ts @@ -77,13 +77,13 @@ async function downloadList(supermercado: Supermercado) { inform(`wget para ${zstdWarcName} tardó ${formatMs(performance.now() - t0)}`); const gzippedWarcPath = join(ctxPath, "temp.warc.gz"); - if (!(await exists(gzippedWarcPath))) { + if (!(await fileExists(gzippedWarcPath))) { const err = report(`no encontré el ${gzippedWarcPath}`); throw err; } await compressionQueue.add(() => recompress(gzippedWarcPath, zstdWarcPath)); - if (!(await exists(zstdWarcPath))) { + if (!(await fileExists(zstdWarcPath))) { const err = report(`no encontré el ${zstdWarcPath}`); throw err; } @@ -201,7 +201,8 @@ function report(msg: string) { return error; } -async function exists(path: string) { +// no se llama exists porque bun tiene un bug en el que usa fs.exists por mas que exista una funcion llamada exists +async function fileExists(path: string) { try { access(path); return true; diff --git a/scraper/cli.ts b/scraper/cli.ts new file mode 100644 index 0000000..e69de29