diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index 145c341..73cfbe2 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -85,41 +85,11 @@ jobs: uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/scraper - - name: Cache usr/src/app/target - uses: actions/cache@v4 - with: - path: usr/src/app/target - key: usr/src/app/target-${{ hashFiles('Dockerfile.scraper') }} - - name: inject usr/src/app/target into docker - uses: reproducible-containers/buildkit-cache-dance@v2.1.3 - with: - cache-source: usr/src/app/target - cache-target: /usr/src/app/target - - name: Cache root/.cargo/registry - uses: actions/cache@v4 - with: - path: root/.cargo/registry - key: root/.cargo/registry-${{ hashFiles('Dockerfile.scraper') }} - - name: inject root/.cargo/registry into docker - uses: reproducible-containers/buildkit-cache-dance@v2.1.3 - with: - cache-source: root/.cargo/registry - cache-target: /root/.cargo/registry - - name: Cache root/.cargo/git - uses: actions/cache@v4 - with: - path: root/.cargo/git - key: root/.cargo/git-${{ hashFiles('Dockerfile.scraper') }} - - name: inject root/.cargo/git into docker - uses: reproducible-containers/buildkit-cache-dance@v2.1.3 - with: - cache-source: root/.cargo/git - cache-target: /root/.cargo/git - name: Build and push Docker image uses: docker/build-push-action@v5 with: - context: . - file: Dockerfile.scraper + context: scraper-rs/ + file: Dockerfile push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile.scraper b/Dockerfile.scraper deleted file mode 100644 index 6a06df3..0000000 --- a/Dockerfile.scraper +++ /dev/null @@ -1,31 +0,0 @@ -FROM cgr.dev/chainguard/wolfi-base AS base -WORKDIR /usr/src/app -RUN apk add --no-cache libgcc - -# tenemos que generar una DB con las migraciones aplicadas para compilar el codigo por sqlx::query!() -FROM base as db-build -RUN apk add --no-cache nodejs npm -RUN npm install --global pnpm -COPY db-datos/ . -RUN pnpm install -RUN DB_PATH=db.db pnpm migrate - -FROM base as rs-build -RUN apk add --no-cache rust build-base sqlite-dev - -COPY scraper-rs/ . -COPY --from=db-build /usr/src/app/db.db . -RUN --mount=type=cache,sharing=locked,target=/root/.cargo/git \ - --mount=type=cache,sharing=locked,target=/root/.cargo/registry \ - --mount=type=cache,sharing=locked,target=/usr/src/app/target \ - DATABASE_URL=sqlite:db.db cargo install --locked --path . - -FROM base -RUN apk add --no-cache sqlite sqlite-libs - -# Scraper -COPY --from=rs-build /root/.cargo/bin/scraper-rs /usr/local/bin/scraper-rs - -ENV DB_PATH=/db/db.db - -CMD ["scraper-rs", "cron"] diff --git a/scraper-rs/.dockerignore b/scraper-rs/.dockerignore new file mode 100644 index 0000000..0d95126 --- /dev/null +++ b/scraper-rs/.dockerignore @@ -0,0 +1,2 @@ +.env +target \ No newline at end of file diff --git a/scraper-rs/Dockerfile b/scraper-rs/Dockerfile new file mode 100644 index 0000000..c69323e --- /dev/null +++ b/scraper-rs/Dockerfile @@ -0,0 +1,23 @@ +FROM cgr.dev/chainguard/wolfi-base AS base +WORKDIR /usr/src/app +RUN apk add --no-cache libgcc + +FROM docker.io/rust:1.76 as rs-build +# RUN apt-get update && apt-get install -y libsqlite3-dev && rm -rf /var/lib/apt/lists/* +WORKDIR /usr/src/app + +COPY . . +RUN --mount=type=cache,sharing=locked,target=/root/.cargo/git \ + --mount=type=cache,sharing=locked,target=/root/.cargo/registry \ + --mount=type=cache,sharing=locked,target=/usr/src/app/target \ + cargo install --locked --path . + +FROM base +RUN apk add --no-cache sqlite sqlite-libs + +# Scraper +COPY --from=rs-build /usr/local/cargo/bin/scraper-rs /usr/local/bin/scraper-rs + +ENV DB_PATH=/db/db.db + +CMD ["scraper-rs", "cron"]