mirror of
https://github.com/catdevnull/preciazo.git
synced 2024-11-23 06:36:19 +00:00
mejorar container scraper-rs
This commit is contained in:
parent
536023f9bb
commit
82c44067d8
4 changed files with 27 additions and 63 deletions
34
.github/workflows/container.yml
vendored
34
.github/workflows/container.yml
vendored
|
@ -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 }}
|
||||
|
|
|
@ -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"]
|
2
scraper-rs/.dockerignore
Normal file
2
scraper-rs/.dockerignore
Normal file
|
@ -0,0 +1,2 @@
|
|||
.env
|
||||
target
|
23
scraper-rs/Dockerfile
Normal file
23
scraper-rs/Dockerfile
Normal file
|
@ -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"]
|
Loading…
Reference in a new issue