container scraper

This commit is contained in:
Cat /dev/Nulo 2023-12-26 00:03:28 -03:00
parent 4589eee5c0
commit 241969e678
11 changed files with 37 additions and 13 deletions

6
.dockerignore Normal file
View file

@ -0,0 +1,6 @@
data/warcs/
data/carrefour/
*/*.db*
downloader/
node_modules/
*/node_modules/

2
.gitignore vendored
View file

@ -12,4 +12,4 @@ scraper/debug/
scraper/x.tsv
*.tmp
target/
.env.*
.env.*

BIN
bun.lockb

Binary file not shown.

View file

@ -1 +0,0 @@
DB_PATH=../scraper/sqlite.db

View file

@ -7,7 +7,6 @@ export const DB_PATH = process.env.DB_PATH;
export default {
schema: "./schema.ts",
out: "./drizzle",
driver: "better-sqlite",
dbCredentials: {
url: process.env.DB_PATH,
},

View file

@ -4,9 +4,11 @@ import { migrate } from "drizzle-orm/bun-sqlite/migrator";
import * as schema from "./schema.js";
import { DB_PATH } from "./drizzle.config.js";
const sqlite = new Database(DB_PATH);
const db = drizzle(sqlite, { schema });
export function migrateDb() {
const sqlite = new Database(DB_PATH);
const db = drizzle(sqlite, { schema });
migrate(db, { migrationsFolder: "./drizzle" });
migrate(db, { migrationsFolder: "./drizzle" });
sqlite.close();
sqlite.close();
}

View file

@ -15,9 +15,7 @@
"drizzle-orm": "^0.29.1"
},
"devDependencies": {
"better-sqlite3": "^9.2.2",
"drizzle-kit": "^0.20.7",
"tsx": "^4.7.0",
"@types/better-sqlite3": "^7.6.8"
"@types/bun": "^1.0.0",
"drizzle-kit": "^0.20.7"
}
}

View file

@ -1 +0,0 @@
DB_PATH=../scraper/sqlite.db

18
scraper/Containerfile Normal file
View file

@ -0,0 +1,18 @@
FROM oven/bun:1-alpine AS base
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
FROM base
COPY --from=builder /tmp/auto.build.js /app/built.js
COPY --from=builder /usr/src/app/db-datos/drizzle /app/drizzle
WORKDIR /app
VOLUME /db
ENV DB_PATH=/db/db.db
CMD ["bun", "/app/built.js"]

View file

@ -5,7 +5,7 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"build:container": "podman build -t gitea.nulo.in/nulo/preciazo/scraper -f ./Containerfile .."
},
"keywords": [],
"author": "",

View file

@ -10,10 +10,13 @@ import { getCotoProduct } from "./parsers/coto.js";
import { join } from "path";
import { and, eq, sql } from "drizzle-orm";
import { DB_PATH } from "db-datos/drizzle.config.js";
import { migrateDb } from "db-datos/migrate.js";
const DEBUG = false;
const PARSER_VERSION = 2;
migrateDb();
const sqlite = new Database(DB_PATH);
const db = drizzle(sqlite, { schema });