1
- FROM apify/actor-node-playwright:16
1
+ # Specify the base Docker image. You can read more about
2
+ # the available images at https://crawlee.dev/docs/guides/docker-images
3
+ # You can also use any other image from Docker Hub.
4
+ FROM apify/actor-node-playwright-chrome:16 AS builder
2
5
3
- # Copy the package.json and package-lock.json files, since they are the only files
4
- # that affect NPM install in the next step
5
- COPY package*.json ./
6
+ # Copy just package.json and package-lock.json
7
+ # to speed up the build using Docker layer cache.
8
+ COPY --chown=myuser package*.json ./
6
9
7
- # Install NPM packages, skip optional and development dependencies to keep the
8
- # image small. Avoid logging too much and print the dependency tree for debugging
10
+ # Install all dependencies. Don't audit to speed up the installation.
11
+ RUN npm install --include=dev --audit=false
9
12
10
- # Log Node version
11
- RUN echo "Node.js version:" && node --version
13
+ # Next, copy the source files using the user set
14
+ # in the base image.
15
+ COPY --chown=myuser . ./
12
16
13
- # Log npm version
14
- RUN echo "NPM version:" && npm --version
17
+ # Install all dependencies and build the project.
18
+ # Don't audit to speed up the installation.
19
+ RUN npm run build
15
20
16
- # Install all runtime dependencies
21
+ # Create final image
22
+ FROM apify/actor-node-playwright-chrome:16
23
+
24
+ # Copy only built JS files from builder image
25
+ COPY --from=builder --chown=myuser /home/myuser/dist ./dist
26
+
27
+ # Copy just package.json and package-lock.json
28
+ # to speed up the build using Docker layer cache.
29
+ COPY --chown=myuser package*.json ./
30
+
31
+ # Install NPM packages, skip optional and development dependencies to
32
+ # keep the image small. Avoid logging too much and print the dependency
33
+ # tree for debugging
17
34
RUN npm --quiet set progress=false \
18
- && npm ci --only=prod --no-optional \
19
- && echo "Installed NPM packages:" \
20
- && (npm ls || true)
35
+ && npm install --omit=dev --omit=optional \
36
+ && echo "Installed NPM packages:" \
37
+ && (npm list --omit=dev --all || true) \
38
+ && echo "Node.js version:" \
39
+ && node --version \
40
+ && echo "NPM version:" \
41
+ && npm --version \
42
+ && rm -r ~/.npm
21
43
22
- # Next, copy the remaining files and directories with the built source code.
44
+ # Next, copy the remaining files and directories with the source code.
23
45
# Since we do this after NPM install, quick build will be really fast
24
- # for simple source file changes.
25
- COPY ./src ./dist
46
+ # for most source file changes.
47
+ COPY --chown=myuser . ./
48
+
49
+
50
+ # Run the image. If you know you won't need headful browsers,
51
+ # you can remove the XVFB start script for a micro perf gain.
52
+ CMD ./start_xvfb_and_run_cmd.sh && npm run start:prod --silent
0 commit comments