Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

fix: improve dockerfiles and project templates

Martin Adámek7c21a646360d
diff --git a/packages/templates/templates/cheerio-js/Dockerfile b/packages/templates/templates/cheerio-js/Dockerfile
index c91f866c4..438d36e17 100644
--- a/packages/templates/templates/cheerio-js/Dockerfile
+++ b/packages/templates/templates/cheerio-js/Dockerfile
@@ -1,6 +1,8 @@
FROM apify/actor-node:16
-COPY . ./
+# copy package.json, lock file and possibly crawlee.json
+COPY package*.json crawlee?json ./
+COPY src ./src
# install only prod deps
RUN npm --quiet set progress=false \
diff --git a/packages/templates/templates/cheerio-js/src/routes.js b/packages/templates/templates/cheerio-js/src/routes.js
index b4e575067..971577b0f 100644
--- a/packages/templates/templates/cheerio-js/src/routes.js
+++ b/packages/templates/templates/cheerio-js/src/routes.js
@@ -5,7 +5,7 @@ export const router = createCheerioRouter();
router.addDefaultHandler(async ({ enqueueLinks, log }) => {
log.info(`Handle Start URLs`);
await enqueueLinks({
- globs: ['https://crawlee.dev/*'],
+ globs: ['https://crawlee.dev/**'],
label: 'DETAIL',
});
});
diff --git a/packages/templates/templates/cheerio-ts/Dockerfile b/packages/templates/templates/cheerio-ts/Dockerfile
index c13b2d3ed..c28874341 100644
--- a/packages/templates/templates/cheerio-ts/Dockerfile
+++ b/packages/templates/templates/cheerio-ts/Dockerfile
@@ -5,7 +5,7 @@ FROM apify/actor-node:16 AS builder
# Second, copy the TS source files, package.json and package-lock.json since it should be
# the only files that affects the installation and build in the next step
-COPY package*.json ./
+COPY package*.json crawlee?json ./
COPY src ./src
# Install all dependencies (including dev deps) and build the project
@@ -14,8 +14,8 @@ RUN npm install --include=dev && npm run build
# Create final image
FROM apify/actor-node:16
-# Copy only necessary files
-COPY --from=builder /usr/src/app/package.json ./
+# Copy only necessary files (crawlee.json might not exist, so we need the regexp trick with `crawlee?json`)
+COPY --from=builder /usr/src/app/package.json /usr/src/app/crawlee?json ./
COPY --from=builder /usr/src/app/README.md ./
COPY --from=builder /usr/src/app/dist ./dist
diff --git a/packages/templates/templates/cheerio-ts/src/routes.ts b/packages/templates/templates/cheerio-ts/src/routes.ts
index 76f76a0fe..a7b0f2e67 100644
--- a/packages/templates/templates/cheerio-ts/src/routes.ts
+++ b/packages/templates/templates/cheerio-ts/src/routes.ts
@@ -5,7 +5,7 @@ export const router = createCheerioRouter();
router.addDefaultHandler(async ({ enqueueLinks, log }) => {
log.info(`Handle Start URLs`);
await enqueueLinks({
- globs: ['https://crawlee.dev/*'],
+ globs: ['https://crawlee.dev/**'],
label: 'DETAIL',
});
});
diff --git a/packages/templates/templates/playwright-js/Dockerfile b/packages/templates/templates/playwright-js/Dockerfile
index d0c939cf4..13aa67daa 100644
--- a/packages/templates/templates/playwright-js/Dockerfile
+++ b/packages/templates/templates/playwright-js/Dockerfile
@@ -1,6 +1,8 @@
FROM apify/actor-node-playwright-chrome:16
-COPY . ./
+# copy package.json, lock file and possibly crawlee.json
+COPY package*.json crawlee?json ./
+COPY src ./src
# install only prod deps
RUN npm --quiet set progress=false \
diff --git a/packages/templates/templates/playwright-js/src/routes.js b/packages/templates/templates/playwright-js/src/routes.js
index 62fbf029f..f26623a67 100644
--- a/packages/templates/templates/playwright-js/src/routes.js
+++ b/packages/templates/templates/playwright-js/src/routes.js
@@ -5,7 +5,7 @@ export const router = createPlaywrightRouter();
router.addDefaultHandler(async ({ enqueueLinks, log }) => {
log.info(`Handle Start URLs`);
await enqueueLinks({
- globs: ['https://crawlee.dev/*'],
+ globs: ['https://crawlee.dev/**'],
label: 'DETAIL',
});
});
diff --git a/packages/templates/templates/playwright-ts/Dockerfile b/packages/templates/templates/playwright-ts/Dockerfile
index fc4850a3d..03cb19e3a 100644
--- a/packages/templates/templates/playwright-ts/Dockerfile
+++ b/packages/templates/templates/playwright-ts/Dockerfile
@@ -5,7 +5,7 @@ FROM apify/actor-node:16 AS builder
# Second, copy the TS source files, package.json and package-lock.json since it should be
# the only files that affects the installation and build in the next step
-COPY package*.json ./
+COPY package*.json crawlee?json ./
COPY src ./src
# Install all dependencies (including dev deps) and build the project
@@ -14,8 +14,8 @@ RUN npm install --include=dev && npm run build
# Create final image
FROM apify/actor-node-playwright-chrome:16
-# Copy only necessary files
-COPY --from=builder /usr/src/app/package.json ./
+# Copy only necessary files (crawlee.json might not exist, so we need the regexp trick with `crawlee?json`)
+COPY --from=builder /usr/src/app/package.json /usr/src/app/crawlee?json ./
COPY --from=builder /usr/src/app/README.md ./
COPY --from=builder /usr/src/app/dist ./dist
diff --git a/packages/templates/templates/playwright-ts/src/routes.ts b/packages/templates/templates/playwright-ts/src/routes.ts
index 62fbf029f..f26623a67 100644
--- a/packages/templates/templates/playwright-ts/src/routes.ts
+++ b/packages/templates/templates/playwright-ts/src/routes.ts
@@ -5,7 +5,7 @@ export const router = createPlaywrightRouter();
router.addDefaultHandler(async ({ enqueueLinks, log }) => {
log.info(`Handle Start URLs`);
await enqueueLinks({
- globs: ['https://crawlee.dev/*'],
+ globs: ['https://crawlee.dev/**'],
label: 'DETAIL',
});
});
diff --git a/packages/templates/templates/puppeteer-js/Dockerfile b/packages/templates/templates/puppeteer-js/Dockerfile
index cace38b27..9bdbbf8a6 100644
--- a/packages/templates/templates/puppeteer-js/Dockerfile
+++ b/packages/templates/templates/puppeteer-js/Dockerfile
@@ -1,6 +1,8 @@
FROM apify/actor-node-puppeteer-chrome:16
-COPY . ./
+# copy package.json, lock file and possibly crawlee.json
+COPY package*.json crawlee?json ./
+COPY src ./src
# install only prod deps
RUN npm --quiet set progress=false \
diff --git a/packages/templates/templates/puppeteer-js/src/routes.js b/packages/templates/templates/puppeteer-js/src/routes.js
index 80b3f0b43..7f2b1d4bc 100644
--- a/packages/templates/templates/puppeteer-js/src/routes.js
+++ b/packages/templates/templates/puppeteer-js/src/routes.js
@@ -5,7 +5,7 @@ export const router = createPuppeteerRouter();
router.addDefaultHandler(async ({ enqueueLinks, log }) => {
log.info(`Handle Start URLs`);
await enqueueLinks({
- globs: ['https://crawlee.dev/*'],
+ globs: ['https://crawlee.dev/**'],
label: 'DETAIL',
});
});
diff --git a/packages/templates/templates/puppeteer-ts/Dockerfile b/packages/templates/templates/puppeteer-ts/Dockerfile
index 7fe977f7f..8852839c6 100644
--- a/packages/templates/templates/puppeteer-ts/Dockerfile
+++ b/packages/templates/templates/puppeteer-ts/Dockerfile
@@ -5,7 +5,7 @@ FROM apify/actor-node:16 AS builder
# Second, copy the TS source files, package.json and package-lock.json since it should be
# the only files that affects the installation and build in the next step
-COPY package*.json ./
+COPY package*.json crawlee?json ./
COPY src ./src
# Install all dependencies (including dev deps) and build the project
@@ -14,8 +14,8 @@ RUN npm install --include=dev && npm run build
# Create final image
FROM apify/actor-node-puppeteer-chrome:16
-# Copy only necessary files
-COPY --from=builder /usr/src/app/package.json ./
+# Copy only necessary files (crawlee.json might not exist, so we need the regexp trick with `crawlee?json`)
+COPY --from=builder /usr/src/app/package.json /usr/src/app/crawlee?json ./
COPY --from=builder /usr/src/app/README.md ./
COPY --from=builder /usr/src/app/dist ./dist
diff --git a/packages/templates/templates/puppeteer-ts/src/routes.ts b/packages/templates/templates/puppeteer-ts/src/routes.ts
index 80b3f0b43..7f2b1d4bc 100644
--- a/packages/templates/templates/puppeteer-ts/src/routes.ts
+++ b/packages/templates/templates/puppeteer-ts/src/routes.ts
@@ -5,7 +5,7 @@ export const router = createPuppeteerRouter();
router.addDefaultHandler(async ({ enqueueLinks, log }) => {
log.info(`Handle Start URLs`);
await enqueueLinks({
- globs: ['https://crawlee.dev/*'],
+ globs: ['https://crawlee.dev/**'],
label: 'DETAIL',
});
});