From a12476129cc0819a793cf049ebd0451a71a5bf36 Mon Sep 17 00:00:00 2001 From: Nulo Date: Sat, 6 Jan 2024 20:23:06 -0300 Subject: [PATCH] usar solo una imagen docker --- .dockerignore | 1 + Containerfile | 48 +++++++++++++++++++++++++++++++++++++++++++ scraper/Containerfile | 27 ------------------------ sitio/Containerfile | 31 ---------------------------- 4 files changed, 49 insertions(+), 58 deletions(-) create mode 100644 Containerfile delete mode 100644 scraper/Containerfile delete mode 100644 sitio/Containerfile diff --git a/.dockerignore b/.dockerignore index a8eafd5..995eb20 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,6 +4,7 @@ data/carrefour/ downloader/ node_modules/ */node_modules/ +Containerfile */Containerfile *.warc.zst .git diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..3555f2a --- /dev/null +++ b/Containerfile @@ -0,0 +1,48 @@ +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 +ARG S6_OVERLAY_VERSION=3.1.6.2 +RUN apk add --no-cache nodejs npm jq + +ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz /tmp +RUN tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz +ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-x86_64.tar.xz /tmp +RUN tar -C / -Jxpf /tmp/s6-overlay-x86_64.tar.xz + +# Cron scraper +RUN printf "#!/bin/sh\nexec bun /bin/scraper auto\n" > /etc/periodic/daily/scraper \ + && chmod +x /etc/periodic/daily/scraper + +# 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 + +VOLUME /db +ENV NODE_ENV=production +ENV DB_PATH=/db/db.db +EXPOSE 3000 + +# Servicios +RUN mkdir -p /etc/services.d/sitio /etc/services.d/scraper && \ + printf "#!/command/execlineb -P\nnode /usr/src/app\n" > /etc/services.d/sitio/run && \ + chmod +x /etc/services.d/sitio/run && \ + printf "#!/command/execlineb -P\nbusybox crond -f -l2\n" > /etc/services.d/scraper/run && \ + chmod +x /etc/services.d/scraper/run + +ENTRYPOINT ["/init"] \ No newline at end of file diff --git a/scraper/Containerfile b/scraper/Containerfile deleted file mode 100644 index 8fbf68e..0000000 --- a/scraper/Containerfile +++ /dev/null @@ -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"] \ No newline at end of file diff --git a/sitio/Containerfile b/sitio/Containerfile deleted file mode 100644 index 687b071..0000000 --- a/sitio/Containerfile +++ /dev/null @@ -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", "."] \ No newline at end of file