mirror of
https://github.com/catdevnull/preciazo.git
synced 2024-11-29 21:16:19 +00:00
Compare commits
4 commits
f645607adf
...
43954d7af8
Author | SHA1 | Date | |
---|---|---|---|
43954d7af8 | |||
14873c95db | |||
add02ac2b0 | |||
a12476129c |
7 changed files with 52 additions and 58 deletions
|
@ -4,7 +4,10 @@ data/carrefour/
|
|||
downloader/
|
||||
node_modules/
|
||||
*/node_modules/
|
||||
Containerfile
|
||||
*/Containerfile
|
||||
Dockerfile
|
||||
*/Dockerfile
|
||||
*.warc.zst
|
||||
.git
|
||||
scraper/debug/
|
31
Dockerfile
Normal file
31
Dockerfile
Normal file
|
@ -0,0 +1,31 @@
|
|||
FROM docker.io/oven/bun:1-alpine AS base
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
FROM base as build
|
||||
ENV NODE_ENV=production
|
||||
RUN apk add --no-cache nodejs
|
||||
COPY . .
|
||||
RUN bun install --frozen-lockfile
|
||||
RUN cd sitio && \
|
||||
bun run build
|
||||
RUN bun build scraper/cli.ts --target=bun --outfile=/tmp/cli.build.js
|
||||
|
||||
FROM base
|
||||
RUN apk add --no-cache tini nodejs npm jq
|
||||
|
||||
# Sitio
|
||||
COPY --from=build /usr/src/app/sitio/package.json package.real.json
|
||||
RUN sh -c 'echo {\"name\":\"sitio\",\"type\":\"module\",\"dependencies\":$(jq .dependencies < package.real.json)} > package.json' && npm install
|
||||
COPY --from=build /usr/src/app/db-datos node_modules/db-datos
|
||||
COPY --from=build /usr/src/app/sitio/build .
|
||||
|
||||
# Scraper
|
||||
COPY --from=build /tmp/cli.build.js /bin/scraper
|
||||
COPY --from=build /usr/src/app/db-datos/drizzle /bin/drizzle
|
||||
|
||||
ENV NODE_ENV=production
|
||||
ENV DB_PATH=/db/db.db
|
||||
EXPOSE 3000
|
||||
|
||||
ENTRYPOINT ["tini", "--"]
|
||||
CMD ["node", "."]
|
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
|
@ -1,27 +0,0 @@
|
|||
FROM docker.io/oven/bun:1-alpine AS base
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
FROM base AS builder
|
||||
ENV NODE_ENV=production
|
||||
COPY . .
|
||||
RUN bun install --frozen-lockfile \
|
||||
&& bun build scraper/cli.ts --target=bun --outfile=/tmp/cli.build.js \
|
||||
&& rm -rf node_modules/
|
||||
|
||||
FROM base
|
||||
RUN apk add --no-cache wget zstd tini
|
||||
RUN printf "#!/bin/sh\nexec bun /bin/scraper auto\n" > /etc/periodic/daily/scraper \
|
||||
&& chmod +x /etc/periodic/daily/scraper
|
||||
|
||||
COPY --from=builder /tmp/cli.build.js /bin/scraper
|
||||
COPY --from=builder /usr/src/app/db-datos/drizzle /bin/drizzle
|
||||
COPY --from=builder /usr/src/app/data /listas
|
||||
WORKDIR /app
|
||||
|
||||
VOLUME /db
|
||||
ENV NODE_ENV=production
|
||||
ENV DB_PATH=/db/db.db
|
||||
ENV LISTS_DIR=/listas/
|
||||
|
||||
CMD ["tini", "/bin/busybox", "crond", "-f", "-l2"]
|
||||
# CMD ["bun", "/bin/scraper"]
|
|
@ -1,31 +0,0 @@
|
|||
FROM docker.io/oven/bun:1-alpine as build
|
||||
RUN apk add --no-cache nodejs
|
||||
WORKDIR /usr/src/app
|
||||
COPY . .
|
||||
WORKDIR /usr/src/app/sitio
|
||||
RUN bun install && \
|
||||
bun run build
|
||||
|
||||
# FROM docker.io/oven/bun:1-alpine as deps
|
||||
# WORKDIR /usr/src/app/sitio
|
||||
# RUN bun init && bun install "better-sqlite3"@"^9.2.2" "chart.js"@"^4.4.1" "chartjs-adapter-dayjs-4"@"^1.0.4" "dayjs"@"^1.11.10" "drizzle-orm"@"^0.29.1"
|
||||
# COPY --from=build /usr/src/app/db-datos node_modules/db-datos
|
||||
|
||||
FROM docker.io/alpine:3.19
|
||||
RUN apk add --no-cache tini nodejs npm jq
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=build /usr/src/app/sitio/package.json package.real.json
|
||||
RUN sh -c 'echo {\"name\":\"sitio\",\"type\":\"module\",\"dependencies\":$(jq .dependencies < package.real.json)} > package.json' && npm install
|
||||
COPY --from=build /usr/src/app/db-datos node_modules/db-datos
|
||||
COPY --from=build /usr/src/app/sitio/build .
|
||||
|
||||
# https://github.com/gornostay25/svelte-adapter-bun/issues/39
|
||||
ENV PROTOCOL_HEADER=x-forwarded-proto
|
||||
ENV HOST_HEADER=x-forwarded-host
|
||||
|
||||
VOLUME /db
|
||||
ENV DB_PATH=/db/db.db
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["tini", "node", "."]
|
|
@ -38,6 +38,7 @@
|
|||
"better-sqlite3": "^9.2.2",
|
||||
"chart.js": "^4.4.1",
|
||||
"chartjs-adapter-dayjs-4": "^1.0.4",
|
||||
"cron": "^3.1.6",
|
||||
"dayjs": "^1.11.10",
|
||||
"drizzle-orm": "^0.29.1"
|
||||
}
|
||||
|
|
17
sitio/src/hooks.server.ts
Normal file
17
sitio/src/hooks.server.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { spawn } from "child_process";
|
||||
import { CronJob } from "cron";
|
||||
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
const job = CronJob.from({
|
||||
cronTime: "0 3 * * *",
|
||||
onTick: function () {
|
||||
runScraper();
|
||||
},
|
||||
start: true,
|
||||
timeZone: "America/Argentina/Buenos_Aires",
|
||||
});
|
||||
}
|
||||
|
||||
function runScraper() {
|
||||
spawn("bun", ["/bin/scraper", "auto"], { stdio: "inherit" });
|
||||
}
|
Loading…
Reference in a new issue